public function _initialize()
 {
     $this->forbidword_type = ArticleController::getType();
     $this->forbidword_type['-1'] = 'nickname';
     //初始化
     $this->_status = array('recover' => array('before_state' => $this->_state['delete'], 'after_state' => $this->_state['normal']), 'active' => array('before_state' => $this->_state['inactive'], 'after_state' => $this->_state['normal']), 'inactive' => array('before_state' => $this->_state['normal'], 'after_state' => $this->_state['inactive']), 'delete' => array('before_state' => array($this->_state['normal'], $this->_state['inactive']), 'after_state' => $this->_state['delete']));
 }
 public function articleList()
 {
     $information = I('post.');
     $table = 'hotarticles';
     $draw = $information['draw'];
     if (empty($draw)) {
         returnJson(801);
     }
     $start = $information['start'];
     $length = $information['length'];
     if (!(is_numeric($start) && is_numeric($length))) {
         returnJson(801);
     }
     $caseSql = $this->tranSqlCase('articletype_id', Article::getType());
     $displayField = array('article_id' => 'id', 'title', 'articletype_id' => 'type_id', 'author', $caseSql => 'type', 'content', 'like_num', 'remark_num', 'created_time', 'updated_time', 'state');
     $columns = $information['columns'];
     $order = array();
     $orders = $information['order'];
     foreach ($orders as $value) {
         //排序需要的列
         $field = $columns[$value['column']]['data'];
         $order[$field] = $value['dir'];
     }
     $parameter = array();
     //框定条件
     if (!empty($information['args'])) {
         foreach ($information['args'] as $field => $value) {
             if (in_array($field, $displayField)) {
                 $parameter[$field] = $value;
             }
         }
     }
     $searchField = array();
     $searchvalue = $information['search']['value'];
     if (!empty($searchvalue)) {
         foreach ($columns as $column) {
             //判断是否需要搜索的
             if ($column['searchable'] == 'true') {
                 if (in_array($column['data'], $displayField)) {
                     $searchField[] = $column['data'];
                 }
             }
         }
         $parameter['*'] = array($searchvalue, $searchField);
     }
     $displayField = $this->displayField($displayField, $table);
     //用户帖需要的属性
     $articlesDisplayField = $this->displayField(array('username' => 'author', 'title', 'CONCAT(SUBSTR(content, 0, 3), "...")' => 'content', 'type_id', 'id', 'state'), 'articles');
     //获得子查询的sql语句
     //bbdd 用户写的文章
     $joinArticles = M('articles')->join('__USERS__ ON __ARTICLES__.user_id = __USERS__.id')->field($articlesDisplayField)->select(false);
     $caseSql = $this->tranSqlCase('articletype_id', array('1' => "重邮新闻", '2' => "教务在线", '3' => "学术讲座", '4' => "校务公告"));
     //新闻文章
     $newsDisplayField = $this->displayField(array($caseSql => 'author', 'title', 'CONCAT(SUBSTR(content, 0, 3), "...")' => 'content', 'articletype_id' => 'type_id', 'id', 'CONCAT("1")' => 'state'), 'news');
     $joinSql = M('news')->field($newsDisplayField)->union($joinArticles)->buildSql();
     //echo $joinSql;
     //公告
     $noticeDisplayField = $this->displayField(array('id', 'username' => 'author', 'title', 'CONCAT(6)' => 'type_id', 'CONCAT("公告")' => 'type', 'CONCAT(SUBSTR(content, 0, 3), "...")' => 'content', 'like_num', 'remark_num', 'created_time', 'updated_time', 'state'), 'notices');
     $joinNotice = M('notices')->field($noticeDisplayField)->join('__USERS__ ON __USERS__.id=__NOTICES__.user_id')->select(false);
     //获得所有文章的字查询表
     $allArticle = M($table)->join(" JOIN " . $joinSql . " article ON article.id=__HOTARTICLES__.article_id and article.type_id = __HOTARTICLES__.articletype_id")->field($displayField)->union($joinNotice)->buildSql();
     $parameter = $this->parameter($parameter);
     //总共的数据量
     $recordsTotal = M()->table($allArticle . ' article')->count();
     //筛选的数据
     $result = M()->table($allArticle . ' article')->where($parameter)->order($order)->select();
     //筛选得到的数据量
     $recordsFiltered = count($result);
     //分页选取数据
     if ($start >= $recordsFiltered) {
         $data = array();
     } else {
         $length = $recordsFiltered - $start > $length ? $length : $recordsFiltered - $start;
         $data = array_slice($result, $start, $length);
     }
     $info = compact('data', 'recordsFiltered', 'recordsTotal', 'draw');
     returnJson('datatable', '', $info);
 }