Exemplo n.º 1
0
 /**
  * Get article lists for overview.
  *
  * @param string $locale
  * @param integer $limit
  * @return ArticleModel[]|null
  */
 public function getArticleList($locale = '', $limit = null)
 {
     $sql = 'SELECT `a`.`id`, `a`.`cat_id`, `ac`.`author_id`, `ac`.`visits`, `ac`.`title`, `ac`.`perma`, `ac`.`article_img`,`ac`.`article_img_source`,`m`.`url_thumb`,`m`.`url`
             FROM `[prefix]_articles` as `a`
             LEFT JOIN `[prefix]_articles_content` as `ac` ON `a`.`id` = `ac`.`article_id`
             AND `ac`.`locale` = "' . $this->db()->escape($locale) . '"
             LEFT JOIN `[prefix]_media` `m` ON `ac`.`article_img` = `m`.`url`
             GROUP BY `a`.`id`
             ORDER BY `a`.`date_created` DESC';
     if ($limit !== null) {
         $sql .= ' LIMIT ' . (int) $limit;
     }
     $articleArray = $this->db()->queryArray($sql);
     if (empty($articleArray)) {
         return null;
     }
     $articles = array();
     foreach ($articleArray as $articleRow) {
         $articleModel = new ArticleModel();
         $articleModel->setId($articleRow['id']);
         $articleModel->setCatId($articleRow['cat_id']);
         $articleModel->setAuthorId($articleRow['author_id']);
         $articleModel->setVisits($articleRow['visits']);
         $articleModel->setTitle($articleRow['title']);
         $articleModel->setPerma($articleRow['perma']);
         $articleModel->setArticleImage($articleRow['article_img']);
         $articleModel->setArticleImageThumb($articleRow['url_thumb']);
         $articleModel->setArticleImageSource($articleRow['article_img_source']);
         $articles[] = $articleModel;
     }
     return $articles;
 }