Simple fix in foreignkeyfields and addded new features for pass arguments to forms via model field

This commit is contained in:
Antonio de la Rosa 2016-01-26 17:59:02 +01:00
parent ae2e94d224
commit a57f714cd2
5 changed files with 28 additions and 9 deletions

View file

@ -25,21 +25,22 @@ class ForeignKeyField extends IntegerField{
public $fields_related_model;
public $name_field_to_field;
function __construct($related_model, $size=11, $default=0)
function __construct($related_model, $size=11, $default_id=0, $name_field='', $name_value='')
{
$this->size=$size;
$this->form='PhangoApp\PhaModels\Forms\SelectForm';
$this->form='PhangoApp\PhaModels\Forms\SelectModelForm';
$this->related_model=&$related_model;
$this->container_model=$this->related_model->name;
//Fields obtained from related_model if you make a query...
$this->fields_related_model=array();
//Representative field for related model...
$this->name_field_to_field='';
$this->default_id=$default;
$this->name_field_to_field=$name_field;
$this->default_id=$default_id;
$this->quot_open='';
$this->quot_close='';
$this->protected=0;
$this->parameters=array(&$this->related_model, $name_field, $name_value);
}

View file

@ -103,7 +103,7 @@ class PhangoField {
public $form_loaded;
/**
* Array for create initial parameters for form..
* Array for create initial extra parameters for form.
*/
public $parameters=array();

View file

@ -25,7 +25,7 @@ class BaseForm {
public $enctype=0;
public function __construct($name, $value)
public function __construct($name, $value, $extra_parameters=array())
{
$this->label=$name;
$this->name=$name;

View file

@ -13,7 +13,7 @@ class SelectModelForm extends SelectForm{
public $model;
public $conditions='WHERE 1=1';
public $conditions=['WHERE 1=1', []];
public $field_value='';
@ -21,6 +21,19 @@ class SelectModelForm extends SelectForm{
public $raw_query=0;
public function __construct($name, $value, $model, $field_name, $field_value)
{
parent::__construct($name, $value);
$this->model=&$model;
$this->field_name=$field_name;
$this->field_value=$field_value;
}
public function form()
{
@ -32,7 +45,7 @@ class SelectModelForm extends SelectForm{
}
$this->model->set_conditions($this->conditions);
$this->model->set_conditions($this->conditions[0], $this->conditions[1]);
$query=$this->model->select(array($this->field_name, $this->field_value), $this->raw_query);

View file

@ -2032,7 +2032,12 @@ class Webmodel {
$form_class=$component->form;
$this->forms[$component_name]=new $form_class($component_name, $component->value);
//$this->forms[$component_name]=new $form_class($component_name, $component->value, $component->parameters);
$rc=new \ReflectionClass($form_class);
array_unshift($component->parameters, $component_name, $component->value);
$this->forms[$component_name]=$rc->newInstanceArgs($component->parameters);
$type_class=get_class($this->forms[$component_name]);