/** * Adds an element BusUnitId.<br/><br/> * Defaults:<br/> * name = busunit_id<br/> * requires = true<br/> * label = Business unit<br/> * placeholder = 'Choose a business unit'<br/> * dimension = 6<br/> * modelfield = busunit_id<br/> * firstvaluenull = true * * @param Zend_Form $form The Zend_Form object where the element will be added * @param array $options The options to pass in the element */ public function addElementBusunitId($form, $options = array()) { $elementName = isset($options['name']) ? $options['name'] : 'busunit_id'; $modelField = isset($options['modelfield']) ? $options['modelfield'] : 'busunit_id'; $form->addElement('select', $elementName, array('filters' => array('StringTrim'), 'label' => isset($options['label']) ? $options['label'] : 'Business unit', 'dimension' => isset($options['dimension']) ? $options['dimension'] : 6, 'placeholder' => 'Choose a business unit', 'required' => isset($options['required']) ? $options['required'] : true, 'value' => $this->_model ? $this->_model->{$modelField} : '')); $el = $form->getElement($elementName); $firstvaluenull = isset($options['firstvaluenull']) ? $options['firstvaluenull'] : true; if ($firstvaluenull) { $el->addMultiOption(null, null); } ///////////////////// // Add Headquarters $bud = new Busunit_Domain_Headquarters(); $bu = $bud->getByAppAccount(Zend_Auth::getInstance()->getIdentity()->appaccount_id); $el->addMultiOption($bu->getId(), $bu->getName()); // Add Branchs $bud = new Busunit_Domain_Branch(); $bu = $bud->getAll('name'); foreach ($bu as $busunit) { $el->addMultiOption($busunit->getId(), $busunit->getName()); } // set value if ($this->_model && $this->_model->{$modelField}) { $el->setValue($this->_model->{$modelField}); } else { $el->setValue(null); } }
public function getBusunit() { if (is_null($this->busunit) && $this->busunit_id) { $bud = new Busunit_Domain_Branch(); $this->busunit = $bud->getById($this->busunit_id); } return $this->busunit; }