/** * Topic list page for viewing */ public function allTopicAction() { $page = $this->params('p', 1); $page = $page > 0 ? $page : 1; $module = $this->getModule(); $config = Pi::config('', $module); $limit = (int) $config['page_limit_all']; $where = array('active' => 1); // Get topics $resultsetTopic = TopicService::getTopics($where, $page, $limit); foreach ($resultsetTopic as &$topic) { $topic['image'] = $topic['image'] ? Media::getThumbFromOriginal($topic['image']) : Pi::service('asset')->getModuleAsset($config['default_topic_image']); } $topicIds = array_keys($resultsetTopic) ?: array(0); // Get topic article counts $model = $this->getModel('article_topic'); $select = $model->select()->where(array('topic' => $topicIds))->columns(array('count' => new Expression('count(id)'), 'topic'))->group(array('topic')); $rowRelation = $model->selectWith($select); $articleCount = array(); foreach ($rowRelation as $row) { $articleCount[$row->topic] = $row->count; } // Get last added article $lastAdded = array(); $select = $model->select()->where(array('topic' => $topicIds))->columns(array('id' => new Expression('max(id)')))->group(array('topic')); $rowset = $model->selectWith($select); $ids = array(0); foreach ($rowset as $row) { $ids[] = $row['id']; } $rowAdded = $model->select(array('id' => $ids)); foreach ($rowAdded as $row) { $lastAdded[$row['topic']] = $row['time']; } // Total count $modelTopic = $this->getModel('topic'); $totalCount = $modelTopic->getSearchRowsCount($where); // Pagination $route = Pi::api('api', $module)->getRouteName(); $paginator = Paginator::factory($totalCount, array('limit' => $limit, 'page' => $page, 'url_options' => array('page_param' => 'p', 'params' => array('topic' => 'all')))); $this->view()->assign(array('title' => __('All Topics'), 'topics' => $resultsetTopic, 'paginator' => $paginator, 'count' => $articleCount, 'config' => $config, 'route' => $route, 'lastAdded' => $lastAdded)); }
/** * List newest topics. * * @param array $options * @param string $module * @return boolean */ public static function newestTopic($options = array(), $module = null) { if (!$module) { return false; } $limit = $options['list-count'] <= 0 ? 10 : $options['list-count']; $order = 'id DESC'; $topics = Topic::getTopics(array(), 1, $limit, null, $order, $module); $config = Pi::config('', $module); $image = Pi::service('asset')->getModuleAsset($config['default_topic_thumb'], $module); foreach ($topics as &$topic) { $topic['title'] = mb_substr($topic['title'], 0, $options['max_title_length'], 'UTF-8'); $topic['description'] = mb_substr($topic['description'], 0, $options['max_description_length'], 'UTF-8'); $topic['image'] = $topic['image'] ? Media::getThumbFromOriginal(Pi::url($topic['image'])) : $image; } return array('items' => $topics, 'target' => $options['target'], 'config' => $config); }