| Server IP : 144.76.79.100 / Your IP : 216.73.216.103 [ Web Server : Apache System : Linux ch05.wehostwebserver.com 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64 User : razzlestore ( 1092) PHP Version : 8.2.29 Disable Function : NONE Domains : 343 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/public_html/application/models/ |
Upload File : |
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Dt_model extends CI_Model{
function __construct($data = array()) {
$this->table = '';
$this->select = '';
// Set orderable column fields
$this->column_order = '';
// Set searchable column fields
$this->column_search = '';
// Set default order
$this->order = '';
$this->where = array();
$this->where_in = array();
$this->where_in_field = '';
$this->join_array = array();
$this->join = '';
$this->join_table = '';
$this->join_type = '';
}
/*
* Fetch members data from the database
* @param $_POST filter data based on the posted parameters
*/
public function getRows($postData,$vars){
$this->table = $vars['table'];
$this->select = !empty($vars['select'])?$vars['select']:$this->select;
$this->column_order = $vars['column_order'];
$this->column_search = $vars['column_search'];
$this->order = $vars['order'];
$this->where = !empty($vars['where'])?$vars['where']:$this->where;
$this->where_in = !empty($vars['where_in'])?$vars['where_in']:$this->where_in;
$this->where_in_field = !empty($vars['where_in_field'])?$vars['where_in_field']:$this->where_in_field;
$this->join_array = (!empty($vars['join_array']) && is_array($vars['join_array']))?$vars['join_array']:$this->join_array;
$this->join = (!empty($vars['join']))?$vars['join']:$this->join;
$this->join_table = (!empty($vars['join_table']))?$vars['join_table']:$this->join_table;
$this->join_type = (!empty($vars['join_type']))?$vars['join_type']:$this->join_type;
$this->_get_datatables_query($postData);
if($postData['length'] != -1){
$this->db->limit($postData['length'], $postData['start']);
}
$query = $this->db->get();
return $query->result();
}
/*
* Count all records
*/
public function countAll($vars){
$this->table = $vars['table'];
$this->db->from($this->table);
return $this->db->count_all_results();
}
/*
* Count records based on the filter params
* @param $_POST filter data based on the posted parameters
*/
public function countFiltered($postData,$vars){
$this->table = $vars['table'];
$this->_get_datatables_query($postData);
$query = $this->db->get();
return $query->num_rows();
}
/*
* Perform the SQL queries needed for an server-side processing requested
* @param $_POST filter data based on the posted parameters
*/
private function _get_datatables_query($postData){
if(!empty($this->select)){
$this->db->select($this->select);
}
if(!empty($this->where)){
$this->db->where($this->where);
}
if(!empty($this->where_in_field && $this->where_in)){
$this->db->where_in($this->where_in_field, $this->where_in);
}
if(!empty($this->join_array) && is_array($this->join_array)){
foreach($this->join_array as $record){
$this->db->join($record['join_table'],$record['join'],$record['join_type']);
$this->db->where($record['join_table'].'_status','enable');
}
}
if(!empty($this->join)){
$this->db->join($this->join_table,$this->join,$this->join_type);
}
$this->db->from($this->table);
$this->db->where($this->table.'_status', 'enable');
$i = 0;
// loop searchable columns
foreach($this->column_search as $item){
// if datatable send POST for search
if($postData['search']['value']){
// first loop
if($i===0){
// open bracket
$this->db->group_start();
$this->db->like($item, $postData['search']['value']);
}else{
$this->db->or_like($item, $postData['search']['value']);
}
// last loop
if(count($this->column_search) - 1 == $i){
// close bracket
$this->db->group_end();
}
}
$i++;
}
if(isset($postData['order'])){
$this->db->order_by($this->column_order[$postData['order']['0']['column']], $postData['order']['0']['dir']);
}else if(isset($this->order)){
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
private function _get_datatables_query2($postData){
$this->db->from($this->table);
$this->db->where($this->table.'_status', 'enable');
$i = 0;
// loop searchable columns
foreach($this->column_search as $item){
// if datatable send POST for search
if($postData['search']['value']){
// first loop
if($i===0){
// open bracket
$this->db->group_start();
$this->db->like($item, $postData['search']['value']);
}else{
$this->db->or_like($item, $postData['search']['value']);
}
// last loop
if(count($this->column_search) - 1 == $i){
// close bracket
$this->db->group_end();
}
}
$i++;
}
if(isset($postData['order'])){
$this->db->order_by($this->column_order[$postData['order']['0']['column']], $postData['order']['0']['dir']);
}else if(isset($this->order)){
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
}