<?php 
class Region_model extends CI_Model {
	public function _consruct(){
		parent::_construct();
 	}

 	public function getRegionData($region_id='',$view=''){
 		$cond  = (!empty($view))?" status IN ($view) ":" status != '2' ";
 		$cond .= (!empty($region_id))?" AND id='$region_id' ":"";

 		$regionData = $this->db->query("SELECT * FROM region WHERE $cond");

 		if(!empty($regionData)){
 			return (empty($region_id))?$regionData->result():$regionData->row();
 		}
 		return 0;
 	}

 	public function createRegion($regionData = array()){
 		if(empty($regionData)){
 			return 0;
 		}
 		$status = $this->db->insert('region',$regionData);
 		return $status;
 	}

 	public function updateRegion($region_id = '', $regionData = array()){
 		if(empty($region_id) || empty($regionData)){
 			return 0;
 		}
 		$status = $this->db->update('region',$regionData,array('id'=>$region_id));
 		return $status;
 	}

 	public function changeStatus($region_id = '', $status = '0'){
 		if(empty($region_id)){
 			return 0;
 		}
 		$status = $this->db->update('region',array('status'=>$status),
 										     array('id'=>$region_id));
 		return $status;
 	}

 	public function getlocalityData($region_id = '',$locality_id = '', $status = '0'){
 		$cond = "status IN (".$status.") ";
 		if(!empty($region_id)){
 			$cond .= " AND region_id='$region_id' ";
 		}
 		if(!empty($locality_id)){
 			$cond .= " AND id='$locality_id' ";
 		}
 		$locData = $this->db->query("SELECT * FROM locality WHERE ".$cond);
 		return (!empty($locality_id))?$locData->row():$locData->result();
 	}
}
?>
