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 addpublicationAction() { if (!$this->_rubric) { throw new Exception('rubric_id не определён'); } $form = new Publications_Framework_Form($this->_rubric->table_name); if ($form->getElement('uniq_id') && $this->getParam('uniq_id')) { $form->getElement('uniq_id')->setValue($this->getParam('uniq_id')); } if ($publication_id = $this->getParam('publication_id')) { $this->view->publication_id = $publication_id; $editData = $this->_modelPublications->fetchRow($this->_modelPublications->select()->where('publication_id = ?', $publication_id))->toArray(); $form->setDefaults($editData); } if ($route_id = $this->getParam('route_id')) { $this->view->route_id = $this->getParam('route_id'); } if (!sizeof($_POST) || !$form->isValid($_POST)) { $this->view->form = $form; } else { $post = $form->getPostData(); if ($route_id) { $post['route_id'] = $route_id; } if ($publication_id) { $this->_modelPublications->update($post, $this->_modelFields->getAdapter()->quoteInto('publication_id = ?', $publication_id)); } else { $this->_modelPublications->insert($post); } $this->renderScript('admin/addPublicationComplete.ajax.phtml'); } }
public function init() { $this->_modelList = new Modules_Publications_Model_List(); $this->_modelFields = new Modules_Publications_Model_Fields(); $this->_model = new Modules_Publications_Model_Table($this->_name); /* Устанавливаем рубрику к которой привязаны публикации */ $this->_routeId = Zend_Registry::get('RouteCurrentId'); if ($this->getParam('route_id')) { $this->_routeId = $this->getParam('route_id'); } if ($this->getParam('skip_route')) { $this->_routeId = null; } $this->view->route_id = $this->_routeId; $this->_model->setRouteId($this->_routeId); /* Находим текущий тип публикаций */ $this->_currentPublicationType = $this->_modelList->getRubricInfo($this->_name); if ($this->_currentPublicationType) { $this->view->pub_rubric_id = $this->_currentPublicationType->rubric_id; } else { throw new Exception('Тип публикации "' . $this->_name . '" не найден'); } }