<?php namespace App\Modules\Exhibitions\Models;

class Mdl_exhibitions
{
    /*public function getPagesUsers()
    {
        return [
            UserPagesEntity::of('PL0001', 'Mufid Jamaluddin'),
            UserPagesEntity::of('PL0002', 'Andre Jhonson'),
            UserPagesEntity::of('PL0003', 'Indira Wright'),
        ];
    }*/
    
    protected $db;
   // protected $captcha;
    protected $allowedFields    = [
        'captcha',
        'year_hunter',
        'height_hunter',
        'weight_hunter',
        'type_hunter',
        'type_nen',
        'type_blood'
    ];
    
    public function connect() 
    {
		$this->db = db_connect();
		
	}
    
    	/*
	**	Insert Query 
	*/
	function insert($table, $data) {
		$this->db->insert($table, $data);
		$id = $this->db->insert_id();
		return $id;
	}
	
	/*
	**	Update Query 
	*/
	function update($table, $col, $val, $data) {
		$this->db->where($col, $val);
		return $this->db->update($table, $data);
	}
	
	/*
	**	Delete By Id Query 
	*/
	function deleteById($table, $col, $val) {
		$this->db->where($col, $val);
		$this->db->delete($table);
	}
	
	/*
	**	Get Record By Value Query 
	*/
	function getByValue($table, $col, $val){
	    
	    $db = \Config\Database::connect();
	    $mysql_query = 'SELECT * FROM '.$table.' WHERE '.$col.' = "'.$val.'"';
		$query = $db->query($mysql_query);
		return $query->getResult(); 
			
		/*$this->db->where($col, $val);
		$query=$this->db->get($table);
		if($query->num_rows() > 0){
			return $query->result(); 
		}else{
			return "No Data";
		} */
	}

	/*
	**	Get Record By Values Query 
	*/
	function getByValues($table, $param) {
		foreach($param as $key => $value){
			$this->db->where($key, $value);
		}
		$query=$this->db->get($table);
		if($query->num_rows() > 0){
			return $query->result(); 
		}else{
			return "No Data";
		} 
	}

	/*
	**	Get All Records Query 
	*/
	function getAllRecords($table) {
	    
	    $db = \Config\Database::connect();
	    $mysql_query = 'SELECT * FROM '.$table;
		$query = $db->query($mysql_query);
		return $query->getResult();
		
		/*$query=$this->db->get($table);
		if($query->num_rows() > 0){
			return $query->result(); 
		}else{
			return "No Data";
		} */
	}
	
	/*
	**	isExist Query
	*/
	function isExist($table, $col, $val){
		$this->db_->where($col, $val);
		$query=$this->db_->get($table);
		if($query->num_rows() > 0){
			return TRUE; 
		}else{
			return FALSE;
		} 
	}
	
	/*
	**	Active Query
	*/
	function active($table, $col, $val){
		$this->db->where($col, $val);
		return $this->db->update($table, array('isActive'=>'1'));
	}
	
	/*
	**	Inactive Query
	*/
	function inactive($table, $col, $val){
		$this->db->where($col, $val);
		return $this->db->update($table, array('isActive'=>'0'));
	}
	
	/*
	**	Custom Query
	*/
	function customQuery($mysql_query) {
	   $db = \Config\Database::connect();
		$query = $db->query($mysql_query);
		//if($query->num_rows() > 0){
			return $query->getResult(); 
    //}else{
    //  return "No Data";
    //}
	}

  function count($table){
    return $this->db->count_all_results($table);
	}
}