Viewing file: Activation_model.php (2.54 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
class Activation_model extends CI_Model{
function __construct() {
$this->table = 'activations';
$this->column_order = array(null, 'activations.number', 'activations.service_id', 'activations.message', 'activations.user', 'activations.status', 'activations.time');
$this->column_search = array('activations.id', 'activations.number', 'activations.service_id', 'activations.message', 'activations.user', 'activations.status', 'activations.time');
$this->order = array('activations.id' => 'desc');
}
public function getRows($postData){
$this->_get_datatables_query($postData);
if(isset($postData['length']) && $postData['length'] != -1){
$this->db->limit($postData['length'], $postData['start']);
}
$this->db->select('activations.*, users.name as username, services.name as service_name, categories.name as category_name');
$this->db->join('users', 'users.id = activations.user', 'left');
$this->db->join('services', 'services.id = activations.service_id', 'left');
$this->db->join('categories', 'categories.id = services.category', 'left');
$query = $this->db->get();
return $query->result();
}
public function countAll(){
$this->db->from($this->table);
return $this->db->count_all_results();
}
public function countFiltered($postData){
$this->_get_datatables_query($postData);
$query = $this->db->get();
return $query->num_rows();
}
private function _get_datatables_query($postData){
$this->db->from($this->table);
$i = 0;
foreach($this->column_search as $item){
if(isset($postData['search']) && $postData['search']['value']){
if($i===0){
$this->db->group_start();
$this->db->like($item, $postData['search']['value']);
}else{
$this->db->or_like($item, $postData['search']['value']);
}
if(count($this->column_search) - 1 == $i){
$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)]);
}
}
}
?>
|