예제 #1
0
 public function actionDelete($page_id = null, $item_id = null, $id = null)
 {
     $model = ModuleList4Files::model()->findByPk($id);
     if ($model != null) {
         $fileId = $model->file_id;
         if ($model->delete()) {
             Files::model()->deleteFile($fileId, $this->module->id);
         }
     }
     $this->redirect(Yii::app()->baseUrl . '?r=' . $this->module->id . '/main/update&page_id=' . $page_id . '&id=' . $item_id . '&/#!/tab_third');
 }
예제 #2
0
 public function actionUpdate($page_id = null, $id = null)
 {
     if (!is_null($page_id) && Pages::model()->existsPage($page_id)) {
         $mpage_id = ModulesInPages::model()->getLink((int) $page_id, $this->module->id);
         if (!is_null($id) && ModuleList4::model()->existsItem($mpage_id, $id)) {
             // обработка параметров с одним значением
             if (isset($_POST['ModuleList4Values']) && is_array($_POST['ModuleList4Values']) && count($_POST['ModuleList4Values'])) {
                 foreach ($_POST['ModuleList4Values'] as $key => $value) {
                     $key = (int) $key;
                     $data_type_id = ModuleList4Params::model()->findByPk($key)->data_type_id;
                     if (ModuleList4Values::model()->existsItem($id, $key)) {
                         $params_value = ModuleList4Values::model()->getItem($id, $key);
                         if ($data_type_id == 7) {
                             $old_file_id = (int) $params_value->value;
                         }
                         ModuleList4Values::model()->new_value($id, $key, '0');
                         $params_value->attributes = array('value' => $value);
                         if ($params_value->save() && $data_type_id == 7) {
                             $file_id = (int) $value;
                             if ($file_id > 0) {
                                 Files::model()->saveTempFile($file_id);
                             }
                             if ($old_file_id != $file_id) {
                                 Files::model()->deleteFile($old_file_id, $this->module->id);
                             }
                         }
                         $criteria = new CDbCriteria();
                         $criteria->condition = 'param_id = :param_id AND item_id = :item_id AND id <> :id';
                         $criteria->params = array('param_id' => $key, 'item_id' => $id, 'id' => $params_value->id);
                         ModuleList4Values::model()->deleteAll($criteria);
                     } else {
                         $params_value = new ModuleList4Values();
                         $params_value->attributes = array('param_id' => $key, 'item_id' => $id, 'value' => $value);
                         if ($params_value->save() && $data_type_id == 7) {
                             $file_id = (int) $value;
                             if ($file_id > 0) {
                                 Files::model()->saveTempFile($file_id);
                             }
                         }
                     }
                 }
             }
             // обработка файлов
             if (isset($_POST['ModuleList4Files'])) {
                 $list4file = new ModuleList4Files();
                 $list4file->short = $_POST['ModuleList4Files']['short'];
                 $list4file->file_id = $_POST['ModuleList4Files']['file_id'];
                 $list4file->item_id = $id;
                 if ($list4file->save()) {
                     Files::model()->saveTempFile((int) $list4file->file_id);
                 } else {
                     Files::model()->deleteFile($list4file->file_id, $this->module->id);
                     Yii::app()->user->setFlash('message', '<p style="color:red;">Ошибка</p>');
                 }
             }
             // обработка параметров с несколькими значениями
             if (isset($_POST['ModuleList4ValuesMultiply']) && is_array($_POST['ModuleList4ValuesMultiply']) && count($_POST['ModuleList4ValuesMultiply'])) {
                 foreach ($_POST['ModuleList4ValuesMultiply'] as $key => $value) {
                     ModuleList4Values::model()->new_value($id, (int) $key, '0');
                     foreach ($value as $key2 => $value2) {
                         if (ModuleList4Values::model()->existsItem($id, (int) $key, '0')) {
                             $params_value = ModuleList4Values::model()->getItem($id, (int) $key, '0');
                             $params_value->attributes = array('value' => $value2);
                             $params_value->save();
                         } else {
                             $params_value = new ModuleList4Values();
                             $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $id, 'value' => $value2);
                             $params_value->save();
                         }
                     }
                 }
             }
             // обработка параметров типа «List4»
             if ($page_id == 99) {
                 $list4ids = ModuleList4::model()->getListIds($mpage_id);
             }
             if (isset($_POST['ModuleList4List4']) && is_array($_POST['ModuleList4List4']) && count($_POST['ModuleList4List4'])) {
                 foreach ($_POST['ModuleList4List4'] as $k => $v) {
                     if (is_array($v) && count($v)) {
                         foreach ($v as $key => $value) {
                             $key = (int) $key;
                             $value = (int) $value;
                             $text = isset($_POST['ModuleList4List4Text'][$k][$key]) ? trim($_POST['ModuleList4List4Text'][$k][$key]) : '';
                             if ($key > 0) {
                                 if (empty($value)) {
                                     ModuleList4List4::model()->deleteAllByAttributes(array('id_1' => $id, 'id_2' => $key));
                                     ModuleList4List4::model()->deleteAllByAttributes(array('id_2' => $id, 'id_1' => $key));
                                 } else {
                                     if ($page_id == 99) {
                                         ModuleList4List4::model()->deleteAllByAttributes(array('id_1' => $list4ids, 'id_2' => $key));
                                         ModuleList4List4::model()->deleteAllByAttributes(array('id_2' => $list4ids, 'id_1' => $key));
                                         ModuleList4List4::model()->add($key, $id, $text);
                                     } else {
                                         ModuleList4List4::model()->add($id, $key, $text);
                                     }
                                 }
                             }
                         }
                     } else {
                         ModuleList4List4::model()->deleteAllByAttributes(array('id_1' => $id));
                         ModuleList4List4::model()->deleteAllByAttributes(array('id_2' => $id));
                         $key = (int) $k;
                         $value = (int) $v;
                         $text = isset($_POST['ModuleList4List4Text'][$k]) ? trim($_POST['ModuleList4List4Text'][$k]) : '';
                         if ($key > 0 && $value > 0) {
                             ModuleList4List4::model()->add($id, $value, $text);
                         }
                     }
                 }
             }
             // сохранение порядка в парамтерах типа «фотогалереях»
             if (isset($_POST['gallery_ids']) && is_array($_POST['gallery_ids']) && count($_POST['gallery_ids'])) {
                 foreach ($_POST['gallery_ids'] as $k => $v) {
                     $gallery_id = (int) $k;
                     $v = explode(',', $v);
                     if (count($v) > 1) {
                         $out = "UPDATE rktv_module_gallery_photos SET order_id= CASE";
                         for ($i = count($v); $i > 0; $i--) {
                             $out .= " WHEN id='" . intval($v[count($v) - $i]) . "' THEN '{$i}'";
                         }
                         $out .= " ELSE order_id END WHERE gallery_id = {$gallery_id}";
                         $connection = Yii::app()->db;
                         $command = $connection->createCommand($out);
                         $out = $command->execute();
                     }
                 }
             }
             // обработка основных полей
             $model = ModuleList4::model()->findByPk($id);
             if (isset($_POST['ModuleList4'])) {
                 $old_file_id = $model->img_id;
                 if ($_POST['ModuleList4']['img_id'] == 'NULL') {
                     $_POST['ModuleList4']['img_id'] = '';
                 }
                 $model->attributes = $_POST['ModuleList4'];
                 if ((int) $_POST['ModuleList4']['img_id']) {
                     Files::model()->saveTempFile((int) $_POST['ModuleList4']['img_id']);
                 } elseif ($_POST['ModuleList4']['img_id'] == '') {
                     Files::model()->deleteFile($old_file_id, $this->module->id);
                 }
                 if ($model->save()) {
                     if ($old_file_id != $model->img_id) {
                         Files::model()->deleteFile($old_file_id, $this->module->id);
                     }
                     Yii::app()->user->setFlash('message', '<p style="color:green;">Сохранено</p>');
                     $this->redirect(Yii::app()->baseUrl . '?r=' . $this->module->id . '/main/update&page_id=' . $page_id . '&id=' . $id);
                 } else {
                     Yii::app()->user->setFlash('message', '<p style="color:red;">Ошибка</p>');
                 }
             }
             $model = ModuleList4::model()->getItem($id, $mpage_id);
             $params_list = ModuleList4Params::model()->getList($mpage_id);
             $params_values_list = ModuleList4Values::model()->getList($id);
             $files = ModuleList4Files::model()->getList($id);
             $module_settings = ModuleList4Settings::model()->getItem($mpage_id);
             $this->pageTitle = $module_settings->title;
             $this->render('update', array('page_id' => $page_id, 'params_list' => $params_list, 'params_values_list' => $params_values_list, 'model' => $model, 'module_settings' => $module_settings, 'files' => $files));
         } else {
             $this->redirect(Yii::app()->baseUrl . '?r=pages/update&id=' . $page_id . '&/#!/tab_' . $this->module->id);
         }
     } else {
         $this->redirect(Yii::app()->request->scriptUrl);
     }
 }