Пример #1
0
 /**
  * List newest published articles
  * 
  * @param array   $options
  * @param string  $module
  * @return boolean 
  */
 public static function newestPublishedArticles($options = array(), $module = null)
 {
     if (empty($module)) {
         return false;
     }
     $params = Pi::service('url')->getRouteMatch()->getParams();
     $config = Pi::config('', $module);
     $image = $config['default_feature_thumb'];
     $image = Pi::service('asset')->getModuleAsset($image, $module);
     $postCategory = isset($params['category']) ? $params['category'] : 0;
     $postTopic = isset($params['topic']) ? $params['topic'] : 0;
     $category = $options['category'] ? $options['category'] : $postCategory;
     $topic = $options['topic'] ? $options['topic'] : $postTopic;
     if (!is_numeric($topic)) {
         $topic = Pi::model('topic', $module)->slugToId($topic);
     }
     $limit = $options['list-count'] <= 0 ? 10 : $options['list-count'];
     $page = 1;
     $order = 'time_update DESC, time_publish DESC';
     $columns = array('subject', 'summary', 'time_publish', 'image');
     $where = array();
     if (!empty($category)) {
         $category = Pi::model('category', $module)->getDescendantIds($category);
         $where['category'] = $category;
     }
     if (!empty($options['is-topic'])) {
         if (!empty($topic)) {
             $where['topic'] = $topic;
         }
         $articles = Topic::getTopicArticles($where, $page, $limit, $columns, $order, $module);
     } else {
         $articles = Entity::getAvailableArticlePage($where, $page, $limit, $columns, $order, $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'], 'config' => $config, 'column' => $options['column-number'], 'rows' => $options['description_rows']);
 }