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

	public function __construct() {
        parent::__construct();
    }
	public function parallel_session_purchased_list($limit, $offset){
		
		$offset = ($offset-1)*$limit;
		$query=$this->db->select(['*'])->from('parallel_session_purchased')
		//->order_by("parallel_session_purchased", "asc")
    	->limit($limit, $offset)
		->get();
		//echo $this->db->last_query();die;
		return $query->result();
	}
	
	public function num_rows(){
	
		$user_id = $this->session->userdata('user_id');
		$query=$this->db->select(['*'])->from('parallel_session_purchased')->get();
		return $query->num_rows();
	}
	public function insert_parallel_session_purchased($data_parallel_session_purchased){
	
		$this->db->insert('parallel_session_purchased', $data_parallel_session_purchased);
		$data_parallel_session_purchased['id'] = $this->db->insert_id();
    	return $data_parallel_session_purchased['id'];	
	}
	
	public function update_parallel_session_purchased($data_parallel_session_purchased,$list_id){
	
		$this->db->where('id',$list_id);
		$this->db->update('parallel_session_purchased', $data_parallel_session_purchased);
		return true;
	}
	
	public function view_parallel_session_purchased($list_id){
	
		$query=$this->db->select(['*'])->from('parallel_session_purchased')->where('id',$list_id)->get();
		return $query->row();
	}
	public function count_parallel_session_purchased($parallel_session_purchased){
	
		$query=$this->db->select(['*'])->from('parallel_session_purchased')->where('parallel_session_purchased',$parallel_session_purchased)->get();
		return $query->num_rows();
	}
	
	public function delete_parallel_session_purchased($list_id){
	
		$this->db->where('id', $list_id);
		$this->db->delete('parallel_session_purchased');
	}
	function getclass(){
	    $response = array();
	    // Select record
	    $this->db->select('*');
	    $q = $this->db->get('class');
	    $response = $q->result_array();
	    
	    return $response;
	}
	
	// Get City departments
	function get_class_subject($postData){
	    $response = array();
	    
	    // Select record
	    $this->db->select('id,subject');
	    $this->db->where('class_id', $postData['classes']);
	    $q = $this->db->get('subject');
	    $response = $q->result_array();
	    
	    return $response;
	}
	
	// Get Department user
	function get_class_subject_faculty($postData){
	    // echo "<pre>";print_r($postData['subject']);die;
	    $response     = array();
	    $this->db->select('*');
	    $this->db->where('subject_id', $postData['subject']);
	    $q            = $this->db->get('v2_faculty');
	    $response     = $q->result_array();
	    return $response;
	}
	
	
	public function search($data_taskpo){
	    
	    $condition	=	$data_taskpo['seach_term'];
	    $order		=	$data_taskpo['order_by'];
	    $query=$this->db->select(['parallel_session_purchased.*'])
	        ->from('parallel_session_purchased');
	        
	        if($condition=='or' && !empty($order)){
	            
	            if(!empty($data_taskpo['parallel_session_purchased'])){
	                $this->db->or_like('parallel_session_purchased.id',$data_taskpo['parallel_session_purchased'])->order_by('parallel_session_purchased.parallel_session_purchased',$order);
	            }
	            if(!empty($data_taskpo['parallel_session_purchased_code'])){
	                $this->db->or_like('parallel_session_purchased.parallel_session_purchased_code'	,$data_taskpo['parallel_session_purchased_code'])
	                ->order_by('parallel_session_purchased.parallel_session_purchased_code',$order);
	            }
	        }
	        
	        if($condition=='or' && empty($order)){
	            
	            if(!empty($data_taskpo['parallel_session_purchased'])){
	                $this->db->or_like('parallel_session_purchased.id'	,$data_taskpo['parallel_session_purchased'])		;
	            }
	            if(!empty($data_taskpo['parallel_session_purchased_code'])){
	                $this->db->or_like('parallel_session_purchased.parallel_session_purchased_code'	,$data_taskpo['parallel_session_purchased_code'])		;
	            }
	        }
	        
	        if($condition=='and' && !empty($order)){
	            
	            if(!empty($data_taskpo['parallel_session_purchased']))	{
	                $this->db->like('parallel_session_purchased.id',$data_taskpo['parallel_session_purchased'])->order_by('parallel_session_purchased.parallel_session_purchased'	,$order);
	            }
	            if(!empty($data_taskpo['parallel_session_purchased_code'])){
	                $this->db->like('parallel_session_purchased.parallel_session_purchased_code',$data_taskpo['parallel_session_purchased_code'])	->order_by('parallel_session_purchased.parallel_session_purchased_code'		,$order);
	            }
	        }
	        
	        if($condition=='and' && empty($order)){
	            
	            if(!empty($data_taskpo['parallel_session_purchased']))	{
	                $this->db->like('parallel_session_purchased.id',$data_taskpo['parallel_session_purchased']);
	            }
	            if(!empty($data_taskpo['parallel_session_purchased_code']))		{
	                $this->db->like('parallel_session_purchased.parallel_session_purchased_code',$data_taskpo['parallel_session_purchased_code'])	;
	            }            
	        }
	        
	        $query=$this->db->get();
	        //echo $this->db->last_query();die;
	        if($query->num_rows()>0){
	            return $query->result();
	        }
	        else{
	            return $query->result();
	        }
	}
}
?>
