From 656f1e2700b8d6ef2f4493c1ee42696b34e91a0b Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Wed, 26 Jun 2013 01:11:32 +0300 Subject: [PATCH] verbose model column label --- ipf/form/model.php | 40 ++++++++++++++++++++--------------- ipf/orm/utils.php | 1 + ipf/orm/validator/verbose.php | 10 +++++++++ 3 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 ipf/orm/validator/verbose.php diff --git a/ipf/form/model.php b/ipf/form/model.php index e951121..9c1909f 100644 --- a/ipf/form/model.php +++ b/ipf/form/model.php @@ -58,10 +58,16 @@ class IPF_Form_Model extends IPF_Form function addDBField($name, $col) { - if ($name==$this->model->getTable()->getIdentifier()) + if ($name == $this->model->getTable()->getIdentifier()) return; - $defaults = array('blank' => true, 'verbose' => $name, 'help_text' => '', 'editable' => true); + $defaults = array( + 'blank' => true, + 'help_text' => '', + 'editable' => true, + 'verbose' => isset($col['verbose']) ? $col['verbose'] : $name, + ); + $type = $col['type']; if (isset($col['notblank'])) { @@ -96,25 +102,25 @@ class IPF_Form_Model extends IPF_Form function addDBRelation($name, $relation, $col) { - if (isset($col['notblank'])) - $blank = false; - else - $blank = true; + $rt = $relation->getType(); + if ($rt !== IPF_ORM_Relation::ONE_AGGREGATE && $rt !== IPF_ORM_Relation::MANY_AGGREGATE) + return; - if ($relation->getType()==IPF_ORM_Relation::ONE_AGGREGATE) { + $defaults = array( + 'blank' => !isset($col['notblank']), + 'help_text' => '', + 'editable' => true, + 'model' => $relation->getClass(), + 'verbose' => isset($col['verbose']) ? $col['verbose'] : $name, + ); + + if ($rt === IPF_ORM_Relation::ONE_AGGREGATE) { $name .= "_id"; $db_field = new IPF_Form_DB_Foreignkey('',$name); - $defaults = array('blank' => $blank, 'verbose' => $name, 'help_text' => '', 'editable' => true, 'model'=>$relation->getClass()); - $form_field = $db_field->formField($defaults); - $this->fields[$name] = $form_field; - return; - } - if ($relation->getType()==IPF_ORM_Relation::MANY_AGGREGATE) { + $this->fields[$name] = $db_field->formField($defaults); + } else if ($rt === IPF_ORM_Relation::MANY_AGGREGATE) { $db_field = new IPF_Form_DB_ManyToMany('',$name); - $defaults = array('blank' => $blank, 'verbose' => $name, 'help_text' => '', 'editable' => true, 'model'=>$relation->getClass()); - $form_field = $db_field->formField($defaults); - $this->fields[$name] = $form_field; - return; + $this->fields[$name] = $db_field->formField($defaults); } } diff --git a/ipf/orm/utils.php b/ipf/orm/utils.php index 4eba188..c87e16d 100644 --- a/ipf/orm/utils.php +++ b/ipf/orm/utils.php @@ -58,6 +58,7 @@ class IPF_ORM_Utils { 'image', 'html', 'uploadTo', + 'verbose', ); } diff --git a/ipf/orm/validator/verbose.php b/ipf/orm/validator/verbose.php new file mode 100644 index 0000000..0a6478e --- /dev/null +++ b/ipf/orm/validator/verbose.php @@ -0,0 +1,10 @@ +