public function create_item($page_id = null, $model) { $controller = Yii::app()->getController(); if (isset($_POST['ModuleList3'])) { $_POST['ModuleList3']['mpage_id'] = ModulesInPages::model()->getLink($page_id, $this->module_id); $model->attributes = $_POST['ModuleList3']; if ((int) $_POST['ModuleList3']['img_id']) { Files::model()->saveTempFile((int) $_POST['ModuleList3']['img_id']); } if ($model->save()) { $item_id = $model->primaryKey; // обработка input-параметров if (isset($_POST['ModuleList3Values']) && is_array($_POST['ModuleList3Values']) && count($_POST['ModuleList3Values'])) { foreach ($_POST['ModuleList3Values'] as $key => $value) { if (is_array($value) && count($value)) { foreach ($value as $key2 => $value2) { $params_value = new ModuleList3Values(); $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $item_id, 'value' => $value2); $params_value->save(); } } else { $params_value = new ModuleList3Values(); $params_value->attributes = array('param_id' => (int) $key, 'item_id' => $item_id, 'value' => $value); $params_value->save(); } } } 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>'); } } }
</tr> <?php } ?> <?php } ?> <?php $param = ModuleList3Params::model()->getItem(21); if ($param->data_type_id == 6) { ?> <?php $params_values = ModuleList3ParamsValues::model()->getList($param->id); foreach ($params_values as $key => $value) { $exist_params_values = ModuleList3Values::model()->exist_value($item->id, $param->id, $value->id); ?> <tr> <td><?php echo $value->title; ?> </td> <td> <?php if ($exist_params_values) { ?> <i class="icon icon-positive"></i> <?php } else { ?> <i class="icon icon-negative"></i>
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); } }
} ?> <?php if ($value['data_type_id'] == 6) { ?> <div style="border: 1px solid #CECECE; padding: 5px; margin-bottom: 5px;"> <label><strong><?php echo $value['title']; ?> </strong></label> <?php $params_values = ModuleList3ParamsValues::model()->getList($value['id']); $i = 0; foreach ($params_values as $key2 => $value2) { $i++; $exist_params_values = ModuleList3Values::model()->exist_value($model->id, $value['id'], $value2['id']); ?> <div class="edit_line checkboxLine"> <input id="ytModuleList3ValuesMultiply_<?php echo $value['code']; echo $value2['id']; ?> " type="hidden" value="0" name="ModuleList3ValuesMultiply[<?php echo $value['id']; ?> ][<?php echo $i; ?> ]"> <input name="ModuleList3ValuesMultiply[<?php echo $value['id'];
public function getItem($id = NULL, $mpage_id = NULL) { $criteria = new CDbCriteria(); $criteria->condition = 'mpage_id = :mpage_id AND id = :id AND active = 1'; $criteria->params = array('mpage_id' => $mpage_id, 'id' => $id); if ($value = $this->find($criteria)) { if ($value->img_id != NULL) { $value->img = $this->getImageById($value->img_id); } else { $value->img = $this->img_default; } $value->params = ModuleList3Values::model()->getListWithParams($value->id); } return $value; }