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/pmw_live_testing/OLD_Root_BAK/application/models/admin/Muser.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mcms extends CI_Model {

	var $table = 'cms';
    var $column_order = array('cms_id','page_name','status','date_of_creation',null); //set column field database for datatable orderable
    var $column_search = array('page_name','status','date_of_creation'); //set column field database for datatable searchable just firstname , lastname , address are searchable
    var $order = array('page_name' => 'asc'); // default order 
	public function __construct() {
		parent::__construct();
	}
	private function _get_datatables_query(){
        $this->db->from($this->table);
		$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;
	}
}