/** * 首页 * */ public function actionIndex() { parent::_acl(); //过期 $show = reqGet('show', null); $catalogId = intval(reqGet('catalogId', 0)); $catalogList = $catalogListSub = null; //顶级分类 if ($catalogId > 0) { $catalogList = XXcache::_doCatalog($catalogId, $this->_catalog); foreach ($this->_catalog as $value) { if ($value['id'] == $catalogId) { $value['catalog_name'] = '==' . $value['catalog_name'] . '=='; if (empty($catalogList)) { $catalogList = array($value); } else { $catalogList = array_merge(array($value), $catalogList); } } } if (!empty($catalogList)) { //非last foreach ($catalogList as $value) { $catalogListSub[] = $value['id']; } // $catalogListSub = implode(',', $catalogListSub); } } else { //全部有效分类 if (!empty($this->_catalog)) { //非last foreach ($this->_catalog as $value) { $catalogListSub[] = $value['id']; } } } $catalogList = $this->_catalog; $model = new Links(); $criteria = new CDbCriteria(); $condition = '1'; $keyword = trim(reqGet('keyword')); $search_type = trim(reqGet('search_type')); $keyword && $search_type && ($condition .= ' AND ' . $search_type . ' LIKE \'%' . $keyword . '%\''); if ($show) { $theTime = time(); //有效但过期 if ($show == 'past') { $condition .= " AND t.status_is = 'Y' AND begin_time>0 AND end_time>0 AND (`begin_time` > '{$theTime}' OR `end_time` < '{$theTime}')"; } //无效 if ($show == 'status_n') { $condition .= " AND t.status_is = 'N' "; } } if (!empty($catalogListSub)) { $temp = null; foreach ($catalogListSub as $value) { $temp[] = "`catalog_id` = '{$value}'"; } $condition .= ' AND (' . implode(' OR ', $temp) . ')'; // $condition .= ' AND `catalog_id` IN ('.$catalogListSub.')'; } else { $catalogId && ($condition .= ' AND `catalog_id`= ' . $catalogId); } $criteria->condition = $condition; $criteria->order = 't.catalog_id ASC,t.status_is ASC,t.sort_order ASC'; $criteria->with = array('catalog', 'user'); $count = $model->count($criteria); $pages = new CPagination($count); $pages->pageSize = 15; $pageParams = XUtils::buildCondition($_GET, array('title', 'catalogId', 'search_type', 'keyword', 'show', 'r')); $pages->params = is_array($pageParams) ? $pageParams : array(); $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $result = $model->findAll($criteria); // ppr($result); $this->render('index', array('datalist' => $result, 'pagebar' => $pages, 'pagecount' => $count, 'catalogList' => $catalogList, 'catalogId' => $catalogId, 'keyword' => $keyword, 'search_type' => $search_type)); }
public function getStatistics() { return ['comments' => Comments::count('user_id = "' . $this->id . '"'), 'tags' => Taggables::count('user_id = "' . $this->id . '"'), 'links' => Links::count('user_id = "' . $this->id . '"'), 'favorites' => Favorites::count('user_id = "' . $this->id . '"')]; }