From 31a7b6efa188bd66da80d351586dd723f753f367 Mon Sep 17 00:00:00 2001 From: Lincoln Luiz Date: Sun, 31 Jul 2016 10:15:31 -0300 Subject: [PATCH] New method whereOrClauseArray to support clause OR sql updated readme with details on new method --- README.md | 9 +++++++++ libraries/Datatable.php | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 8d198d7..00aa59a 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ Name | Description | Return `fromTableStr` | Specify the table name to select from. *Tip: You can also include an alias here `return 'mytable a';`*| **String ** `joinArray` | Join additional tables for DataTable columns to reference. *Tip: Join Types CAN be specifed by using a pipe in the key value `'table_to_join b|left outer'`*| **Assoc. Array** *Key*=Table To Join *Value*=SQL Join Expression. `whereClauseArray`| Append Static SQL to the generated Where Clause| **Assoc. Array** *Key*= Column Name *Value*=Value To Filter **OR** *NULL* +`whereOrClauseArray`| Append Static SQL to the generated Where OR Clause| **Assoc. Array** *Key*= Column Name *Value*=Value To Filter Methods ---- @@ -132,6 +133,10 @@ Basic DatatableModel Implementation public function whereClauseArray(){ return NULL; + } + + public function whereOrClauseArray(){ + return null; } } ``` @@ -166,6 +171,10 @@ More Advanced DatatableModel Implementation return array( 'u.id' => $this -> ion_auth -> get_user_id() ); + } + + public function whereOrClauseArray(){ + return null; } } ``` diff --git a/libraries/Datatable.php b/libraries/Datatable.php index d7f2363..583d4e7 100644 --- a/libraries/Datatable.php +++ b/libraries/Datatable.php @@ -418,6 +418,12 @@ private function sqlJoinsAndWhere() if (is_null($wArray) === FALSE && is_array($wArray) === TRUE && count($wArray) > 0) { $this->CI->db->where($wArray, $this->protectIdentifiers); } + + //append a static where 'OR' clause to what the user has filtered, if the model tells us to do so + $wOrArray = $this->model->whereOrClauseArray(); + if (is_null($wOrArray) === FALSE && is_array($wOrArray) === TRUE && count($wOrArray) > 0) { + $this->CI->db->or_where($wOrArray, $this->protectIdentifiers); + } return $debug; } @@ -454,6 +460,14 @@ public function joinArray(); * when not filtering by additional criteria */ public function whereClauseArray(); + + /** + * + * @return + * Static where OR clause to be appended to all search queries. Return NULL or empty array + * when not filtering by additional criteria + */ + public function whereOrClauseArray(); } // END Datatable Class