<?php

if(!defined('BASEPATH')) exit('Hacking Attempt : Get Out of the system ..!');

class Home_model extends CI_Model
{
	public function __construct(){
		parent::__construct();
	}
	
	public function getsinglepagedetails($slug){
		$this->db->select('*');
		$where = array('pages.slug='=>$slug,"pages.status"=>1);
		$this->db->where($where);
		$query = $this->db->get('pages');
		return $query->result_array();
	}
	


	public function get_blog_count($param=null) {
        $this->db->select('articles.*,article_category.`title` as cat,article_category.`slug` AS catslug');
		$this->db->join('article_to_category',"article_to_category.`articleId`=articles.`articleId`","left");
		$this->db->join('article_category',"article_category.`articlecatId`=article_to_category.`articlecatId`","left");
		if($param){
			$where = array('articles.`status`'=>1,'article_category.`status`'=>1,'article_category.`slug`'=>$param);
		}else{
			$where = array('articles.`status`'=>1,'article_category.`status`'=>1);
		}
		$this->db->where($where);
		$this->db->group_by('article_category.`articlecatId`');
		$this->db->from('articles');
		return $this->db->count_all_results();
    }
	public function getblogs($limit, $start,$param=null){
		$this->db->select('articles.*,article_category.`title` as cat,article_category.`slug` AS catslug');
		$this->db->join('article_to_category',"article_to_category.`articleId`=articles.`articleId`","left");
		$this->db->join('article_category',"article_category.`articlecatId`=article_to_category.`articlecatId`","left");
		if($param){
			$where = array('articles.`status`'=>1,'article_category.`status`'=>1,'article_category.`slug`'=>$param);
		}else{
			$where = array('articles.`status`'=>1,'article_category.`status`'=>1);
		}
		$this->db->where($where);
		 $this->db->limit($limit, $start);
		$this->db->order_by('articles.createdon','ASC');
		$this->db->group_by('article_category.`articlecatId`');
		$query = $this->db->get('articles');
		return $query->result_array();
	}
	
	public function getrelatedblogs($limit){
		$this->db->select('articles.title,articles.slug,articles.image,articles.updatedon,article_category.`title` as cat,article_category.`slug` AS catslug');
		$this->db->join('article_to_category',"article_to_category.`articleId`=articles.`articleId`","left");
		$this->db->join('article_category',"article_category.`articlecatId`=article_to_category.`articlecatId`","left");
		$where = array('articles.`status`'=>1,'article_category.`status`'=>1);
		$this->db->where($where);
		$this->db->limit($limit);
		$this->db->order_by('rand()');
		$this->db->group_by('article_category.`articlecatId`');
		$query = $this->db->get('articles');
		return $query->result_array();
	}
	
	public function getblogsearch($term){
		$this->db->select('articles.*,article_category.`title` as cat,article_category.`slug` AS catslug');
		$this->db->join('article_to_category',"article_to_category.`articleId`=articles.`articleId`","left");
		$this->db->join('article_category',"article_category.`articlecatId`=article_to_category.`articlecatId`","left");
		$where = array('articles.`status`'=>1,'article_category.`status`'=>1);
		$this->db->where($where);
		$this->db->like('articles.title', $term);
		$this->db->order_by('articles.createdon','ASC');
		$this->db->group_by('article_category.`articlecatId`');
		$query = $this->db->get('articles');
		return $query->result_array();
	}
	

	public function getgalleryimg($slug){
		$this->db->select('gallery_category.title as cattitle,gallery_category.description as catdescription,gallery_category.slug,gallery_category.categoryId,gallery.*');
		$this->db->join('gallery',"gallery.`itemId`=gallery_category.`categoryId`","left");
		$where = array('gallery_category.`slug`'=>$slug,'gallery.`table`'=>'gallery_category');
		$this->db->where($where);
		$this->db->order_by('gallery.order','ASC');
		$query = $this->db->get('gallery_category');
		return $query->result();
	}
}

?>