SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | ||
3 | namespace App\Models; | |
4 | ||
5 | use CodeIgniter\HTTP\RequestInterface; | |
6 | use CodeIgniter\Model; | |
7 | ||
8 | class Modelfile extends Model | |
9 | { | |
10 | protected $table = ""; | |
11 | protected $column_order = array(); | |
12 | protected $column_search = array(); | |
13 | protected $order = array('' => ''); | |
14 | protected $request; | |
15 | protected $db; | |
16 | protected $dt; | |
17 | ||
18 | function __construct(RequestInterface $request) | |
19 | { | |
20 | parent::__construct(); | |
21 | $this->db = db_connect(); | |
22 | $this->request = $request; | |
23 | ||
24 | $this->dt = $this->db->table($this->table); | |
25 | } | |
26 | private function _get_datatables_query() | |
27 | { | |
28 | $i = 0; | |
29 | foreach ($this->column_search as $item) { | |
30 | if ($this->request->getPost('search')['value']) { | |
31 | if ($i === 0) { | |
32 | $this->dt->groupStart(); | |
33 | $this->dt->like($item, $this->request->getPost('search')['value']); | |
34 | } else { | |
35 | $this->dt->orLike($item, $this->request->getPost('search')['value']); | |
36 | } | |
37 | if (count($this->column_search) - 1 == $i) | |
38 | $this->dt->groupEnd(); | |
39 | } | |
40 | $i++; | |
41 | } | |
42 | ||
43 | if ($this->request->getPost('order')) { | |
44 | $this->dt->orderBy($this->column_order[$this->request->getPost('order')['0']['column']], $this->request->getPost('order')['0']['dir']); | |
45 | } else if (isset($this->order)) { | |
46 | $order = $this->order; | |
47 | $this->dt->orderBy(key($order), $order[key($order)]); | |
48 | } | |
49 | } | |
50 | function get_datatables() | |
51 | { | |
52 | $this->_get_datatables_query(); | |
53 | if ($this->request->getPost('length') != -1) | |
54 | $this->dt->limit($this->request->getPost('length'), $this->request->getPost('start')); | |
55 | $query = $this->dt->get(); | |
56 | return $query->getResult(); | |
57 | } | |
58 | function count_filtered() | |
59 | { | |
60 | $this->_get_datatables_query(); | |
61 | return $this->dt->countAllResults(); | |
62 | } | |
63 | public function count_all() | |
64 | { | |
65 | $tbl_storage = $this->db->table($this->table); | |
66 | return $tbl_storage->countAllResults(); | |
67 | } | |
68 | } |