Fixes on fields for new behaviour

This commit is contained in:
Antonio de la Rosa 2015-08-28 05:24:58 +02:00
parent 2a342ad9f9
commit 890704010b
21 changed files with 78 additions and 36 deletions

View file

@ -24,7 +24,7 @@ class BooleanField extends PhangoField {
{ {
$this->size=1; $this->size=1;
$this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; $this->form=public $form='PhangoApp\PhaModels\Forms\SelectForm';
} }

View file

@ -31,7 +31,7 @@ class CharField extends PhangoField {
{ {
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::TextForm'; $this->form='PhangoApp\PhaModels\Forms\BaseForm';
} }

View file

@ -3,6 +3,7 @@
namespace PhangoApp\PhaModels\CoreFields; namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaUtils\Utils; use PhangoApp\PhaUtils\Utils;
use PhangoApp\PhaI18n\I18n; use PhangoApp\PhaI18n\I18n;
use PhangoApp\PhaModels\Forms\SelectForm;
/** /**
* *
@ -14,7 +15,6 @@ class ChoiceField extends PhangoField {
public $value=0; public $value=0;
public $label=""; public $label="";
public $required=0; public $required=0;
public $form="";
public $quot_open='\''; public $quot_open='\'';
public $quot_close='\''; public $quot_close='\'';
public $std_error=''; public $std_error='';
@ -22,18 +22,18 @@ class ChoiceField extends PhangoField {
public $arr_values=array(); public $arr_values=array();
public $arr_formatted=array(); public $arr_formatted=array();
public $default_value=''; public $default_value='';
public $form='PhangoApp\PhaModels\Forms\SelectForm';
function __construct($size=11, $type='integer', $arr_values=array(), $default_value='') function __construct($size=11, $type='integer', $arr_values=array(), $default_value='')
{ {
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::SelectForm';
$this->type=$type; $this->type=$type;
$this->arr_values=$arr_values; $this->arr_values=$arr_values;
$this->default_value=$default_value; $this->default_value=$default_value;
$this->arr_formatted['']=''; $this->arr_formatted['']=I18n::lang('common', 'none_selected', 'None selected');
foreach($arr_values as $value) foreach($arr_values as $value)
{ {
@ -119,11 +119,13 @@ class ChoiceField extends PhangoField {
public function show_formatted($value) public function show_formatted($value)
{ {
$this->restart_formatted();
return $this->arr_formatted[$value]; return $this->arr_formatted[$value];
} }
/*
function get_parameters_default() function get_parameters_default()
{ {
@ -145,13 +147,26 @@ class ChoiceField extends PhangoField {
else else
{ {
$arr_values=array(0, 'Option 1', 0, 'Option 2', 1); $arr_values=array(0 => 'Option 1', 1 => 'Option 2');
} }
return array($this->name_component, '', $arr_values); return array($this->name_component, '', $arr_values);
} }*/
/*
public function create_form()
{
$form=new SelectForm($this->name_component, $this->value);
$form->default_value=$this->default_value;
$form->required=$this->required;
$form->label=$this->label;
$form->arr_select=$this->arr_formatted;
return $form;
}*/
} }

View file

@ -23,7 +23,7 @@ class DateField extends PhangoField {
{ {
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::DateForm'; $this->form='PhangoApp\PhaModels\CoreForms\DateForm';
} }

View file

@ -22,7 +22,7 @@ class DoubleField extends PhangoField {
{ {
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::TextForm'; $this->form='PhangoApp\PhaModels\Forms\BaseForm';
} }

View file

@ -12,7 +12,7 @@ class EmailField extends PhangoField {
public $size=200; public $size=200;
public $value=""; public $value="";
public $label=""; public $label="";
public $form="PhangoApp\PhaModels\CoreForms::TextForm"; public $form='PhangoApp\PhaModels\Forms\BaseForm';
public $class=""; public $class="";
public $required=0; public $required=0;
public $quot_open='\''; public $quot_open='\'';

View file

@ -12,7 +12,7 @@ class FileField extends PhangoField {
public $value=""; public $value="";
public $label=""; public $label="";
public $required=0; public $required=0;
public $form="PhangoApp\PhaModels\CoreForms::FileForm"; public $form='PhangoApp\PhaModels\Forms\BaseForm';
public $name_file=""; public $name_file="";
public $path=""; public $path="";
public $url_path=""; public $url_path="";

View file

@ -28,7 +28,7 @@ class ForeignKeyField extends IntegerField{
{ {
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; $this->form='PhangoApp\PhaModels\Forms\SelectForm';
$this->related_model=&$related_model; $this->related_model=&$related_model;
$this->container_model=$this->related_model->name; $this->container_model=$this->related_model->name;
//Fields obtained from related_model if you make a query... //Fields obtained from related_model if you make a query...
@ -76,7 +76,9 @@ class ForeignKeyField extends IntegerField{
//Need checking if the value exists with a select_count //Need checking if the value exists with a select_count
$num_rows=$this->related_model->select_count('where '.$this->related_model.'.'.$this->related_model->idmodel.'='.$value, $this->related_model->idmodel); $this->related_model->set_conditions('where '.$this->related_model->name.'.'.$this->related_model->idmodel.'='.$value);
$num_rows=$this->related_model->select_count();
if($num_rows>0) if($num_rows>0)
{ {

View file

@ -15,7 +15,7 @@ class ImageField extends PhangoField {
public $value=""; public $value="";
public $label=""; public $label="";
public $required=0; public $required=0;
public $form="PhangoApp\PhaModels\CoreForms::ImageForm"; public $form='PhangoApp\PhaModels\Forms\BaseForm';
public $name_file=""; public $name_file="";
public $path=""; public $path="";
public $url_path=""; public $url_path="";

View file

@ -22,7 +22,7 @@ class IntegerField extends PhangoField {
{ {
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::TextForm'; $this->form='PhangoApp\PhaModels\Forms\BaseForm';
$this->only_positive=$only_positive; $this->only_positive=$only_positive;
$this->min_num=$min_num; $this->min_num=$min_num;
$this->max_num=$max_num; $this->max_num=$max_num;

View file

@ -26,7 +26,7 @@ class KeyField extends PhangoField {
{ {
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::TextForm'; $this->form='PhangoApp\PhaModels\Forms\BaseForm';
} }

View file

@ -17,7 +17,7 @@ class ParentField extends IntegerField{
$this->parent_model=&$parent_model; $this->parent_model=&$parent_model;
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; $this->form='PhangoApp\PhaModels\Forms\BaseForm';
} }

View file

@ -20,7 +20,7 @@ class PasswordField extends CharField {
{ {
$this->min_length=5; $this->min_length=5;
$this->size=$size; $this->size=$size;
$this->form='PhangoApp\PhaModels\CoreForms::PasswordForm'; $this->form='PhangoApp\PhaModels\Forms\PasswordForm';
} }

View file

@ -88,7 +88,7 @@ class PhangoField {
* Form define the function for use in forms... * Form define the function for use in forms...
*/ */
public $form="PhangoApp\PhaModels\CoreForms::TextForm"; public $form='PhangoApp\PhaModels\Forms\BaseForm';
/** /**
* Array for create initial parameters for form.. * Array for create initial parameters for form..
@ -108,6 +108,7 @@ class PhangoField {
public $default_value=''; public $default_value='';
/** /**
* Method used for internal tasks related with searchs. You can overwrite this method in your PhangoField object if you need translate the value that the user want search to a real value into the database. * Method used for internal tasks related with searchs. You can overwrite this method in your PhangoField object if you need translate the value that the user want search to a real value into the database.
*/ */
@ -168,7 +169,7 @@ class PhangoField {
/** /**
* Method for create a form, you only need subclass the field if you want another form different to default * Method for create a form, you only need subclass the field if you want another form different to default
*/ */
/*
public function create_form() public function create_form()
{ {
@ -179,7 +180,7 @@ class PhangoField {
return $form; return $form;
} }*/
} }

View file

@ -34,7 +34,7 @@ class PrimaryField extends PhangoField {
* By default, the form used for this field is HiddenForm. * By default, the form used for this field is HiddenForm.
*/ */
public $form="PhangoApp\PhaModels\CoreForms::HiddenForm"; public $form='PhangoApp\PhaModels\Forms\BaseForm';
/** /**
* By default this field is protected. * By default this field is protected.
@ -82,7 +82,7 @@ class PrimaryField extends PhangoField {
/** /**
* By default primaryfield use a hidden form * By default primaryfield use a hidden form
*/ */
/*
public function create_form() public function create_form()
{ {
@ -94,7 +94,7 @@ class PrimaryField extends PhangoField {
return $form; return $form;
} }*/
} }

View file

@ -12,7 +12,7 @@ class SerializeField extends PhangoField {
public $value=""; public $value="";
public $label=""; public $label="";
public $required=0; public $required=0;
public $form="TextForm"; public $form='PhangoApp\PhaModels\Forms\BaseForm';
public $quot_open='\''; public $quot_open='\'';
public $quot_close='\''; public $quot_close='\'';
public $std_error=''; public $std_error='';

View file

@ -22,7 +22,7 @@ class TextField extends PhangoField {
function __construct($multilang=0) function __construct($multilang=0)
{ {
$this->form='PhangoApp\PhaModels\CoreForms::TextAreaForm'; $this->form='PhangoApp\PhaModels\Forms\BaseForm';
$this->multilang=$multilang; $this->multilang=$multilang;
} }

View file

@ -25,7 +25,7 @@ class TextHTMLField extends PhangoField {
function __construct($multilang=0) function __construct($multilang=0)
{ {
$this->form='PhangoApp\PhaModels\CoreForms::TextAreaForm'; $this->form='PhangoApp\PhaModels\Forms\BaseForm';
$this->multilang=$multilang; $this->multilang=$multilang;
$this->set_safe_html_tags(); $this->set_safe_html_tags();

View file

@ -66,6 +66,15 @@ class UserPhangoModel extends Webmodel {
if(isset($post[$this->username]) && $post[$this->email]) if(isset($post[$this->username]) && $post[$this->email])
{ {
if(!isset($post['IdUser_admin']))
{
settype($_GET['IdUser_admin'], 'integer');
$post['IdUser_admin']=$_GET['IdUser_admin'];
}
if($this->check_user_exists($post[$this->username], $post[$this->email], $post['IdUser_admin'])) if($this->check_user_exists($post[$this->username], $post[$this->email], $post['IdUser_admin']))
{ {
@ -87,7 +96,7 @@ class UserPhangoModel extends Webmodel {
unset($post[$this->password]); unset($post[$this->password]);
} }
return parent::update($post, $safe_query); return parent::update($post, $safe_query);
} }

View file

@ -26,7 +26,7 @@ class SelectForm extends BaseForm{
foreach($this->arr_select as $value => $select) foreach($this->arr_select as $value => $select)
{ {
settype($arr_selected[$value], 'string'); settype($arr_selected[$value], 'string');
?> ?>

View file

@ -242,21 +242,21 @@ class Webmodel {
* *
*/ */
protected $conditions='WHERE 1=1'; public $conditions='WHERE 1=1';
/** /**
* A string where is set the order of query * A string where is set the order of query
* *
*/ */
protected $order_by=''; public $order_by='';
/** /**
* A string where is saved the limit of rows in query * A string where is saved the limit of rows in query
* *
*/ */
protected $limit=''; public $limit='';
/** /**
* A string where is saved the limit of rows in query * A string where is saved the limit of rows in query
@ -572,6 +572,13 @@ class Webmodel {
} }
public function show_conditions()
{
return $this->conditions;
}
/** /**
* This method insert a row in database using model how mirage of table. * This method insert a row in database using model how mirage of table.
* *
@ -742,7 +749,7 @@ class Webmodel {
} }
else else
{ {
return 1; return 1;
} }
@ -1573,7 +1580,15 @@ class Webmodel {
public function create_form($component_name) public function create_form($component_name)
{ {
$this->forms[$component_name]=$this->components[$component_name]->create_form(); $component=$this->components[$component_name];
$form_class=$component->form;
$this->forms[$component_name]=new $form_class($component_name, $component->value);
$this->forms[$component_name]->default_value=$component->default_value;
$this->forms[$component_name]->required=$component->required;
$this->forms[$component_name]->label=$component->label;
} }