Beispiel #1
0
 protected function getFormInstance()
 {
     if ($this->z_form === NULL) {
         $this->z_form = new Z_Admin_Form();
         //добавляем элементы формы на основании даннх из БД
         $modelForms = new Z_Model_Resourceforms();
         $modelFormsParams = new Z_Model_Resourceformsparams();
         $elements = $modelForms->fetchAll(array('resourceid=?' => $this->z_resourceInfo->id), 'orderid asc');
         $isRoot = Z_Auth::getInstance()->getUser()->getRole() == 'root';
         foreach ($elements as $element) {
             if ($element->type == 'MultiImage') {
                 $element->type = 'File';
             }
             if ($element->show_check) {
                 //    				try{
                 if (!eval($element->show_check)) {
                     continue;
                 }
                 //    				}
                 //    				catch (Exception $e){
                 //    					continue;
                 //    				}
             }
             $elementClass = 'Z_Admin_Form_Element_' . ucfirst($element->type);
             if ($element->only_for_root && $isRoot || !$element->only_for_root) {
                 $elementOptions = array('label' => $element->label, 'description' => $element->description, 'required' => $element->required, 'value' => $element->value);
                 $params = $modelFormsParams->fetchAll(array('formid=?' => $element->id));
                 foreach ($params as $param) {
                     $elementOptions[$param->title] = $param->is_eval ? eval($param->value) : $param->value;
                 }
                 $this->z_form->addElement(new $elementClass($element->field, $elementOptions));
             }
         }
         //пользовательское доопределение формы
         $this->getForm($this->z_form);
         //разбиваем элементы на группы
         $groupArray = array();
         foreach ($this->z_form->getElements() as $el) {
             if ($group = $el->getAttrib('displayGroup')) {
                 $groupId = Z_Transliterator::translateCyr($group);
                 if (!isset($groupArray[$group])) {
                     $groupArray[$group] = array();
                 }
                 $groupArray[$group][] = $el->getName();
             }
         }
         foreach ($groupArray as $groupKey => $groupEl) {
             $this->z_form->addDisplayGroup($groupEl, Z_Transliterator::translateCyr($groupKey), array('legend' => $groupKey));
         }
         $this->addSubmitButtonsToForm($this->z_form);
         $this->z_form->getElement('submit')->removeDecorator('Label');
         if (!$this->z_form->getAction()) {
             $this->z_form->setAction($this->view->url(array('id' => $this->_getParam('id'))));
         }
     }
     return $this->z_form;
 }