示例#1
0
 /**
  * Все таблицы для хранения данных имеют префикс
  *
  */
 protected function _setup()
 {
     parent::_setup();
     $this->_cleanName = $this->_name;
     $this->_name = self::PREFIX_TABLE . $this->_name;
     if (false == array_key_exists($this->_cleanName, self::$setupedTables)) {
         $modelFields = new Modules_Publications_Model_Fields();
         $this->_tableProfile = $modelFields->fetchAllByTableName($this->_cleanName);
         foreach ($this->_tableProfile as $row) {
             if ($row->list_values) {
                 if (false == array_key_exists($row->list_values, self::$linkedData)) {
                     if ('routes' == $row->list_values) {
                         self::$linkedData[$row->list_values] = Modules_Router_Model_Router::getInstance()->getRoutesTreeHash();
                     } else {
                         $model = new self($row->list_values);
                         self::$linkedData[$row->list_values] = $model->fetchAll()->toArray();
                     }
                 }
                 self::$linkedFieldsTableData[$this->_cleanName . '_' . $row->name] = self::$linkedData[$row->list_values];
             }
         }
         self::$setupedTables[$this->_cleanName] = $this->_tableProfile;
     } else {
         $this->_tableProfile = self::$setupedTables[$this->_cleanName];
     }
 }
 /**
  * Добавляем / изменяем публикацию
  *
  */
 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');
     }
 }
示例#3
0
 public function isValid($value)
 {
     if (Zend_Controller_Front::getInstance()->getRequest()->getParam('field_id')) {
         return true;
     }
     // изменение публикации - валидатор пропускаем
     $isValid = true;
     $modelFields = new Modules_Publications_Model_Fields();
     $rubric_id = Zend_Controller_Front::getInstance()->getRequest()->getParam('rubric_id');
     $field = $modelFields->findFiled($value, $rubric_id);
     if (sizeof($field)) {
         $this->_error(self::ERROR, $value);
         $isValid = false;
     }
     return $isValid;
 }
示例#4
0
 /**
  * insert с учётом создания таблицы для хранения данных о публикации
  *
  * @param array $data
  * @return int
  */
 public function insert(array $data)
 {
     $rowID = parent::insert($data);
     if ($rowID) {
         /* создаём таблицу для хранения данных */
         $tableName = $data['table_name'];
         if (!System_Functions::tableExist($tableName)) {
             $_migrationManager = new Modules_Dbmigrations_Framework_Manager();
             $_migrationManager->upTo('Modules_Publications_Migrations_CreatePublicationAbstractTable', $tableName, false);
             // Добавляем базовые поля
             $filedsModel = new Modules_Publications_Model_Fields();
             $filedsModel->insert(array('rubric_id' => $rowID, 'name' => 'name', 'title' => 'Название', 'type' => 'text', 'validator' => '.*', 'sort' => 1));
             $filedsModel->insert(array('rubric_id' => $rowID, 'name' => 'active', 'title' => 'активно', 'type' => 'checkbox', 'default' => '1', 'sort' => 2));
         }
     }
     return $rowID;
 }
示例#5
0
 protected function _addElements()
 {
     if (!$this->_rubric) {
         throw new Exception('rubric_id не определён');
     }
     $fields = $this->_modelFields->getFieldsByRubric($this->_rubric->rubric_id);
     $arrayFields = array();
     foreach ($fields as $i => $field) {
         if (ZETTA_FRONT && $field->hidden_front) {
             continue;
         }
         $arrayFields[$i] = $field->toArray();
         $arrayFields[$i]['options'] = $field->toArray();
         if ($field['validator']) {
             $arrayFields[$i]['options']['validators'] = array('custom' => new Publications_Framework_Validator_CustomRegexp($field));
             $arrayFields[$i]['options']['required'] = 1;
         }
     }
     $this->_fields = $arrayFields;
     $this->setElements($this->_fields);
 }