<?php

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

class Locations_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('locations');
		
		return $query->result();
	}
	
	public function get_single_general($id){
		$this->db->select('*');
		$where = array('locationId='=>$id);
		$this->db->where($where);
		$query = $this->db->get('locations');		
		return $query->result();
	}
	
	public function delete_general($id){
		$this->db->where('locationId', $id );
		$this->db->delete('locations');
		
		$this->db->where(array('itemId='=>$id,'table='=>'locations') );
		$this->db->delete('site_seo');
	}
	
	public function set_general($data,$id){
		
		if($id>0)
		{
			$this->db->where('locationId', $id);
			$this->db->update('locations', $data);	
		}else{
			
			$this->db->insert('locations', $data);
			
			$insert_id = $this->db->insert_id();
			
			$seo['itemId']=$insert_id;
			$seo['slug']=$data['slug'];
			$seo['table']='locations';
			$this->db->insert('site_seo', $seo);			
		}
		

	}
/*###########################################################################################*/
/*########################################## General END ############################################*/
/*############################################################################*/

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

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

?>