%PDF-1.4
Directory : /var/www/vhosts/lautnusantara.com/httpdocs/web/app/Models/ |
<?php namespace App\Models; use CodeIgniter\Model; class Artikel_Model extends Model { protected $table = 'ssn_news_items'; protected $primaryKey = 'id'; public function get_data_artikel($id = false, $catid = false, $keyword = false, $limit = false) { $builder = $this->select('ssn_news_items.* ,ssn_users.first_name,ssn_users.last_name, ,ssn_news_categories.name as categori_name ,ssn_news_categories.description as cat_desc'); $builder->join('ssn_users', 'ssn_news_items.created_by=ssn_users.id', 'left'); $builder->join('ssn_news_categories', 'ssn_news_items.catid=ssn_news_categories.id', 'left'); if ($id != false) { $builder->where('ssn_news_items.id', $id); } if ($catid != false) { $builder->where('ssn_news_items.catid', $catid); } $builder->where('ssn_news_items.publish_up <=', date('Y-m-d H:i:s')) ->where('ssn_news_items.published', '1') ->where('ssn_news_items.active', '1') ->where('ssn_news_items.trash', '0'); if ($keyword != null) { $builder->like('title', $keyword) // ->orLike('introtext', $keyword) // ->orLike('fulltexts', $keyword) // ->orLike('metadesc', $keyword) // ->orLike('metadata', $keyword) ->orLike('metakey', $keyword) ->orLike('ssn_news_categories.name', $keyword) ->groupBy('title') ->having('ssn_news_items.publish_up <=', date('Y-m-d H:i:s')) ->having('ssn_news_items.published', '1') ->having('ssn_news_items.active', '1') ->having('ssn_news_items.trash', '0'); if ($catid != null) { $builder->having('ssn_news_items.catid', $id); } } if ($limit != false) { $builder->limit($limit); } $builder->orderBy('ssn_news_items.publish_up', 'DESC'); return $builder; } public function get_data_artikel_populer($id = false, $catid = false, $keyword = false, $limit = false) { $builder = $this->select('ssn_news_items.* ,ssn_users.first_name,ssn_users.last_name, ,ssn_news_categories.name as categori_name ,ssn_news_categories.description as cat_desc'); $builder->join('ssn_users', 'ssn_news_items.created_by=ssn_users.id', 'left'); $builder->join('ssn_news_categories', 'ssn_news_items.catid=ssn_news_categories.id', 'left'); if ($id != false) { $builder->where('ssn_news_items.id', $id); } if ($catid != false) { $builder->where('ssn_news_items.catid', $catid); } $builder->where('ssn_news_items.publish_up <=', date('Y-m-d H:i:s')) ->where('ssn_news_items.published', '1') ->where('ssn_news_items.active', '1') ->where('ssn_news_items.trash', '0'); if ($keyword != null) { $builder->like('title', $keyword) // ->orLike('introtext', $keyword) // ->orLike('fulltexts', $keyword) // ->orLike('metadesc', $keyword) // ->orLike('metadata', $keyword) ->orLike('metakey', $keyword) ->orLike('ssn_news_categories.name', $keyword) ->groupBy('title') ->having('ssn_news_items.publish_up <=', date('Y-m-d H:i:s')) ->having('ssn_news_items.published', '1') ->having('ssn_news_items.active', '1') ->having('ssn_news_items.trash', '0'); if ($catid != null) { $builder->having('ssn_news_items.catid', $id); } } if ($limit != false) { $builder->limit($limit); } $builder->orderBy('ssn_news_items.hits', 'DESC'); return $builder; } public function get_name_kategori($catid = false) { $builder = $this->db->table('ssn_news_categories'); $builder->select('name'); $builder->where('id', $catid); return $builder->get(); } // tags public function get_tags_by_artikel($itemsid) { $builder = $this->db->table('ssn_news_tags_xref'); $builder->select('ssn_news_tags_xref.*,ssn_news_tags.name'); $builder->join('ssn_news_tags', 'ssn_news_tags.id=ssn_news_tags_xref.tag_id', 'left'); $builder->where('ssn_news_tags_xref.items_id', $itemsid); $builder->where('ssn_news_tags_xref.active', '1'); $builder->where('ssn_news_tags_xref.trash', '0'); return $builder->get(); } public function get_tags_id_by_name($name) { $builder = $this->db->table('ssn_news_tags'); $builder->select('ssn_news_tags.id'); $builder->where('ssn_news_tags.name', $name); return $builder->get(); } public function get_artikel_by_tags($itemsid) { $builder = $this->db->table('ssn_news_tags_xref'); $builder->select('ssn_news_tags_xref.*, ssn_news_items.*'); $builder->join('ssn_news_items', 'ssn_news_items.id = ssn_news_tags_xref.items_id', 'left'); $builder->where('ssn_news_tags_xref.tag_id', $itemsid); $builder->where('ssn_news_tags_xref.active', '1'); $builder->where('ssn_news_tags_xref.trash', '0'); return $builder->get(); } //////////////////////////////////////////////////////////////// public function save_news_hits($id, $jenis = 1, $hits2) { if ($jenis == 1) { $hits = $this->db->table('ssn_news_items')->update($hits2, array('id' => $id)); } else { $hits = $this->db->table('ssn_news_statis')->update($hits2, array('id' => $id)); } } public function save_hits($id, $jenis = 1, $data) { if ($jenis == 1) { $hits = $this->db->table('ssn_news_hits')->insert($data); } else { $hits = $this->db->table('ssn_statis_hits')->insert($data); } } } ?>