Modify the forms system

This commit is contained in:
Antonio de la Rosa 2015-08-25 18:10:49 +02:00
parent faa1d76350
commit 1cc3c8cf34
5 changed files with 106 additions and 77 deletions

View file

@ -18,14 +18,13 @@ class ForeignKeyField extends IntegerField{
//field related in the model...
public $related_model='';
public $container_model='';
public $null_relation=1;
public $params_loading_mod=array();
public $default_id=0;
public $yes_zero=0;
public $fields_related_model;
public $name_field_to_field;
function __construct($related_model, $size=11, $null_relation=1, $default=0)
function __construct($related_model, $size=11, $default=0)
{
$this->size=$size;
@ -38,10 +37,8 @@ class ForeignKeyField extends IntegerField{
$this->name_field_to_field='';
$this->null_relation=$null_relation;
$this->default_id=$default;
//PhangoVar::$model[$related_model]->related_models_delete[]=array('model' => $this->name_model, 'related_field' => $this->name_component);
//echo get_parent_class();
$this->quot_open='';
$this->quot_close='';
}
@ -56,8 +53,6 @@ class ForeignKeyField extends IntegerField{
}
else
{
//show_error('You need load model before set relantionship', $this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model', $output_external='');
throw new \Exception($this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model');
@ -86,13 +81,6 @@ class ForeignKeyField extends IntegerField{
if($num_rows>0)
{
if($value==0 && $this->yes_zero==0)
{
return NULL;
}
return $value;
@ -100,18 +88,9 @@ class ForeignKeyField extends IntegerField{
else
{
if($this->default_id<=0 && $this->yes_zero==0)
{
return NULL;
}
else
{
return $this->default_id;
return $this->default_id;
}
}
@ -130,11 +109,8 @@ class ForeignKeyField extends IntegerField{
function get_type_sql()
{
$arr_null[0]='NOT NULL';
$arr_null[1]='NULL';
return 'INT('.$this->size.') '.$arr_null[$this->null_relation];
return 'INT('.$this->size.') NOT NULL DEFAULT "0"';
}

View file

@ -101,6 +101,12 @@ class PhangoField {
public $protected=false;
/**
* A property that set the 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.
*/
@ -158,6 +164,22 @@ class PhangoField {
}
/**
* Method for create a form, you only need subclass the field if you want another form different to default
*/
public function create_form()
{
$form=new BaseForm($this->name, $this->value);
$form->default_value=$this->default_value;
$form->required=$this->required;
$form->label=$this->label;
return $form;
}
}

View file

@ -35,6 +35,12 @@ class PrimaryField extends PhangoField {
public $form="PhangoApp\PhaModels\CoreForms::HiddenForm";
/**
* By default this field is protected.
*/
public $protected=true;
/**
* Check function that convert the value on a PrimaryField value.
*