Beispiel #1
0
 function get_popular_articles($cat_id, $cntNews, $hourAgo, $textLength = 200, $img = true, $parentCat = false)
 {
     $dateStart = date("Y-m-d H:i:s", strtotime(" - {$hourAgo} hours"));
     if ($img) {
         $imgSql = "\n AND `article`.`main_img` != '' ";
     } else {
         $imgSql = '';
     }
     $query = $this->db->query("SELECT `sub_cat_id` FROM `category` WHERE `id` = '{$cat_id}' ");
     $row = $query->row();
     if (!empty($row->sub_cat_id)) {
         $subCatWhere = " OR `article`.`cat_id` IN ({$row->sub_cat_id}) ";
     } else {
         $subCatWhere = '';
     }
     $sql = "SELECT  \r\n                    `article`.`id`,  `article`.`date`,  `article`.`url_name`,  `article`.`title`,  `article`.`text`,  `article`.`main_img`,  `category`.`full_uri` \r\n                FROM  \r\n                    `article` LEFT OUTER JOIN `category` ON `article`.`cat_id` = `category`.`id`\r\n                WHERE    \r\n                    `article`.`date` >  '{$dateStart}'\r\n                    AND\r\n                    ( `article`.`cat_id` = '{$cat_id}' {$subCatWhere} )\r\n                    {$imgSql}    \r\n                ORDER BY  \r\n                    `article`.`views` DESC, `article`.`id` DESC \r\n                LIMIT {$cntNews}";
     $query = $this->db->query($sql);
     if ($query->num_rows() < 1) {
         return NULL;
     }
     $result = array();
     foreach ($query->result_array() as $row) {
         $row['text'] = $this->get_short_txt($row['text'], $textLength);
         $row['date'] = get_date_str_ar($row['date']);
         $result[] = $row;
     }
     return $result;
 }
Beispiel #2
0
 private function get_like_articles_from_ids($idsStr)
 {
     $sql = "SELECT \r\n                    `article`.`id`, `article`.`title`, `article`.`url_name`, `article`.`main_img`, `article`.`date`, `article`.`description`, `article`.`views`, `category`.`full_uri` \r\n                FROM \r\n                    `article`, `category`\r\n                WHERE\r\n                    `article`.`id` IN {$idsStr}\r\n                     AND\r\n                     `category`.`id` = `article`.`cat_id`\r\n                LIMIT 9     \r\n                ";
     $query = $this->db->query($sql);
     if ($query->num_rows() < 1) {
         return NULL;
     }
     $result = array();
     foreach ($query->result_array() as $row) {
         //            $row['text']    = $this->get_short_txt( $row['text'], 600, 'dot' );
         $row['date_ar'] = get_date_str_ar($row['date']);
         $result[] = $row;
     }
     return $result;
 }