<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Drivers_model extends CI_Model{
	 protected $table = 'drivers';

	public function add_drivers($data) { 
		$driverins = $data; 
		if(isset($data['d_password'])) { 
			$driverins['d_password'] = md5($data['d_password']); 
		}
			$this->db->insert('drivers',$driverins); 
		return $this->db->insert_id();
	}
	  public function get_count() {
        return $this->db->count_all($this->table);
    }
	public function add_driver_documents($data) { 
		return	$this->db->insert('driver_documents',$data);	} 
		
    public function getall_drivers() { 
		$organization_id=$this->session->userdata['session_data']['organization_id'];
		if($organization_id == "0"){
			return $this->db->select('*')->from('drivers')->order_by('d_id','desc')->get()->result_array();
		}else{
			   // $this->db->limit($limit, $start);
			   // $this->db->where('organization_id',$organization_id);

      //   return $this->db->get($this->table);
			return $this->db->select('*')->from('drivers')->where('organization_id',$organization_id)->order_by('d_id','desc')->get()->result_array();
		}
		
	}
	public function getall_feedback() { 
		//return $this->db->select('*')->from('customers')->order_by('c_id','desc')->get()->result_array();

		$organization_id=$this->session->userdata['session_data']['organization_id'];
		$this->db->select("*");
		$this->db->from('feedback_drivers');
		$this->db->join('drivers', 'drivers.d_id=feedback_drivers.f_d_id');
		// $this->db->join('customers', 'customers.c_id=feedback_customers.f_c_id');

		$this->db->where('drivers.organization_id',$organization_id);
		 
		$query = $this->db->get();
		return $query->result_array();


	} 
	public function get_feedback($fd_id) { 
		return $this->db->select('*')->from('feedback_drivers')->where('fd_id',$fd_id)->get()->result_array();
		
	} 
	public function getall_active_drivers() {  
		//return $this->db->select('*')->from('drivers')->order_by('d_id','desc')->get()->result_array();
		return $this->db->select('*')->from('drivers')->where('d_is_active',1)->order_by('d_id','desc')->get()->result_array();
	} 

	public function get_driverdetails($d_id) { 
		//return $this->db->select('*')->from('drivers')->where('d_id',$d_id)->get()->result_array();
		 $this->db->select("*");
		 $this->db->from('drivers');
		 $this->db->join('organization', 'organization.org_id=drivers.organization_id');
		 $this->db->where('drivers.d_id',$d_id);
		 $query = $this->db->get();
		return $query->result_array();
	} 
	public function edit_driver() { 
		$this->db->where('d_id',$this->input->post('d_id'));
		return $this->db->update('drivers',$this->input->post());
	}
} 