public function addElement($element, $name = null, $options = null) { switch ($element) { case 'html': $element = 'textarea'; break; case 'file_dialog': $element = 'text'; $options['z_image_dialog'] = 1; break; case 'date': $element = 'text'; $options['z_date'] = 1; break; case 'datetime': $element = 'text'; $options['z_date_time'] = 1; break; case 'captcha': // throw new Exception('Мы ещё не подключили этот тип поля'); $options['captcha'] = array('captcha' => 'Image', 'font' => SYSTEM_PATH . '/public/font/captcha_font.ttf', 'imgDir' => TEMP_PATH . DS . 'Captcha', 'imgUrl' => HTTP_HOST . '/Temp/Captcha/', 'wordLen' => 5, 'lineNoiseLevel' => 2, 'dotNoiseLevel' => 50); break; case 'route': $element = 'select'; $options['list_values'] = 'routes'; break; } if (array_key_exists('default', $options) && $options['default']) { $options['value'] = $options['default']; } if (array_key_exists('title', $options) && $options['title']) { $options['label'] = $options['title']; } $elementObject = parent::addElement($element, $name, $options); if (array_key_exists('list_values', $options) && $options['list_values']) { switch ($element) { case 'multiCheckbox': case 'radio': case 'select': if ('routes' == $options['list_values']) { $this->getElement($name)->addMultiOptions(Modules_Router_Model_Router::getInstance()->getRoutesTreeHash()); } else { $model = new Modules_Publications_Model_Table($options['list_values']); $options = $model->getAssocArray('publication_id', 'name'); $this->getElement($name)->addMultiOptions($options); } break; } } return $elementObject; }
public function addAction() { $form = new Zetta_Form(Zend_Registry::get('config')->Router->form); $parentMenuId = $form->getElement('parent_route_id'); $parentMenuId->addMultiOptions($this->_modelRoutes->getRoutesTreeHash()); $defaultActions = $form->getElement('default_modules'); $defaultActions->addMultiOptions($this->_modelRoutes->getDefaultModules()); if ($pId = $this->getParam('parent_route_id')) { $parentMenuId->setValue($pId); } if ($route_id = $this->getParam('route_id')) { $this->view->route_id = $route_id; $editRouteData = $this->_modelRoutes->getItem($route_id); $form->setDefaults($editRouteData); $exist_modules = array_keys($this->_modelRoutes->getDefaultModules()); if ($editRouteData['module'] != 'default' && !in_array($editRouteData['module'] . '~' . $editRouteData['controller'], $exist_modules)) { $type = $form->getElement('type'); $type->setValue('free'); } else { $defaultActions->setValue($editRouteData['module'] . '~' . $editRouteData['controller']); $form->addElement('hidden', 'action_value', array('value' => $editRouteData['module'] . '~' . $editRouteData['controller'] . '~' . $editRouteData['action'])); } if ($route_id == 1) { $form->removeElement('uri'); } } $selectActionsObject = $form->getElement('default_actions'); $selectActionsObject->setRegisterInArrayValidator(false); if (!sizeof($_POST) || !$form->isValid($_POST)) { $this->view->form = $form; } else { $arrayData = array('name' => $form->getValue('name'), 'parent_route_id' => $route_id == 1 ? new Zend_Db_Expr('NULL') : intval($form->getValue('parent_route_id')), 'uri' => $route_id == 1 ? '' : $form->getValue('uri'), 'disable' => (bool) $form->getValue('disable'), 'module' => $form->getValue('module'), 'controller' => $form->getValue('controller'), 'action' => $form->getValue('action'), 'parms' => $form->getValue('parms')); if ($route_id) { $this->_modelRoutes->update($arrayData, $this->_modelRoutes->getAdapter()->quoteInto('route_id = ?', $route_id)); } else { $this->_modelRoutes->insert($arrayData); } $this->renderScript('admin/addComplete.ajax.phtml'); } }