Beispiel #1
0
 protected function afterSave()
 {
     if (!$this->isNewRecord) {
         $idOldPhpScript = $this->getPkBeforeSave();
         if ($this->id_php_script_type != $idOldPhpScript) {
             PhpScriptInstance::model()->updateAll(array('id_php_script_type' => $this->id_php_script_type), 'id_php_script_type=:id', array(':id' => $idOldPhpScript));
             DaObjectViewColumn::model()->updateAll(array('handler' => $this->id_php_script_type), 'handler=:id', array(':id' => $idOldPhpScript));
         }
     }
     return parent::afterSave();
 }
Beispiel #2
0
 protected function afterSave()
 {
     parent::afterSave();
     if ($this->isNewRecord) {
         $idObject = $this->id_object;
         if ($this->object_type == self::OBJECT_TYPE_TABLE && $this->table_name != "") {
             // Если создается объект у которого тип=Таблица, то создаем свойство Первичного ключа
             $p = ObjectParameter::newModel('ObjectParameter');
             $p->id_object = $idObject;
             $p->id_parameter_type = DataType::PRIMARY_KEY;
             $p->caption = 'id';
             $fieldName = 'id_' . str_replace(array('da_', 'pr_'), '', $this->table_name);
             $p->field_name = $fieldName;
             $p->id_parameter = $idObject . '-' . str_replace('_', '-', $fieldName);
             $p->setIsRequired(true);
             $p->save();
         }
     } else {
         if ($this->id_object != $this->getPkBeforeSave()) {
             ObjectParameter::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave()));
             ObjectParameter::model()->updateAll(array('add_parameter' => $this->id_object), 'id_parameter_type=7 AND add_parameter=:obj', array(':obj' => $this->getPkBeforeSave()));
             DaObjectView::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave()));
             DaObjectViewColumn::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave()));
             File::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave()));
             Search::model()->updateAll(array('id_object' => $this->id_object), 'id_object=:obj', array(':obj' => $this->getPkBeforeSave()));
         }
     }
 }
 public function processModel(CEvent $event)
 {
     /**
      * @var $model DaObject
      */
     $model = $this->model;
     $idObject = $model->getIdInstance();
     $idView = null;
     if (HU::post("create_rep") == 1) {
         //Создать представление с введённым именем
         $name = trim(HU::post("create_rep_name"));
         $view = null;
         if ($name != "") {
             $view = new DaObjectView();
             $id = $idObject . '-view-main';
             while (DaObjectView::model()->exists('id_object_view=:id', array(':id' => $id))) {
                 $id = $idObject . '-view-view' . rand(1, 100);
             }
             $view->id_object_view = $id;
             $view->name = $name;
             $view->id_object = $idObject;
             $parent = $model->getFieldByType(DataType::ID_PARENT);
             if ($parent != null) {
                 $view->id_parent = $parent;
             }
             //Сортировка
             $view->sql_order_by = $model->getOrderBy();
             $view->save();
             $idView = $view->getIdInstance();
         }
     }
     $columnsForm = HU::post('column');
     if (count($columnsForm)) {
         if (is_null($idView)) {
             //Свойства стоят, представления нет, приписываем имеющемуся
             //Если у объекта есть единственное представление, приписываем отмеченные галочки ему
             $view = DaObjectView::model()->findAll('id_object=:id', array(':id' => $idObject));
             if (count($view) != 1) {
                 return;
             }
             $idView = $view[0]->getIdInstance();
         }
         //Уже приписанные представлению колонки
         $already = array();
         $columns = DaObjectViewColumn::model()->findAll('id_object_view=:id', array(':id' => $idView));
         foreach ($columns as $c) {
             $already[] = $c->id_object_parameter;
         }
         foreach ($columnsForm as $col) {
             if (in_array($col, $already)) {
                 continue;
             }
             $p = $model->getParameterObjectByIdParameter($col);
             if ($p == null) {
                 continue;
             }
             $column = new DaObjectViewColumn();
             $column->id_object_view_column = $idView . '-' . str_replace('_', '-', $p->getFieldName());
             $column->id_object_view = $idView;
             $column->id_object = $idObject;
             $column->id_object_parameter = $p->getIdParameter();
             $column->caption = $p->getCaption();
             $column->id_data_type = $p->getType();
             $column->field_name = $p->getFieldName();
             $column->save();
         }
     }
 }
Beispiel #4
0
 protected function afterSave()
 {
     if ($this->isNewRecord) {
         $idObject = $this->id_object;
         $notChangeObject = array(20, 21);
         if (!in_array($idObject, $notChangeObject)) {
             $this->sqlChange($this, 'insert');
         }
     } else {
         $pk = $this->getPkBeforeSave();
         $idOldParameter = $pk['id_parameter'];
         if ($this->id_parameter != $idOldParameter) {
             DaObject::model()->updateAll(array('id_field_order' => $this->id_parameter), 'id_field_order=:param', array(':param' => $idOldParameter));
             DaObject::model()->updateAll(array('id_field_caption' => $this->id_parameter), 'id_field_caption=:param', array(':param' => $idOldParameter));
             File::model()->updateAll(array('id_parameter' => $this->id_parameter), 'id_parameter=:param', array(':param' => $idOldParameter));
             DaObjectViewColumn::model()->updateAll(array('id_object_parameter' => $this->id_parameter), 'id_object_parameter=:param', array(':param' => $idOldParameter));
         }
     }
     return parent::afterSave();
 }
Beispiel #5
0
 private function uninstallCategory($data)
 {
     Yii::app()->authManager->removeAuthItemObject('list', $data['id_object_category']);
     $columns = DaObjectViewColumn::model()->findAll('id_object=:id_object AND field_name=:field', array(':id_object' => $data['id_object'], ':field' => 'id_news_category'));
     foreach ($columns as $column) {
         /**
          * @var $column DaObjectViewColumn
          */
         $column->visible = 0;
         $column->update(array('visible'));
     }
 }
Beispiel #6
0
 protected function afterSave()
 {
     if (!$this->isNewRecord) {
         $idOldView = $this->getPkBeforeSave();
         if ($this->id_object_view != $idOldView) {
             DaObjectViewColumn::model()->updateAll(array('id_object_view' => $this->id_object_view), 'id_object_view=:view', array(':view' => $idOldView));
         }
     }
     return parent::afterSave();
 }