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

	function getAppReason(){
		$reason = $this->db->get_where('appointment_reason', array('status'=>'1'));
		if(!empty($reason)){
			return $reason->result();
		}
		return;
	}

	function getTripType(){
		$tripType = $this->db->get_where('trip_type', array('status'=>'1'));
		if(!empty($tripType)){
			return $tripType->result();
		}
		return;
	}

	function uploadRides($insertArr = array()){
		if(empty($insertArr)){
			return 0;
		}
		$status = $this->db->insert_batch('transport_details',$insertArr);
		return ($status)?1:0;
	}

	function create_ride($data = array()){
		if(empty($data)){
			return 0;
		}
		$status = $this->db->insert('transport_details',$data);
		return ($status)?1:0;
	}

	function getRideData($ride_id = ''){
		$cond = (!empty($ride_id))?" AND TD.transport_id = '$ride_id'":"";
		$sql = "SELECT TD.*, BK.broker_name
				FROM transport_details AS TD
				LEFT JOIN brokers AS BK ON (TD.broker_id = BK.broker_id)
				WHERE TD.status != '2' ".$cond."
				ORDER BY TD.transport_id DESC";
		$ride_data = $this->db->query($sql);
		if(empty($ride_data)){
			return;
		}
		return (!empty($ride_id))?$ride_data->row():$ride_data->result();
	}

 	function changeStatus($ride_id = '', $status = '0'){
 		if(empty($ride_id)){
 			return 0;
 		}
 		$status = $this->db->update('transport_details',array('status'=>$status), array('transport_id'=>$ride_id));
 		return $status;
 	}
}
?>