HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //var/www/html/pmw24/app/application/models/admin/Mlog.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mlog extends CI_Model {

	var $table = 'log';
	

    var $column_order = array('log_id','action_type','log_title','log_description','name','log_ts',null); //set column field database for datatable orderable
    var $column_search = array('action_type','log_title','log_description','name','log_ts'); //set column field database for datatable searchable just firstname , lastname , address are searchable
    var $order = array('log_id' => 'DESC'); // default order 
	public function __construct() {
		parent::__construct();
	}
	private function _get_datatables_query(){
        $this->db->select('log.*,admins.name,date_format(log.log_ts,"%d/%m/%Y %h:%i %p") as log_ts');
        $this->db->from($this->table);
        $this->db->join('admins','admins.admin_id=log.action_done_by','LEFT');
		$i = 0;
        foreach ($this->column_search as $item){ // loop column 
            if($_POST['search']['value']){ // if datatable send POST for search
                 
                if($i===0){ // first loop
					$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
                    $this->db->like($item, $_POST['search']['value']);
                }
                else{
                    $this->db->or_like($item, $_POST['search']['value']);
                }
				if(count($this->column_search) - 1 == $i) //last loop
                $this->db->group_end(); //close bracket
            }
            $i++;
        }
         
        if(isset($_POST['order'])){ // here order processing
			$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
        }else if(isset($this->order)){
            $order = $this->order;
            $this->db->order_by(key($order), $order[key($order)]);
        }
    }
	public function get_datatables(){	
        $this->_get_datatables_query();
        if($_POST['length'] != -1)
        $this->db->limit($_POST['length'], $_POST['start']);
        $query = $this->db->get();
	
        return $query->result();
    }
	public function count_filtered(){
        $this->_get_datatables_query();
        $query = $this->db->get();
        return $query->num_rows();
    }
    public function count_all(){
        $this->db->from($this->table);
        return $this->db->count_all_results();
    }
	public function get_details($cms_id){
		$this->db->select('*');
		$this->db->from($this->table);
		$this->db->where('cms_id',$cms_id);
		$query=$this->db->get();
		return $query->row_array();
	}
	public function update($condition,$data){
		$this->db->where($condition);
		$this->db->update($this->table,$data);
		return 1;
	}
	public function add($data){
		$this->db->insert($this->table,$data);
		return true;
	}
	public function delete($condition){
		$this->db->delete($this->table,$condition);
		return 1;
	}
}