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



public function get_all_Assist_booking($filter=null) {
        if($filter){
            $this->db->order_by($filter['order_by'], $filter['order_type']);
            if(!empty($filter['where'])){
                $this->db->where($filter['where']);
            }
            if($filter['length']!=-1)
                $this->db->limit($filter['length'],$filter['start']);
            }
        
        
        $this->db->order_by('road_booking.date','desc');
        $this->db->select("customer.name as customer_name,customer.phone_no as customer_phone,customer.email_id,road_booking.*,vehicle_model.year,vehicle_model.vin,vehicle_model.model,vehicle_model.make,vehicle_model.vehicle_name,vehicle_model.mileage,road_assist.road_assist_code,road_assist.name as road_assist_name,road_assist.phone_no as road_assist_phone,road_assist.email_id as road_assist_email");
        $this->db->from('road_booking');
        $this->db->join('customer', 'customer.cust_id = road_booking.cust_id');
        $this->db->join('vehicle_model', 'vehicle_model.id = road_booking.vehicle_id');
        $this->db->join('road_assist', 'road_assist.road_assist_id = road_booking.road_assist_id');
        $res = $this->db->get();
        
        return $res->result();
    }












 	public function getAssist_bookingData($booking_id=''){

 		
        $this->db->order_by('road_booking.date','desc');
        $this->db->where('road_booking.id',$booking_id);
        $this->db->select("customer.name as customer_name,customer.phone_no as customer_phone,customer.email_id,road_booking.*,vehicle_model.year,vehicle_model.vin,vehicle_model.model,vehicle_model.make,vehicle_model.vehicle_name,vehicle_model.mileage,road_assist.road_assist_code,road_assist.name as road_assist_name,road_assist.phone_no as road_assist_phone");
        $this->db->from('road_booking');
        $this->db->join('customer', 'customer.cust_id = road_booking.cust_id');
        $this->db->join('vehicle_model', 'vehicle_model.id = road_booking.vehicle_id');
         $this->db->join('road_assist', 'road_assist.road_assist_id = road_booking.road_assist_id');
        
        $res = $this->db->get();
        
        return $res->result();
    }






 
 	public function changeStatus($booking_id = '', $status = '0'){

 		if(empty($booking_id)){
 			return 0;
 		}

 		$status = $this->db->update('users',array('status'=>$status),array('profile_id'=>$booking_id,'user_type'=>'1'));
 		
 		return $status;
 	}



public function email_availability_check($email)
    {
if($email!=''){

        $query = "SELECT * FROM Assist_booking AS CUST 
 									   INNER JOIN users AS USR ON (USR.profile_id=CUST.cust_id)
 									   WHERE USR.status!='2' AND CUST.cust_id!='".$booking_id."' AND 
								   			 USR.username='".$email."'";
        $query=$this->db->query($query,array($email));
        if($query->num_rows()>0)
        {
            return $query->row_array();
        } else
        {
            return false;
        }

        }
    return false;
    }



}
?>