loadDefaultDecoratorsIsDisabled()) { return $this; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('FormElements'); $this->addDecorator(array('items-tbody' => 'HtmlTag'), array('tag' => 'tbody')); $this->addDecorator('CommitteeTFoot'); $this->addDecorator('CommitteeTHead'); $this->addDecorator( array('items-table' => 'HtmlTag'), array('tag' => 'table', 'class' => 'table table-striped') ); $this->addDecorator(array('element-dd' => 'HtmlTag'), array('tag' => 'dd')); $this->addDecorator('Label', array('tag' => 'dt')); } return $this; } public function initRender() { if (!$this->loadDefaultDecoratorsIsDisabled()) { $id = $this->getId(); $this->getDecorator('element-dd')->setOption('id', $id . '-element'); $this->getDecorator('items-table')->setOption('id', $id . '-table'); if (!$this->getLabel()) { /** @var \Qs_Form_Decorator_Label $label */ $label = $this->getDecorator('Label'); $label->setTagOption('class', 'hidden'); } } return parent::initRender(); } public function setLabel($label) { $this->_label = $label; return $this; } public function getLabel() { return $this->_label; } public function isRequired() { return $this->_isRequired; } public function setRequired($value) { $this->_isRequired = (bool) $value; return $this; } protected function _addResources() { /** @var \App_Doc_Admin $doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/app/user/committee-sub-form.js'); $renderUrl = $this->_parentForm->getAction(); $itemSubForm = $this->getSubForms(); $itemSubForm = reset($itemSubForm); $scriptOptions = array( 'formId' => $this->_parentForm->getId(), 'subFormId' => $this->getFullId(), 'renderUrl' => $renderUrl, 'itemClass' => get_class($itemSubForm), 'itemName' => $this->getName(), ); $doc->addInitObject('app.user.CommitteeSubForm', array($scriptOptions)); return parent::_addResources(); } public function addSubForm(\Zend_Form $form, $name, $order = null) { /** @var \Zend_Form_Element $element */ foreach ($form as $element) { if (!($element instanceof Zend_Form_Element_Hidden) && !($element instanceof CommitteeItemOptions)) { $element->setRequired($this->isRequired()); switch ($element->getName()) { case 'committeeId': $this->_addCommitteeIdValidators($form); break; case 'positionId': $this->_addPositionIdValidators($form); break; } } } return parent::addSubForm($form, $name, $order); } protected function _addCommitteeIdValidators(\Zend_Form $form) { $this->_addRequiredValidator($form, 'committeeId'); return $this; } protected function _addPositionIdValidators(\Zend_Form $form) { $this->_addRequiredValidator($form, 'positionId'); return $this; } protected function _addRequiredValidator(\Zend_Form $form, $fieldName) { $element = $form->getElement($fieldName); $required = new Zend_Validate_Callback(array($form, 'validateRequired')); $required->setOptions(array('fieldName' => $fieldName)); $required->setMessage($element->getLabel() . ' is required', Zend_Validate_Callback::INVALID_VALUE); $element->addValidator($required, true); return $this; } public function getMessages($name = null, $suppressArrayNotation = false) { if (null !== $name) { if (isset($this->_elements[$name])) { return $this->getElement($name)->getMessages(); } else if (isset($this->_subForms[$name])) { return $this->getSubForm($name)->getMessages(null, true); } /** @var CommitteeItemSubForm $subForm */ foreach ($this->getSubForms() as $subForm) { if ($subForm->isArray()) { $belongTo = $subForm->getElementsBelongTo(); if ($name == $this->_getArrayName($belongTo)) { return $subForm->getMessages(null, true); } } } } $customMessages = $this->_getErrorMessages(); $messages = array(); /** @var \Zend_Form_Element $element */ foreach ($this->getElements() as $name => $element) { $eMessages = $element->getMessages(); if (!empty($eMessages)) { $messages[$name] = $eMessages; } } foreach ($this->getSubForms() as $key => $subForm) { $merge = $subForm->getMessages(null, true); if (!empty($merge)) { if (!$subForm->isArray()) { $merge = array($key => $merge); } else { $merge = $this->_attachToArray($merge, $subForm->getElementsBelongTo()); } $messages = $this->_array_replace_recursive($messages, $merge); } } if (!$suppressArrayNotation && $this->isArray() && !$this->_getIsRendered()) { $messages = $this->_attachToArray($messages, $this->getElementsBelongTo()); } return Qs_Array::mergeAssoc($messages, $customMessages); } }