From 37ea4bea2ab3e23903c74b709fbdb0af5957e91e Mon Sep 17 00:00:00 2001 From: Denis <27.idea@gmail.com> Date: Fri, 28 Oct 2016 18:40:26 +0700 Subject: [PATCH 1/4] Update Datatables.php Fix alias issue by add "ci->from" method and change "ci->get" method on some method Fix distinct issue --- application/libraries/Datatables.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/application/libraries/Datatables.php b/application/libraries/Datatables.php index c6de11f..519410f 100644 --- a/application/libraries/Datatables.php +++ b/application/libraries/Datatables.php @@ -109,6 +109,7 @@ public function group_by($val) */ public function from($table) { + $this->ci->db->from($table); $this->table = $table; return $this; } @@ -351,7 +352,7 @@ private function get_filtering() */ private function get_display_result() { - return $this->ci->db->get($this->table); + return $this->ci->db->get(); } /** @@ -420,6 +421,8 @@ private function produce_output($output, $charset) */ private function get_total_results($filtering = FALSE) { + $this->ci->db->from($this->table); + if($filtering) $this->get_filtering(); @@ -446,11 +449,11 @@ private function get_total_results($filtering = FALSE) if(strlen($this->distinct) > 0) { - $this->ci->db->distinct($this->distinct); - $this->ci->db->select($this->columns); + $this->ci->db->distinct(); + $this->ci->db->select($this->select); } - $query = $this->ci->db->get($this->table, NULL, NULL, FALSE); + $query = $this->ci->db->get(NULL, NULL, NULL, FALSE); return $query->num_rows(); } From 9468c5becae2d66e3d88c8cb080466bdbf96cc71 Mon Sep 17 00:00:00 2001 From: Denisa Rachman <27.idea@gmail.com> Date: Wed, 8 Apr 2020 20:16:05 +0700 Subject: [PATCH 2/4] Update for CI4 --- .../Datatables.php => Datatables.php | 118 +++++++++--------- readme.txt | 58 ++------- 2 files changed, 65 insertions(+), 111 deletions(-) rename application/libraries/Datatables.php => Datatables.php (83%) diff --git a/application/libraries/Datatables.php b/Datatables.php similarity index 83% rename from application/libraries/Datatables.php rename to Datatables.php index 519410f..0226caa 100644 --- a/application/libraries/Datatables.php +++ b/Datatables.php @@ -1,18 +1,5 @@ - - * @author Vincent Bambico - * Yusuf Ozdemir - * @link http://ellislab.com/forums/viewthread/160896/ - */ +ci =& get_instance(); + $db = \Config\Database::connect(); + + $this->db = $db; + $this->request = \Config\Services::request(); } /** @@ -50,8 +43,8 @@ public function __construct() */ public function set_database($db_name) { - $db_data = $this->ci->load->database($db_name, TRUE); - $this->ci->db = $db_data; + $db = \Config\Database::connect($db_name); + $this->db = $db; } /** @@ -71,7 +64,7 @@ public function select($columns, $backtick_protect = TRUE) $this->select[$column] = trim(preg_replace('/(.*)\s+as\s+(\w*)/i', '$1', $val)); } - $this->ci->db->select($columns, $backtick_protect); + $this->builder->select($columns, $backtick_protect); return $this; } @@ -84,7 +77,7 @@ public function select($columns, $backtick_protect = TRUE) public function distinct($column) { $this->distinct = $column; - $this->ci->db->distinct($column); + $this->builder->distinct($column); return $this; } @@ -97,19 +90,20 @@ public function distinct($column) public function group_by($val) { $this->group_by[] = $val; - $this->ci->db->group_by($val); + $this->builder->groupBy($val); return $this; } /** - * Generates the FROM portion of the query + * Generates the TABLE portion of the query * * @param string $table * @return mixed */ - public function from($table) + public function table($table) { - $this->ci->db->from($table); + // $this->builder->table($table); + $this->builder = $this->db->table($table); $this->table = $table; return $this; } @@ -125,7 +119,7 @@ public function from($table) public function join($table, $fk, $type = NULL) { $this->joins[] = array($table, $fk, $type); - $this->ci->db->join($table, $fk, $type); + $this->builder->join($table, $fk, $type); return $this; } @@ -140,7 +134,7 @@ public function join($table, $fk, $type = NULL) public function where($key_condition, $val = NULL, $backtick_protect = TRUE) { $this->where[] = array($key_condition, $val, $backtick_protect); - $this->ci->db->where($key_condition, $val, $backtick_protect); + $this->builder->where($key_condition, $val, $backtick_protect); return $this; } @@ -155,7 +149,7 @@ public function where($key_condition, $val = NULL, $backtick_protect = TRUE) public function or_where($key_condition, $val = NULL, $backtick_protect = TRUE) { $this->or_where[] = array($key_condition, $val, $backtick_protect); - $this->ci->db->or_where($key_condition, $val, $backtick_protect); + $this->builder->orWhere($key_condition, $val, $backtick_protect); return $this; } @@ -170,7 +164,7 @@ public function or_where($key_condition, $val = NULL, $backtick_protect = TRUE) public function where_in($key_condition, $val = NULL) { $this->where_in[] = array($key_condition, $val); - $this->ci->db->where_in($key_condition, $val); + $this->builder->whereIn($key_condition, $val); return $this; } @@ -199,7 +193,7 @@ public function filter($key_condition, $val = NULL, $backtick_protect = TRUE) public function like($key_condition, $val = NULL, $side = 'both') { $this->like[] = array($key_condition, $val, $side); - $this->ci->db->like($key_condition, $val, $side); + $this->builder->like($key_condition, $val, $side); return $this; } @@ -214,7 +208,7 @@ public function like($key_condition, $val = NULL, $side = 'both') public function or_like($key_condition, $val = NULL, $side = 'both') { $this->or_like[] = array($key_condition, $val, $side); - $this->ci->db->or_like($key_condition, $val, $side); + $this->builder->orLike($key_condition, $val, $side); return $this; } @@ -283,11 +277,11 @@ public function generate($output = 'json', $charset = 'UTF-8') */ private function get_paging() { - $iStart = $this->ci->input->post('start'); - $iLength = $this->ci->input->post('length'); + $iStart = $this->request->getPost('start'); + $iLength = $this->request->getPost('length'); if($iLength != '' && $iLength != '-1') - $this->ci->db->limit($iLength, ($iStart)? $iStart : 0); + $this->builder->limit($iLength, ($iStart)? $iStart : 0); } /** @@ -298,15 +292,15 @@ private function get_paging() private function get_ordering() { - $Data = $this->ci->input->post('columns'); + $Data = $this->request->getPost('columns'); - if ($this->ci->input->post('order')) - foreach ($this->ci->input->post('order') as $key) + if ($this->request->getPost('order')) + foreach ($this->request->getPost('order') as $key) if($this->check_cType()) - $this->ci->db->order_by($Data[$key['column']]['data'], $key['dir']); + $this->builder->orderBy($Data[$key['column']]['data'], $key['dir']); else - $this->ci->db->order_by($this->columns[$key['column']] , $key['dir']); + $this->builder->orderBy($this->columns[$key['column']] , $key['dir']); } @@ -318,11 +312,11 @@ private function get_ordering() private function get_filtering() { - $mColArray = $this->ci->input->post('columns'); + $mColArray = $this->request->getPost('columns'); $sWhere = ''; - $search = $this->ci->input->post('search'); - $sSearch = $this->ci->db->escape_like_str(trim($search['value'])); + $search = $this->request->getPost('search'); + $sSearch = trim($search['value']); $columns = array_values(array_diff($this->columns, $this->unset_columns)); if($sSearch != '') @@ -337,12 +331,12 @@ private function get_filtering() $sWhere = substr_replace($sWhere, '', -3); if($sWhere != '') - $this->ci->db->where('(' . $sWhere . ')'); + $this->builder->where('(' . $sWhere . ')'); // TODO : sRangeSeparator foreach($this->filter as $val) - $this->ci->db->where($val[0], $val[1], $val[2]); + $this->builder->where($val[0], $val[1], $val[2]); } /** @@ -352,7 +346,7 @@ private function get_filtering() */ private function get_display_result() { - return $this->ci->db->get(); + return $this->builder->get(); } /** @@ -373,7 +367,7 @@ private function produce_output($output, $charset) $iFilteredTotal = $this->get_total_results(TRUE); } - foreach($rResult->result_array() as $row_key => $row_val) + foreach($rResult->getResultArray() as $row_key => $row_val) { $aaData[$row_key] = ($this->check_cType())? $row_val : array_values($row_val); @@ -399,7 +393,7 @@ private function produce_output($output, $charset) { $sOutput = array ( - 'draw' => intval($this->ci->input->post('draw')), + 'draw' => intval($this->request->getPost('draw')), 'recordsTotal' => $iTotal, 'recordsFiltered' => $iFilteredTotal, 'data' => $aaData @@ -421,40 +415,42 @@ private function produce_output($output, $charset) */ private function get_total_results($filtering = FALSE) { - $this->ci->db->from($this->table); + $this->builder->from($this->table, true); if($filtering) $this->get_filtering(); foreach($this->joins as $val) - $this->ci->db->join($val[0], $val[1], $val[2]); + $this->builder->join($val[0], $val[1], $val[2]); foreach($this->where as $val) - $this->ci->db->where($val[0], $val[1], $val[2]); + $this->builder->where($val[0], $val[1], $val[2]); foreach($this->or_where as $val) - $this->ci->db->or_where($val[0], $val[1], $val[2]); + $this->builder->orWhere($val[0], $val[1], $val[2]); foreach($this->where_in as $val) - $this->ci->db->where_in($val[0], $val[1]); + $this->builder->whereIn($val[0], $val[1]); foreach($this->group_by as $val) - $this->ci->db->group_by($val); + $this->builder->groupBy($val); foreach($this->like as $val) - $this->ci->db->like($val[0], $val[1], $val[2]); + $this->builder->like($val[0], $val[1], $val[2]); foreach($this->or_like as $val) - $this->ci->db->or_like($val[0], $val[1], $val[2]); + $this->builder->orLike($val[0], $val[1], $val[2]); if(strlen($this->distinct) > 0) { - $this->ci->db->distinct(); - $this->ci->db->select($this->select); + $this->builder->distinct(); + $this->builder->select($this->select); } - $query = $this->ci->db->get(NULL, NULL, NULL, FALSE); - return $query->num_rows(); + // echo $this->builder->getCompiledSelect(); die(); + + $query = $this->builder->get(); + return $this->builder->countAll(); } /** @@ -511,7 +507,7 @@ private function exec_replace($custom_val, $row_data) */ private function check_cType() { - $column = $this->ci->input->post('columns'); + $column = $this->request->getPost('columns'); if(is_numeric($column[0]['data'])) return FALSE; else @@ -636,8 +632,6 @@ private function jsonify($result = FALSE) */ public function last_query() { - return $this->ci->db->last_query(); + return $this->builder->last_query(); } } -/* End of file Datatables.php */ -/* Location: ./application/libraries/Datatables.php */ diff --git a/readme.txt b/readme.txt index 2e7d63e..f9f4875 100644 --- a/readme.txt +++ b/readme.txt @@ -1,54 +1,14 @@ -********************** -* Ignited Datatables * -********************** +### Ignited Datatables CodeIgniter 4 +This is was adjusting version for CodeIgniter 4 -Ignited Datatables is a wrapper class/library based on the native Datatables server-side implementation by Allan Jardine -found at http://datatables.net/examples/data_sources/server_side.html for CodeIgniter +Changelog: +- Change "from" method name to "table" -Fork : https://github.com/IgnitedDatatables/Ignited-Datatables -Wiki : https://github.com/IgnitedDatatables/Ignited-Datatables/wiki -Discuss: http://ellislab.com/forums/viewthread/160896/ -Contact: Vincent Bambico - Yusuf Ozdemir +This adjustment is make change how to write the code +For this version, the table method should be called first, like so: -============ -Requirements -============ -jQuery 1.5+ -DataTables 1.10+ -CodeIgniter "Reactor" -======= -Install -======= -To install the library, copy the libraries/datatables.php file into your application/libraries folder. -======= -License -======= -DON'T BE A DICK PUBLIC LICENSE - -Version 1, December 2009 - -Copyright (C) 2009 Philip Sturgeon -Everyone is permitted to copy and distribute verbatim or modified -copies of this license document, and changing it is allowed as long -as the name is changed. - -DON'T BE A DICK PUBLIC LICENSE -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -1. Do whatever you like with the original work, just don't be a dick. - -Being a dick includes - but is not limited to - the following instances: - -1a. Outright copyright infringement - Don't just copy this and change the name. -1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick. -1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick. - -2. If you become rich through modifications, related works/services, or supporting the original work, -share the love. Only a dick would make loads off this work and not buy the original works -creator(s) a pint. - -3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes -you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back. + $dt = new Datatables(); + $dt->table('table_name')->select('id, name'); + return $dt->generate(); From 84f16107361cb465503a63d19cf49e1ef31db6c1 Mon Sep 17 00:00:00 2001 From: Denisa Rachman <27.idea@gmail.com> Date: Wed, 8 Apr 2020 20:17:30 +0700 Subject: [PATCH 3/4] md --- readme.txt => readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename readme.txt => readme.md (100%) diff --git a/readme.txt b/readme.md similarity index 100% rename from readme.txt rename to readme.md From ecf5aa5af8b9a9e27254cf9869f9ae68ac84c8fd Mon Sep 17 00:00:00 2001 From: Denis <27.idea@gmail.com> Date: Wed, 8 Apr 2020 20:21:02 +0700 Subject: [PATCH 4/4] Update readme.md --- readme.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/readme.md b/readme.md index f9f4875..fa2d85f 100644 --- a/readme.md +++ b/readme.md @@ -4,8 +4,7 @@ This is was adjusting version for CodeIgniter 4 Changelog: - Change "from" method name to "table" -This adjustment is make change how to write the code -For this version, the table method should be called first, like so: +This adjustment is make change how to write the code. For this version, the table method should be called first, like so: