MCmaniac

model.php

May 25th, 2016
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.04 KB | None | 0 0
  1. private function _get_datatables_query()
  2.     {
  3.        
  4.         $this->db->from($this->table);
  5.        
  6.  
  7.         $i = 0;
  8.    
  9.         foreach ($this->column as $item) // loop column 'kd_barang','nm_barang','harga_Laundry','harga_Dryclean'
  10.         {
  11.             if($_POST['columns']['1']['search']['value'])
  12.             {
  13.                 if($i===0) // first loop
  14.                 {
  15.                    
  16.                     $this->db->group_start();
  17.                     $this->db->like($item, $_POST['columns']['1']['search']['value']);
  18.                 }
  19.                 else
  20.                 {
  21.                     $this->db->or_like($item, $_POST['columns']['1']['search']['value']);
  22.                 }
  23.  
  24.                     if(count($this->column) - 1 == $i) //last loop
  25.                     $this->db->group_end(); //close bracket
  26.                
  27.             }
  28.            
  29.            
  30.            
  31.             if($_POST['search']['value']) // if datatable send POST for search
  32.             {
  33.             //  for($i = 0, $i <  count($this->column), $i++
  34.                 if($i===0) // first loop
  35.                 {
  36.                     $this->db->group_start();
  37.                     $this->db->like($item, $_POST['search']['value']);
  38.                 }
  39.                 else
  40.                 {
  41.                     $this->db->or_like($item, $_POST['search']['value']);
  42.                 }
  43.  if(count($this->column) - 1 == $i) //last loop
  44.                     $this->db->group_end(); //close bracket
  45.                
  46.             }
  47.        
  48.             $column[$i] = $item; // set column array variable to order processing
  49.             $i++;
  50.         }
  51.         if(isset($_POST['order'])) // here order processing
  52.         {
  53.             $this->db->order_by($column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
  54.         }
  55.         else if(isset($this->order))
  56.         {
  57.             $order = $this->order;
  58.             $this->db->order_by(key($order), $order[key($order)]);
  59.         }
  60.     }
  61.  
  62.     function get_datatables()
  63.     {
  64.         $this->_get_datatables_query();
  65.         if($_POST['length'] != -1)
  66.         $this->db->limit($_POST['length'], $_POST['start']);
  67.         $query = $this->db->get();
  68.         return $query->result();
  69.     }
  70.  
  71.     function count_filtered()
  72.     {
  73.         $this->_get_datatables_query();
  74.         $query = $this->db->get();
  75.         return $query->num_rows();
  76.     }
  77.    
  78.     public function delete_by_id($id)
  79.     {
  80.         $this->db->where('kd_barang', $id);
  81.         $this->db->delete($this->table);
  82.     }
  83.  
  84.     public function count_all()
  85.     {
  86.         $this->db->from($this->table);
  87.         return $this->db->count_all_results();
  88.     }
Advertisement
Add Comment
Please, Sign In to add comment