public function run($page_id = null, $page = 1) { $page_id = $this->page_id; $page = $this->page; $controller = Yii::app()->getController(); $model = new ModuleNews(); if (!is_null($page_id) && Pages::model()->existsPage($page_id)) { $this->create_item($page_id, $model); $mpage_id = ModulesInPages::model()->getLink($page_id, $this->module_id); $records_on_page = 10; $count = ModuleNews::model()->getCount($mpage_id); $pagination = $this->pagination('/admin.php?r=pages/update&id=' . $page_id . '&page=', $count, $page, $records_on_page); $offset = ($page - 1) * $records_on_page; $limit = $records_on_page; $data = ModuleNews::model()->getList($mpage_id, $offset, $limit); $this->render('module_news', array('model' => $model, 'page_id' => $page_id, 'data' => $data, 'pagination' => $pagination)); } else { $controller->redirect(Yii::app()->request->scriptUrl); } }
protected function moduleNewsList2($data) { $pages = $data['pages']; $mpage_id_list2 = ModulesInPages::model()->getLink($data['doc_id_last'], 'list2'); $mpage_id_news = ModulesInPages::model()->getLink($data['doc_id_last'], 'news'); $records_on_page = 10; // количество новостей на странице $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 ModuleNews(); $news_id = floor(substr($type, 5)); if ($lenta->existsItem($mpage_id_news, $news_id, 1)) { $data['news_show'] = 1; $data['item_id'] = $news_id; $data['item'] = $lenta->getItem($news_id, $mpage_id_news); $data['lastNews'] = $lenta->getLastNewsList($mpage_id_news, $news_id, 2); $list2 = new ModuleList2(); $data['list2'] = ModuleList2::model()->getList($mpage_id_list2, 0, 0, 1); $data['doc_id_list2'] = $data['doc_id_last']; if (count($data['item']) == 0) { $this->redirect($pages->make_url($data['doc_id_last'])); } else { $data['title'] = $data['item']['title'] . ' — ' . $data['title']; $this->render('news_list2_show', $data); } } else { // новость не найдена $this->redirect($pages->make_url($data['doc_id_last'])); } } elseif (substr($type, 0, 7) == 'action_') { // конкретная акция $list2 = new ModuleList2(); $lenta = new ModuleNews(); $action_id = floor(substr($type, 7)); if ($list2->existsItem($mpage_id_list2, $action_id, 1)) { $data['news_show'] = 0; $data['item_id'] = $action_id; $data['item'] = $list2->getItem($action_id, $mpage_id_list2); $data['doc_id_list2'] = $data['doc_id_last']; $data['list2'] = $list2->getOtherList($mpage_id_list2, $action_id, 0, 1); $data['lastNews'] = $lenta->getLastNewsList($mpage_id_news, 0, 2); if (count($data['item']) == 0) { $this->redirect($pages->make_url($data['doc_id_last'])); } else { $data['title'] = $data['list2']['title'] . ' — ' . $data['title']; $this->render('news_list2_show', $data); } } else { // акция не найдена $this->redirect($pages->make_url($data['doc_id_last'])); } } elseif (substr($type, 0, 5) == 'page_' || empty($type)) { // выбор страницы $page = 1; $lenta = new ModuleNews(); if (!empty($type)) { $page = floor(substr($type, 5)); } if ($page < 1) { $page = 1; } $data['pagination'] = $this->pagination($pages->make_url($data['doc_id_last']) . 'page_', $lenta->getCount($mpage_id_news, 1), $page, $records_on_page); $offset = ($page - 1) * $records_on_page; $limit = $records_on_page; $data['newsList'] = ModuleNews::model()->getList($mpage_id_news, $offset, $limit, 1); $data['url_for_menu'] = substr(substr($data['pages']->make_url($data['doc_id_last']), 0, -1), 1); $data['list2'] = ModuleList2::model()->getList($mpage_id_list2, 0, 0, 1); $data['doc_id_list2'] = $data['doc_id_last']; $this->render('news_list2', $data); } else { // неизвестный тип отображения $this->redirect($pages->make_url($data['doc_id_last'])); } }
public function actionDeactivation($page_id = null) { $result = false; // доступно для пользователей первой роли (например, «Реактиву») $role_id = Users::model()->findByPk(Yii::app()->user->id)->role_id; if ($role_id < 2 && !is_null($page_id) && Pages::model()->existsPage($page_id)) { $link_id = ModulesInPages::model()->getLink($page_id, $this->module->id); if ($link_id) { $result = ModuleNews::model()->deactivation($link_id, $this->module->id); } } if ($result) { $this->redirect(Yii::app()->baseUrl . '?r=pages/update&id=' . $page_id . '&/#!/tab_fourth'); } else { $this->redirect(Yii::app()->request->baseUrl . '/admin.php'); } }