Ejemplo n.º 1
0
 /**
  * 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));
 }
Ejemplo n.º 2
0
 /**
  * List hot articles by visit count
  * 
  * @param array   $options
  * @param string  $module
  * @return boolean 
  */
 public static function hotArticles($options = array(), $module = null)
 {
     if (!$module) {
         return false;
     }
     $limit = isset($options['list-count']) ? (int) $options['list-count'] : 10;
     $config = Pi::config('', $module);
     $image = $config['default_feature_thumb'];
     $image = Pi::service('asset')->getModuleAsset($image, $module);
     $day = $options['day-range'] ? intval($options['day-range']) : 7;
     if ($options['is-topic']) {
         $params = Pi::service('url')->getRouteMatch()->getParams();
         if (is_string($params)) {
             $params['topic'] = Pi::model('topic', $module)->slugToId($params['topic']);
         }
         $articles = Topic::getVisitsRecently($day, $limit, null, isset($params['topic']) ? $params['topic'] : null, $module);
     } else {
         $articles = Entity::getVisitsRecently($day, $limit, null, $module);
     }
     foreach ($articles as &$article) {
         $article['subject'] = mb_substr($article['subject'], 0, $options['max_subject_length'], 'UTF-8');
         $article['summary'] = mb_substr($article['summary'], 0, $options['max_summary_length'], 'UTF-8');
         $article['image'] = $article['image'] ? Media::getThumbFromOriginal(Pi::url($article['image'])) : $image;
     }
     return array('articles' => $articles, 'target' => $options['target'], 'elements' => (array) $options['element'], 'column' => $options['column-number'], 'config' => $config, 'rows' => $options['description_rows']);
 }