From: <gem...@li...> - 2011-12-16 15:03:14
|
Revision: 366 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=366&view=rev Author: mennodekker Date: 2011-12-16 15:03:03 +0000 (Fri, 16 Dec 2011) Log Message: ----------- Moved some stuff from ModelTabFormSnipperGeneric to ModelFormSnippetAbstract so normal and tabform can be changed by changing the base snippet Modified Paths: -------------- trunk/library/classes/Gems/Snippets/ModelTabFormSnippetGeneric.php trunk/library/classes/MUtil/Snippets/ModelFormSnippetAbstract.php Modified: trunk/library/classes/Gems/Snippets/ModelTabFormSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Snippets/ModelTabFormSnippetGeneric.php 2011-12-16 12:37:11 UTC (rev 365) +++ trunk/library/classes/Gems/Snippets/ModelTabFormSnippetGeneric.php 2011-12-16 15:03:03 UTC (rev 366) @@ -55,69 +55,6 @@ protected $_form; /** - * Array of item names still to be added to the form - * - * @var array - */ - protected $_items; - - /** - * Add items to the bridge, and remove them from the items array - * - * @param MUtil_Model_FormBridge $bridge - * @param string $element1 - * - * @return void - */ - protected function addItems($bridge, $element1) - { - $args = func_get_args(); - if (count($args)<2) { - throw new Gems_Exception_Coding('Use at least 2 arguments, first the bridge and then one or more idividual items'); - } - - $bridge = array_shift($args); - $elements = $args; - - //Remove the elements from the _items variable - $this->_items = array_diff($this->_items, $elements); - - //And add them to the bridge - foreach($elements as $name) { - if ($label = $this->model->get($name, 'label')) { - $bridge->add($name); - } else { - $bridge->addHidden($name); - } - } - } - - /** - * Adds elements from the model to the bridge that creates the form. - * - * Overrule this function to add different elements to the browse table, without - * having to recode the core table building code. - * - * @param MUtil_Model_FormBridge $bridge - * @param MUtil_Model_ModelAbstract $model - * @param array $items - */ - protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model, $items = null) - { - //Get all elements in the model if not already done - $this->initItems(); - - //Now add all remaining items to the last last tab (if any) - foreach($this->_items as $name) { - if ($label = $model->get($name, 'label')) { - $bridge->add($name); - } else { - $bridge->addHidden($name); - } - } - } - - /** * Perform some actions on the form, right before it is displayed but already populated * * Here we add the table display to the form. @@ -156,14 +93,4 @@ return $form; } - - /** - * Initialize the _items variable to hold all items from the model - */ - protected function initItems() - { - if (is_null($this->_items)) { - $this->_items = $this->model->getItemsOrdered(); - } - } } \ No newline at end of file Modified: trunk/library/classes/MUtil/Snippets/ModelFormSnippetAbstract.php =================================================================== --- trunk/library/classes/MUtil/Snippets/ModelFormSnippetAbstract.php 2011-12-16 12:37:11 UTC (rev 365) +++ trunk/library/classes/MUtil/Snippets/ModelFormSnippetAbstract.php 2011-12-16 15:03:03 UTC (rev 366) @@ -60,7 +60,14 @@ protected $_form; /** + * Array of item names still to be added to the form * + * @var array + */ + protected $_items; + + /** + * * @var Zend_Form_Element_Submit */ protected $_saveButton; @@ -149,8 +156,37 @@ */ protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model) { - foreach($model->getItemsOrdered() as $name) { - if ($label = $model->get($name, 'label')) { + //Get all elements in the model if not already done + $this->initItems(); + + //And any remaining item + $this->addItems($bridge, $this->_items); + } + + /** + * Add items to the bridge, and remove them from the items array + * + * @param MUtil_Model_FormBridge $bridge + * @param string $element1 + * + * @return void + */ + protected function addItems(MUtil_Model_FormBridge $bridge, $element1) + { + $args = func_get_args(); + if (count($args)<2) { + throw new Gems_Exception_Coding('Use at least 2 arguments, first the bridge and then one or more idividual items'); + } + + $bridge = array_shift($args); + $elements = MUtil_Ra::flatten($args); + + //Remove the elements from the _items variable + $this->_items = array_diff($this->_items, $elements); + + //And add them to the bridge + foreach($elements as $name) { + if ($label = $this->model->get($name, 'label')) { $bridge->add($name); } else { $bridge->addHidden($name); @@ -323,6 +359,16 @@ } /** + * Initialize the _items variable to hold all items from the model + */ + protected function initItems() + { + if (is_null($this->_items)) { + $this->_items = $this->model->getItemsOrdered(); + } + } + + /** * Makes sure there is a form. */ protected function loadForm() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |