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

 	public function getVenueData($venue_id='',$view='',$provider_id=''){
 		$cond  = (!empty($view))?" VNE.status IN ($view) ":" VNE.status != '2' ";
 		$cond .= (!empty($venue_id))?" AND VNE.id='$venue_id' ":"";
 		$cond .= (!empty($provider_id))?" AND VNE.provider_id='$provider_id' ":"";

 		$sql = "SELECT VNE.id AS venue_id,VNE.*,REG.name AS region_name,HST.host_category,HST.show_layout
 				FROM venue AS VNE
 				INNER JOIN region AS REG ON (VNE.region_id=REG.id)
 				INNER JOIN host_categories AS HST ON (HST.host_cat_id=VNE.host_cat_id)
 				WHERE $cond";

 		$venueData = $this->db->query($sql);

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

 	public function createVenue($venueData = array(),$locality = array()){
 		if(empty($venueData)){
 			return 0;
 		}
 		if(!empty($locality)){
	 		$status = $this->db->insert('locality',
	 				  array('locality'=>$locality['locality'],
	 				  		'locality_ar'=>$locality['locality_ar'],
	 				  	    'region_id'=>$venueData['region_id']));

	 		if($status){
	 			$venueData['locality_id'] = $this->db->insert_id();
	 		}
	 	}
 		$status = $this->db->insert('venue',$venueData);

 		return $status;
 	}

 	public function updateVenues($venue_id = '', $venueData = array(), $locality = array()){
 		if(empty($venue_id) || empty($venueData)){
 			return 0;
 		}
 		if(!empty($locality)){
	 		$status = $this->db->insert('locality',
	 				  array('locality'=>$locality['locality'],
	 				  		'locality_ar'=>$locality['locality_ar'],
	 				  	    'region_id'=>$venueData['region_id']));

	 		if($status){
	 			$venueData['locality_id'] = $this->db->insert_id();
	 		}
	 	}
 		$status = $this->db->update('venue',$venueData,array('id'=>$venue_id));
 		return $status;
 	}

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