/** * 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 getAction() { try { $head = new Busunit_Model_Headquarters(); $user = Zend_Auth::getInstance()->getIdentity(); $domain = new Busunit_Domain_Headquarters(); $head = $domain->getByAppAccount($user->appaccount_id); // if there is no organization for this appaccount, create the only one allowed // TODO move this logic to domain class if (is_null($head)) { $translate = Zend_Registry::get('Zend_Translate'); $head = new Busunit_Model_Headquarters(); $head->setName($translate->_('Default value - please change it')); $head->setAppaccount_id($user->appaccount_id); $domain->setBusunit($head); $head = $domain->create($user->appaccount_id); $head = $domain->getById($head); } } catch (Exception $exc) { $this->_helper->flashMessenger->addMessage(array('error' => $exc->getMessage())); } $this->view->headquarters = $head; }