<?php

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

class Property_model extends CI_Model
{
	public function __construct(){
		parent::__construct();
	}
	
	
/*#############################################################################################*/
/*################################################ General START ######################################*/
/*#########################################################################################################*/
	
	public function get_general($status=NULL){
		$this->db->select('*');
		if($status>=0){
			$where = array('status='=>$status);
			$this->db->where($where);
		}
		$this->db->order_by('updatedon','ASC');
		$query = $this->db->get('property');
		
		return $query->result();
	}
	
	public function get_single_general($id){
		$this->db->select('*');
		$where = array('PropertyId='=>$id);
		$this->db->where($where);
		$query = $this->db->get('property');		
		return $query->result();
	}
	
	public function delete_general($id){
		$this->db->where('PropertyId', $id );
		$this->db->delete('property');
		
		$this->db->where(array('itemId='=>$id,'table='=>'property') );
		$this->db->delete('site_seo');
	}
	
	public function set_general($data,$id){
		
		if($id>0)
		{
			$this->db->where('PropertyId', $id);
			$this->db->update('property', $data);	
		}else{
			
			$this->db->insert('property', $data);
			
			$insert_id = $this->db->insert_id();
			
			$seo['itemId']=$insert_id;
			$seo['slug']=$data['slug'];
			$seo['table']='property';
			$this->db->insert('site_seo', $seo);			
		}
		

	}
	
	public function get_gallery($id){
		$this->db->select('property.name,gallery.*');		
		$this->db->join('property','property.propertyId=gallery.itemId');
		$this->db->where(array('gallery.itemId'=>$id,'gallery.table'=>'property','gallery.type'=>0));
		$this->db->order_by('gallery.updatedon','ASC');
		$query = $this->db->get('gallery');		
		return $query->result();
	}
/*#################################################################################################*/
/*###################################### General END ##################################*/
/*#####################################################################################*/

public function set_page_seo($data,$id){
		
			$this->db->where('itemId', $id);
			$this->db->update('site_seo', $data);

			$this->db->where('PropertyId', $id);
			$this->db->update('property', array('slug'=>$data['slug']));	
	}
		
		public function get_page_seo($id){
		$this->db->select('*');
		$where = array('itemId='=>$id,'table='=>'property');
		$this->db->where($where);
		$query = $this->db->get('site_seo');		
		return $query->result();
	}
}

?>