addElementPrefixPath('App_Settings_Validate', 'App/Settings/Validate/', 'validate'); return $this; } protected function _getDataObj() { if (null === $this->_dataObj) { $this->_dataObj = new App_Settings_Obj(); } return $this->_dataObj; } public function setIdCategory($idCategory) { $this->_idCategory = $idCategory; $this->_getDataObj()->setIdCategory($this->_idCategory); return $this; } protected function _initElements() { $this->addElement('hidden', 'idCategory', array('value' => $this->_idCategory)); $fields = $this->_getDataObj()->getList(); foreach ($fields as $field) { $elementType = ucfirst($field['fieldType']); $options = $this->_getDataObj()->getFieldOptions($field['name']); switch ($elementType) { case 'Emails': $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'rows' => 5, 'description' => $field['description'], 'decorators' => array( array('Description', array('tag' => 'p', 'class' => 'description')), 'ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'dd', 'id' => $field['name'] . '-element')), array('Label', array('tag' => 'dt')) ) ); $this->addElement('textarea', $field['name'], array_merge($defaultOptions, $options)); $this->{$field['name']}->addValidator('EmailAddresses') ->addFilter('EmailAddresses'); $this->{$field['name']}->getDecorator('Label')->setOption('escape', false); break; case 'Select': $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'size' => $options['size'], 'description' => $field['description'], 'multiple' => $options['multiple'] ); $this->addElement($elementType, $field['name'], array_merge($defaultOptions, $options)); break; case 'HtmlEditor': $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'description' => $field['description'] ); $this->addElement($elementType, $field['name'], array_merge($defaultOptions, $options)); break; case 'Header': if (!empty($field['label'])) { $label = $field['label']; } else { $label = $field['value']; } $defaultOptions = array('label' => $label); $this->addElement($elementType, $field['name'], array_merge($defaultOptions, $options)); break; case 'Static': $defaultOptions = array('label' => $field['label'], 'value' => $field['value']); $this->addElement($elementType, $field['name'], array_merge($defaultOptions, $options)); break; case 'Url': $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'description' => $field['description'] ); $this->addElement('text', $field['name'], array_merge($defaultOptions, $options)); $this->{$field['name']}->addValidator('Url')->addFilter('StringTrim'); break; default: $defaultOptions = array( 'label' => $field['label'], 'required' => ('y' == $field['required']), 'description' => $field['description'] ); if (class_exists($field['fieldType'])) { $reflection = new ReflectionClass($field['fieldType']); if ($reflection->isSubclassOf('Zend_Form_Element')) { $element = $reflection->newInstance($field['name'], array_merge($defaultOptions, $options)); $this->addElement($element); break; } } $this->addElement($elementType, $field['name'], array_merge($defaultOptions, $options)); break; } $element = $this->getElement($field['name']); if ($element->isRequired() && $element->getValidator('Int')) { if (!$element->getValidator('NotEmpty')) { $validators = $element->getValidators(); $notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true); array_unshift($validators, $notEmpty); $element->setValidators($validators); } $types = array(Zend_Validate_NotEmpty::INTEGER, Zend_Validate_NotEmpty::ZERO, Zend_Validate_NotEmpty::SPACE, Zend_Validate_NotEmpty::NULL, Zend_Validate_NotEmpty::STRING); $element->getValidator('NotEmpty')->setType($types); } } return $this; } public function render(Zend_View_Interface $view = null) { /** @var $doc App_Doc_Admin */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/lib/settings.js'); $doc->addInitFunction('App_Settings.init', array($this->getId())); return parent::render($view); } }