Exemplo n.º 1
0
 public function actionDelete($page_id = null, $item_id = null, $id = null)
 {
     $model = ModuleList3Files::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');
 }
Exemplo n.º 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) && ModuleList3::model()->existsItem($mpage_id, $id)) {
             // обработка параметров с одним значением
             if (isset($_POST['ModuleList3Values']) && is_array($_POST['ModuleList3Values']) && count($_POST['ModuleList3Values'])) {
                 foreach ($_POST['ModuleList3Values'] as $key => $value) {
                     ModuleList3Values::model()->new_value($id, (int) $key, '0');
                     if (ModuleList3Values::model()->existsItem($id, (int) $key)) {
                         $params_value = ModuleList3Values::model()->getItem($id, (int) $key);
                         $params_value->attributes = array('value' => $value);
                         $params_value->save();
                         $criteria = new CDbCriteria();
                         $criteria->condition = 'param_id = :param_id AND item_id = :item_id AND id <> :id';
                         $criteria->params = array('param_id' => (int) $key, 'item_id' => $id, 'id' => $params_value->id);
                         ModuleList3Values::model()->deleteAll($criteria);
                     } else {
                         $params_value = new ModuleList3Values();
                         $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $id, 'value' => $value);
                         $params_value->save();
                     }
                 }
             }
             // обработка параметров с несколькими значениями
             if (isset($_POST['ModuleList3Files'])) {
                 $list3file = new ModuleList3Files();
                 $list3file->short = $_POST['ModuleList3Files']['short'];
                 $list3file->file_id = $_POST['ModuleList3Files']['file_id'];
                 $list3file->item_id = $id;
                 if ($list3file->save()) {
                     Files::model()->saveTempFile((int) $list3file->file_id);
                 } else {
                     Files::model()->deleteFile($list3file->file_id, $this->module->id);
                     Yii::app()->user->setFlash('message', '<p style="color:red;">Ошибка</p>');
                 }
             }
             if (isset($_POST['ModuleList3ValuesMultiply']) && is_array($_POST['ModuleList3ValuesMultiply']) && count($_POST['ModuleList3ValuesMultiply'])) {
                 foreach ($_POST['ModuleList3ValuesMultiply'] as $key => $value) {
                     ModuleList3Values::model()->new_value($id, (int) $key, '0');
                     foreach ($value as $key2 => $value2) {
                         if (ModuleList3Values::model()->existsItem($id, (int) $key, '0')) {
                             $params_value = ModuleList3Values::model()->getItem($id, (int) $key, '0');
                             $params_value->attributes = array('value' => $value2);
                             $params_value->save();
                         } else {
                             $params_value = new ModuleList3Values();
                             $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $id, 'value' => $value2);
                             $params_value->save();
                         }
                     }
                 }
             }
             $model = ModuleList3::model()->findByPk($id);
             if (isset($_POST['ModuleList3'])) {
                 $old_file_id = $model->img_id;
                 if ($_POST['ModuleList3']['img_id'] == 'NULL') {
                     $_POST['ModuleList3']['img_id'] = '';
                 }
                 $model->attributes = $_POST['ModuleList3'];
                 if ((int) $_POST['ModuleList3']['img_id']) {
                     Files::model()->saveTempFile((int) $_POST['ModuleList3']['img_id']);
                 } elseif ($_POST['ModuleList3']['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 = ModuleList3::model()->getItem($id, $mpage_id);
             if ($mpage_id == 5) {
                 $mpage_id = 4;
             }
             if ($mpage_id == 54) {
                 $mpage_id = 4;
             }
             if ($mpage_id == 56) {
                 $mpage_id = 4;
             }
             if ($mpage_id == 58) {
                 $mpage_id = 4;
             }
             $params_list = ModuleList3Params::model()->getList($mpage_id);
             $params_values_list = ModuleList3Values::model()->getList($id);
             $files = ModuleList3Files::model()->getList($id);
             $this->render('update', array('page_id' => $page_id, 'params_list' => $params_list, 'params_values_list' => $params_values_list, 'model' => $model, '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);
     }
 }
Exemplo n.º 3
0
 protected function moduleList3($data)
 {
     $pages = $data['pages'];
     $mpage_id = ModulesInPages::model()->getLink($data['doc_id_last'], 'list3');
     $records_on_page = 0;
     // количество публикаций на странице
     $type = explode($pages->make_url($data['doc_id_last']), '/' . Yii::app()->request->pathInfo);
     $type = explode('/', $type[1]);
     $type = $type[0];
     if (substr($type, 0, 5) == 'show_') {
         // конкретная публикация
         $lenta = new ModuleList3();
         $item_id = floor(substr($type, 5));
         if ($lenta->existsItem($mpage_id, $item_id, 1)) {
             $data['item_id'] = $item_id;
             $data['item'] = $lenta->getItem($item_id, $mpage_id);
             $data['longtitle'] = $data['item']['title'];
             switch ($data['doc_id_last']) {
                 case 37:
                     $data['longtitle'] = 'Вклад ' . $data['item']['title'];
                     break;
                     /*case :
                       $data['longtitle'] = ''.$data['item']['title'];
                       break;*/
             }
             //$data['other_lenta'] = $lenta->getOtherList($mpage_id, $item_id,4,1);
             if (count($data['item']) == 0) {
                 $this->redirect($pages->make_url($data['doc_id_last']));
             } else {
                 $data['title'] = $data['item']['title'] . ' — ' . $data['title'];
                 if ($data['doc_id_last'] == 37) {
                     $data['list3'] = ModuleList3::model()->getList($mpage_id);
                     $ids = [];
                     foreach ($data['list3'] as $value) {
                         $ids[] = $value->id;
                     }
                     $count = count($ids);
                     $i = 0;
                     while ($ids[$i] != $item_id) {
                         $i++;
                     }
                     if ($i == 0) {
                         $data['prev'] = false;
                         $data['next'] = $count > 1 ? $lenta->getItem($ids[1], $mpage_id) : false;
                     } else {
                         if ($i == $count - 1) {
                             $data['prev'] = $count > 1 ? $lenta->getItem($ids[$i - 1], $mpage_id) : false;
                             $data['next'] = false;
                         } else {
                             $data['prev'] = $lenta->getItem($ids[$i - 1], $mpage_id);
                             $data['next'] = $lenta->getItem($ids[$i + 1], $mpage_id);
                         }
                     }
                     $list3files = ModuleList3Files::model()->findAllByAttributes(['item_id' => $item_id]);
                     if (count($list3files) > 0) {
                         foreach ($list3files as $file) {
                             $data['files'][$file->id]['short'] = $file->short;
                             $data['files'][$file->id]['ref'] = Files::model()->getVirtualPath('list3', $file->file_id);
                         }
                     }
                     $this->render('deposit_show', $data);
                 } else {
                     $this->render('list3_show', $data);
                 }
             }
         } else {
             // публикация не найдена
             $this->redirect($pages->make_url($data['doc_id_last']));
         }
     } elseif (substr($type, 0, 5) == 'page_' || empty($type)) {
         // выбор страницы
         $page = 1;
         $lenta = new ModuleList3();
         if (!empty($type)) {
             $page = floor(substr($type, 5));
         }
         if ($page < 1) {
             $page = 1;
         }
         if ($records_on_page > 0) {
             $data['pagination'] = $this->pagination($pages->make_url($data['doc_id_last']) . 'page_', $lenta->getCount($mpage_id, 1), $page, $records_on_page);
         }
         $offset = ($page - 1) * $records_on_page;
         $limit = $records_on_page;
         $data['list3'] = ModuleList3::model()->getList($mpage_id, $offset, $limit, 1);
         $data['url_for_menu'] = substr(substr($data['pages']->make_url($data['doc_id_last']), 0, -1), 1);
         if ($data['doc_id_last'] == 37) {
             $this->render('deposit', $data);
         } else {
             $this->render('list3', $data);
         }
     } else {
         // неизвестный тип отображения ПУБЛИКАЦИЙ
         $this->redirect($pages->make_url($data['doc_id_last']));
     }
 }