<?php defined('BASEPATH') or exit('No direct Access is Allowed'); ?>
<?php
class Attendeemodel extends CI_Model{

	public function __construct() {
        parent::__construct();
    }
	public function attendee_list($limit, $offset){

		$offset = ($offset-1)*$limit;
		$query=$this->db->select(['*'])->from('master_user')->where('category','2')
		//->order_by("attendee", "asc")
    	->limit($limit, $offset)
		->get();
		//echo $this->db->last_query();die;
		return $query->result();
	}

	public function attendee_list_name(){
		  $query   =	 $this->db->select(['id','first_name','last_name'])
		  ->from('master_user')
		   ->where('master_user.category','2')->order_by("id", "asc")->get();
	    $return 	= 	array();
	    if($query->num_rows() > 0) {
	        $return[''] = ('Select name');
	        foreach($query->result_array() as $row) {
	           $return[$row['id']] = strtoupper($row['first_name'].$row['last_name']);
	        }
	    }
	    return $return;
    }
	public function attendee_list_email(){
		  $query   =	 $this->db->select(['id','email'])
		  ->from('master_user')
		   ->where('master_user.category','2')->order_by("id", "asc")->get();
	    $return 	= 	array();
	    if($query->num_rows() > 0) {
	        $return[''] = ('Select email');
	        foreach($query->result_array() as $row) {
	           $return[$row['id']] = strtoupper($row['email']);
	        }
	    }
	    return $return;
    }

	public function attendee_list_mobile(){
		  $query   =	 $this->db->select(['id','mobile'])
		  ->from('master_user')
		   ->where('master_user.category','2')->order_by("id", "asc")->get();
	    $return 	= 	array();
	    if($query->num_rows() > 0) {
	        $return[''] = ('Select mobile');
	        foreach($query->result_array() as $row) {
	           $return[$row['id']] = strtoupper($row['mobile']);
	        }
	    }
	    return $return;
    }

	public function num_rows(){

	    $query=$this->db->select(['*'])->from('master_user')->where('category','2')->get();
		return $query->num_rows();
	}
	public function insert_attendee($data_attendee){

		$this->db->insert('master_user', $data_attendee);
		$data_attendee['id'] = $this->db->insert_id();
    	return $data_attendee['id'];
	}

	public function update_attendee($data_attendee,$list_id){
	    $this->db->where('category','2');
		$this->db->where('id',$list_id);
		$this->db->update('master_user', $data_attendee);
		return true;
	}

	public function view_attendee($list_id){

	    $query=$this->db->select(['*'])->from('master_user')->where('category','2')->where('id',$list_id)->get();
		return $query->row();
	}

	public function delete_attendee($list_id){
	    $this->db->where('category','2');
		$this->db->where('id', $list_id);
		$this->db->delete('master_user');
	}
	public function count_attendee($email){
	    $query=$this->db->select(['email'])->from('master_user')->where('category','2')->where('email',$email)->get();
	    return $query->num_rows();
	}
	public function search($data_taskpo){

	    $condition	=	$data_taskpo['seach_term'];
	    $order		=	$data_taskpo['order_by'];
		$sql		=
	    $query=$this->$query=$this->db->select(['*'])->from('master_user')->where('category','2');

	        if($condition=='or' && !empty($order)){

	            if(!empty($data_taskpo['email'])){
	                $this->db->or_where('master_user.id', $data_taskpo['email']);
	            }

				 if(!empty($data_taskpo['name'])){
	                $this->db->or_where('master_user.id', $data_taskpo['name'])
	                ->order_by('master_user.id',$order);
	            }

				if(!empty($data_taskpo['mobile'])){
	                $this->db->or_where('master_user.id',$data_taskpo['mobile'])->order_by('master_user.mobile',$order);
	            }

	        }

	        if($condition=='or' && empty($order)){
	            if(!empty($data_taskpo['email'])){
	                $this->db->or_where('master_user.id', $data_taskpo['email']);
	            }
				if(!empty($data_taskpo['name'])){
	                $this->db->or_where('master_user.id', $data_taskpo['name']);
	            }

				if(!empty($data_taskpo['mobile'])){
	                $this->db->or_where('master_user.id', $data_taskpo['mobile']);
	            }

	        }

	        if($condition=='and' && !empty($order)){

	           if(!empty($data_taskpo['email'])){
	                $this->db->where('master_user.id',$data_taskpo['email'])->order_by('master_user.email', $order);
	            }
	            if(!empty($data_taskpo['name'])){
	                $this->db->where('master_user.id',$data_taskpo['name'])->order_by('master_user.id', $order);
	            }

				if(!empty($data_taskpo['mobile']))	{
	                $this->db->where('master_user.id',$data_taskpo['mobile'])->order_by('master_user.mobile',$order);
	            }
	        }

	        if($condition=='and' && empty($order)){

				if(!empty($data_taskpo['email']))		{
	                $this->db->where('master_user.id',$data_taskpo['email'])	;
	            }
				if(!empty($data_taskpo['name']))		{
	                $this->db->where('master_user.id',$data_taskpo['name'])	;
	            }

	           if(!empty($data_taskpo['mobile']))	{
	                $this->db->where('master_user.id',$data_taskpo['mobile']);
	            }

	        }

	        $query=$this->db->get();
			//echo $this->db->last_query();die;
	        if($query->num_rows()>0){
	            return $query->result();
	        }
	        else{
	            return $query->result();
	        }
	}
}
?>
