<?php
class Postings_Model extends CI_Model {
	function __construct(){

	}

	
	public function getPostingImages($id,$main=true){
		$this->db->select('*');
		$this->db->from('postingimages');
		$this->db->where('posting_id',$id);
                if($main){
                    $this->db->where('is_main',1);
                    $query=$this->db->get();
                    return $query->row();
                }else{
                    $query = $this->db->get();
                    return $query->result();
                }
	}
	public function getPostingSImages($id){
		$this->db->select('*');
		$this->db->from('postingimages');
		$this->db->where('posting_id',$id);
               
                    $this->db->where('is_main',0);
                    $query=$this->db->get();
                    return $query->row();
                
	}
	public function getDetails($id){
		$this->db->select('*');
		$this->db->from('postings');
		$this->db->where('id',$id);
		$query=$this->db->get();
		return $query->row();
	}
	
	public function searchListings($search=null,$limit=5,$start=0){
		$sql="select * from postings where";
		if(!empty($search) && $search != 'all'){
			$sql.=" title like '%".$search."%' or description like '%".$search."%' and ";
		}
		$sql.=" published=1";
		$all_records=$this->db->query($sql);
		$all_record_count=$all_records->num_rows();
		$sql.=" order by id asc ";
		//$sql.=" order by dt_created desc ";
		//$sql.=" limit $start,$limit";
                $query=$this->db->query($sql);
		$data['total_rec']=$all_record_count;
		$data['result']=$query->result();
		return $data;
	}
} 
?>
