/** * 查看专题 */ public function actionShow($name) { $specialModel = Special::model()->find('title_alias=:titleAlias', array('titleAlias' => CHtml::encode(strip_tags($name)))); if (false == $specialModel) { throw new CHttpException(404, '专题不存在'); } //更新浏览次数 $specialModel->updateCounters(array('view_count' => 1), 'id=:id', array('id' => $specialModel->id)); $specialPostModel = new Post(); $criteria = new CDbCriteria(); $criteria->addCondition('t.status_is=:status AND special_id=:specialId'); $criteria->params = array('status' => 'Y', 'specialId' => $specialModel->id); $criteria->order = 't.id DESC'; $bagecmsSpecialCount = $specialPostModel->count($criteria); $postPage = new CPagination($bagecmsSpecialCount); $postPage->pageSize = 10; $postPageParams = XUtils::buildCondition($_GET, array()); $postPageParams['#'] = 'list'; $postPage->params = is_array($postPageParams) ? $postPageParams : array(); $criteria->limit = $postPage->pageSize; $criteria->offset = $postPage->currentPage * $postPage->pageSize; $specialPostList = $specialPostModel->findAll($criteria); $this->_seoTitle = empty($specialModel->seo_title) ? $specialModel->title . ' - ' . $this->_conf['site_name'] : $specialModel->seo_title; $tpl = empty($specialModel->tpl) ? 'show' : $specialModel->tpl; $data = array('specialShow' => $specialModel, 'specialPostList' => $specialPostList, 'bagecmsPagebar' => $postPage); $this->render($tpl, $data); }
public function init() { parent::init(); //内容模型id $this->_type = $this->_type_ids['post']; //文章栏目 $this->_catalog = Catalog::model()->findAll('status=:status AND type=:type', array(':status' => 'Y', ':type' => $this->_type)); //专题 $this->_special = Special::model()->findAll('status=:status', array('status' => 'Y')); }
public function init() { parent::init(); //内容模型id $this->_type = $this->_type_ids['image']; //图集栏目 $this->_catalog = Catalog::getTopCatalog(true, $this->_type); //专题 $this->_special = Special::model()->findAll('status=:status', array('status' => 'Y')); }
/** * 获取专题 */ public function actionGetSpecial() { $catalog_id = intval($this->_gets->getPost('catalog_id')); $special = Special::model()->findAll(array('select' => array('id', 'title'), 'condition' => 'catalog_id=:catalog_id', 'params' => array(':catalog_id' => $catalog_id))); $options = ''; if (!empty($special)) { foreach ($special as $val) { $options .= "<option value='{$val['id']}'>{$val['title']}</option>"; } } echo $options; }
/** * 判断数据是否存在 * * return \$this->model */ public function loadModel() { if ($this->model === null) { if (isset($_GET['id'])) { $this->model = Special::model()->findbyPk($_GET['id']); } if ($this->model === null) { throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.')); } } return $this->model; }
private function fetchPosts() { $with['select'] = array('id', 'category_id', 'topic_id', 'title', 'create_time', 'comment_nums', 'digg_nums', 'visit_nums', 'state', 'thumbnail'); $with['order'] = 'posts.create_time desc, posts.id desc'; $with['limit'] = $this->count; $condition = 'posts.state = ' . POST_STATE_DISABLED; if ($this->cid) { $condition .= ' and posts.category_id = ' . $this->cid; } if ($this->tid) { $condition .= ' and posts.topic_id = ' . $this->tid; } $with['condition'] = $condition; $model = Special::model()->with(array('posts' => $with))->findByAttributes(array('token' => $this->token)); return $model; }
public function run() { $this->controller->layout = false; $id = intval(Yii::app()->request->getParam('id')); $special = Special::model()->findByPk($id); if (!$special) { throw new Exception(Yii::t('common', 'The requested page does not exist.')); } $this->controller->_seoTitle = $special->seo_title ? $special->seo_title : $special->title . ' - ' . $this->controller->_setting['site_name']; $this->controller->_seoKeywords = $special->seo_keywords; $this->controller->_seoDescription = $special->seo_description; //专题资讯 $special_news = Post::model()->findAll(array('select' => 'id, title', 'condition' => 'special_id =' . $id . ' AND status ="' . Post::STATUS_SHOW . '"', 'limit' => 30)); //专题图集 $special_images = Image::model()->findAll(array('select' => 'id, title', 'condition' => 'special_id =' . $id . ' AND status ="' . Image::STATUS_SHOW . '"', 'limit' => 30)); $this->controller->render('index', array('special' => $special, 'special_news' => $special_news, 'special_images' => $special_images)); }
public function run() { $ids = Yii::app()->request->getParam('id'); $command = Yii::app()->request->getParam('command'); empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select')); if (!is_array($ids)) { $ids = array($ids); } $criteria = new CDbCriteria(); $criteria->addInCondition('id', $ids); switch ($command) { case 'delete': //删除 Special::model()->deleteAll($criteria); break; case 'sortOrder': $sortOrder = $_POST['sortOrder']; foreach ((array) $ids as $id) { $res = Special::model()->findByPk($id); if ($res) { $res->sort_order = $sortOrder[$id]; $res->save(); } } break; case 'show': //显示 Special::model()->updateAll(['status' => 'Y'], $criteria); break; case 'hidden': //隐藏 Special::model()->updateAll(['status' => 'N'], $criteria); break; default: $this->controller->message('error', Yii::t('admin', 'Error Operation')); } $this->controller->message('success', Yii::t('admin', 'Batch Operate Success')); }
/** * 批量操作 * */ public function actionBatch() { if ($this->method() == 'GET') { $command = trim($_GET['command']); $ids = intval($_GET['id']); } elseif ($this->method() == 'POST') { $command = trim($_POST['command']); $ids = $_POST['id']; } else { $this->message('errorBack', Yii::t('admin', 'Only POST Or GET')); } empty($ids) && $this->message('error', Yii::t('admin', 'No Select')); switch ($command) { case 'specialDelete': foreach ((array) $ids as $id) { $specialModel = Special::model()->findByPk($id); if ($specialModel) { Uploader::deleteFile($specialModel->attach_file); Uploader::deleteFile($specialModel->attach_thumb); $specialModel->delete(); } } break; default: throw new CHttpException(404, Yii::t('admin', 'Error Operation')); break; } $this->message('success', Yii::t('admin', 'Batch Operate Success')); }
/** * Returns the static model of the specified AR class. * @return AdminSpecial the static model class */ public static function model($className = __CLASS__) { return parent::model($className); }