Exemple #1
0
 public function getListWithParams($item_id)
 {
     $data = array();
     $criteria = new CDbCriteria();
     $criteria->condition = 't.item_id = :item_id';
     $criteria->params = array('item_id' => $item_id);
     $criteria->order = 'param.order_id DESC, t.param_id ASC, t.id ASC';
     foreach ($this->with('param')->findAll($criteria) as $value) {
         $param = ModuleList4Params::model()->getItem($value->param_id);
         if (!isset($data[$param->code]) || !is_array($data[$param->code])) {
             $data[$param->code] = array();
             $data[$param->code]['id'] = $param->id;
             $data[$param->code]['title'] = $param->title;
             $data[$param->code]['data_type_id'] = $param->data_type_id;
         }
         // SELECT'ы
         if (in_array($param->data_type_id, array(5, 6))) {
             if (!isset($data[$param->code]['value']) || !is_array($data[$param->code]['value'])) {
                 $data[$param->code]['value'] = array();
             }
             $i = count($data[$param->code]['value']);
             $item_id = (int) $value->value;
             if (ModuleList4ParamsValues::model()->existsItem($param->id, $item_id)) {
                 $param_value = ModuleList4ParamsValues::model()->getItem($item_id);
                 $data[$param->code]['value'][$i] = array();
                 $data[$param->code]['value'][$i]['id'] = $param_value->id;
                 $data[$param->code]['value'][$i]['title'] = $param_value->title;
             }
         } elseif (in_array($param->data_type_id, array(7))) {
             $data[$param->code]['value'] = $value->value;
             $img_id = (int) $value->value;
             if ($img_id > 0 && Files::model()->existsFile($img_id)) {
                 $data[$param->code]['img'] = $this->getImageById($img_id);
             } else {
                 $data[$param->code]['img'] = $this->img_default;
             }
         } else {
             $data[$param->code]['value'] = $value->value;
         }
     }
     return $data;
 }
Exemple #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);
     }
 }
Exemple #3
0
 public function create_item($page_id = null, $model)
 {
     $controller = Yii::app()->getController();
     if (isset($_POST['ModuleList4'])) {
         $mpage_id = ModulesInPages::model()->getLink($page_id, $this->module_id);
         $_POST['ModuleList4']['mpage_id'] = $mpage_id;
         if (!isset($_POST['ModuleList4']['date'])) {
             $_POST['ModuleList4']['date'] = date('Y-m-d');
         }
         $model->attributes = $_POST['ModuleList4'];
         if ((int) $_POST['ModuleList4']['img_id']) {
             Files::model()->saveTempFile((int) $_POST['ModuleList4']['img_id']);
         }
         if ($model->save()) {
             $item_id = $model->primaryKey;
             // обработка input-параметров
             if (isset($_POST['ModuleList4Values']) && is_array($_POST['ModuleList4Values']) && count($_POST['ModuleList4Values'])) {
                 foreach ($_POST['ModuleList4Values'] as $key => $value) {
                     if (is_array($value) && count($value)) {
                         foreach ($value as $key2 => $value2) {
                             $params_value = new ModuleList4Values();
                             $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $item_id, 'value' => $value2);
                             $params_value->save();
                         }
                     } else {
                         $params_value = new ModuleList4Values();
                         $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $item_id, 'value' => $value);
                         $params_value->save();
                     }
                 }
             }
             // активация (создание) альбомов для параметров типа «Фотогалерея»
             $params_list = ModuleList4Params::model()->getList($mpage_id);
             if (count($params_list)) {
                 foreach ($params_list as $key => $value) {
                     if ($value['data_type_id'] == 8) {
                         $param_id = $value['id'];
                         $id = $item_id;
                         $param_value = ModuleList4Values::model()->getItem($id, $param_id);
                         if (count($param_value) == 0 || is_null(ModuleGallery::model()->findByPk((int) $param_value['value']))) {
                             $gallery = new ModuleGallery();
                             $gallery->attributes = array('title' => 'list4 # param_id = ' . $param_id . ', item_id = ' . $id, 'date' => date('Y-m-d'), 'active' => 1);
                             if ($gallery->save()) {
                                 if (count($param_value) == 0) {
                                     $model = new ModuleList4Values();
                                     $model->attributes = array('param_id' => $param_id, 'item_id' => $id, 'value' => $gallery->primaryKey);
                                     $model->save();
                                 } else {
                                     ModuleList4Values::model()->new_value($id, $param_id, $gallery->primaryKey);
                                 }
                             }
                         }
                     }
                 }
             }
             Yii::app()->user->setFlash($this->module_id . '_add_message', '<p style="color:green;">Добавлено</p>');
             $controller->redirect(Yii::app()->baseUrl . '?r=pages/update&id=' . $page_id . '&/#!/tab_' . $this->module_id);
         } else {
             Yii::app()->user->setFlash($this->module_id . '_add_message', '<p style="color:red;">Ошибка</p>');
         }
     }
     return $model;
 }
Exemple #4
0
 public function getList4($id, $mpage_id, $maxlevel = 1, $level = 1, $param_list = false)
 {
     if ($level > $maxlevel) {
         return NULL;
     }
     /*//$modulelist4 = new ModuleList4();
       //$val = $modulelist4->findByAttributes(array('id' => $id, 'mpage_id' => $mpage_id));
       //if (is_null($val)) return NULL;
       $val = (object) array('id'=>$id);
       //$list4 = $val->getAttributes();
       $list4 = array('id'=>$id);*/
     $modulelist4 = new ModuleList4();
     $val = $modulelist4->findByAttributes(array('id' => $id, 'mpage_id' => $mpage_id));
     if (is_null($val)) {
         return NULL;
     }
     $list4 = $val->getAttributes();
     if ($param_list !== false) {
         $params = ModuleList4Params::model()->findAllByAttributes(array('mpage_id' => $mpage_id, 'code' => $param_list));
     } else {
         $params = ModuleList4Params::model()->findAllByAttributes(array('mpage_id' => $mpage_id));
     }
     foreach ($params as $param) {
         $list4['params'][$param->id] = $param->getAttributes();
         $list4['params'][$param->id]['settings'] = unserialize($list4['params'][$param->id]['settings']);
         switch ($param->data_type_id) {
             case '1':
             case '2':
             case '3':
             case '4':
                 $values = ModuleList4Values::model()->findAllByAttributes(array('param_id' => $param->id, 'item_id' => $val->id));
                 $j = 0;
                 foreach ($values as $value) {
                     $list4['params'][$param->id]['values'][$j] = $value->getAttributes();
                     $list4['params'][$param->id]['values'][$j]['value'] = $value->value;
                     $j++;
                 }
                 break;
                 /* case '3':
                        $values = ModuleList4Values::model()->findAllByAttributes(
                            array(
                                'param_id' => $param->id,
                                'item_id' => $val->id,
                            )
                        );
                        $j = 0;
                        foreach ($values as $value) {
                            $list4['params'][$param->id]['values'][$j] = $value->getAttributes();
                            $list4['params'][$param->id]['values'][$j]['value'] = $value->value;
                            $j++;
                        }
                        break;
                    case '4':
                        $values = ModuleList4Values::model()->findAllByAttributes(
                            array(
                                'param_id' => $param->id,
                                'item_id' => $val->id,
                            )
                        );
                        $j = 0;
                        foreach ($values as $value) {
                            $list4['params'][$param->id]['values'][$j] = $value->getAttributes();
                            $list4['params'][$param->id]['values'][$j]['value'] = $value->value;
                            $j++;
                        }
                        break; */
             /* case '3':
                    $values = ModuleList4Values::model()->findAllByAttributes(
                        array(
                            'param_id' => $param->id,
                            'item_id' => $val->id,
                        )
                    );
                    $j = 0;
                    foreach ($values as $value) {
                        $list4['params'][$param->id]['values'][$j] = $value->getAttributes();
                        $list4['params'][$param->id]['values'][$j]['value'] = $value->value;
                        $j++;
                    }
                    break;
                case '4':
                    $values = ModuleList4Values::model()->findAllByAttributes(
                        array(
                            'param_id' => $param->id,
                            'item_id' => $val->id,
                        )
                    );
                    $j = 0;
                    foreach ($values as $value) {
                        $list4['params'][$param->id]['values'][$j] = $value->getAttributes();
                        $list4['params'][$param->id]['values'][$j]['value'] = $value->value;
                        $j++;
                    }
                    break; */
             case '5':
                 $values = ModuleList4Values::model()->findAllByAttributes(array('param_id' => $param->id, 'item_id' => $val->id));
                 $j = 0;
                 foreach ($values as $value) {
                     $list4['params'][$param->id]['values'][$j] = $value->getAttributes();
                     $list4['params'][$param->id]['values'][$j]['value'] = ModuleList4ParamsValues::model()->findByPk($value->value)->title;
                     $tmp_value = ModuleList4ParamsValues::model()->findByPk($value->value);
                     if ($tmp_value) {
                         $tmp_value_id = $tmp_value->id;
                         $list4['params'][$param->id]['values'][$j]['value_id'] = $tmp_value_id;
                     }
                     //						$list4['params'][$param->id]['values'][$j]['value_id'] = ModuleList4ParamsValues::model()->
                     //							findByPk($value->value)->id;
                     $j++;
                 }
                 break;
                 // $values = ModuleList4Values::model()->with('list4paramsvalues')->findAllByAttributes(
                 // array(
                 // 't.param_id' => $param->id,
                 // 't.item_id' => $val->id,
                 // )
                 // );
                 // $j = 0;
                 // foreach ($values as $value) {
                 // $list4['params'][$param->id]['values'][$j] = $value->getAttributes();
                 // $list4['params'][$param->id]['values'][$j]['value'] = $value->list4paramsvalues->title;
                 // $j++;
                 // }
                 break;
             case '8':
                 $value = ModuleList4Values::model()->findByAttributes(array('param_id' => $param->id, 'item_id' => $val->id));
                 $photos = array();
                 // $gId = $list4['params'][$param->id]['value'] = '1234123412';//$value->value;
                 $gId = $value->value;
                 foreach (ModuleGalleryPhotos::model()->with('file')->findAllByAttributes(array('gallery_id' => $gId)) as $item) {
                     $photos[] = $item->file->file_name;
                 }
                 $list4['params'][$param->id]['value'] = $photos;
                 break;
             case '9':
                 $linked_mpages = array();
                 foreach (ModuleList4ParamsList4::model()->findAllByAttributes(array('param_id' => $param->id)) as $link) {
                     $linked_mpages[] = $link->mpage_id;
                 }
                 $j = 0;
                 foreach ($linked_mpages as $linked_mpage) {
                     $allowed = array();
                     foreach ($modulelist4->findAllByAttributes(array('mpage_id' => $linked_mpage)) as $v) {
                         $allowed[] = $v->id;
                     }
                     $linkparams = ModuleList4List4::model()->findAllByAttributes(array('id_1' => $val->id, 'id_2' => $allowed));
                     foreach ($linkparams as $linkparam) {
                         $list4['params'][$param->id]['values'][$j] = $linkparam->getAttributes();
                         $list4['params'][$param->id]['values'][$j]['value'] = $this->getList4($linkparam->id_2, $linked_mpage, $maxlevel, $level + 1, $param_list);
                         $j++;
                     }
                 }
                 break;
             default:
                 break;
         }
     }
     return $list4;
 }
Exemple #5
0
 public function actionDelete_value($page_id = null, $param_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 (ModuleList4Params::model()->existsItem($mpage_id, $param_id) && ModuleList4ParamsValues::model()->deleteItem($param_id, $id)) {
             Yii::app()->user->setFlash($this->module->id . '_delete_message', '<p style="color:green;">Удалено</p>');
         } else {
             Yii::app()->user->setFlash($this->module->id . '_delete_message', '<p style="color:red;">Ошибка удаления</p>');
         }
         $this->redirect(Yii::app()->baseUrl . '?r=' . $this->module->id . '/params/update&page_id=' . $page_id . '&id=' . $param_id);
     } else {
         $this->redirect(Yii::app()->request->scriptUrl);
     }
 }