From e859d09322a26b59584dd0b79ab2ce3c581dfba9 Mon Sep 17 00:00:00 2001 From: Dave Laszczak Date: Mon, 18 Jul 2016 13:29:58 -0500 Subject: [PATCH] Add a filter param when loading the datatable model to allow for dynamic where clause --- libraries/Datatable.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libraries/Datatable.php b/libraries/Datatable.php index d7f2363..71cb118 100644 --- a/libraries/Datatable.php +++ b/libraries/Datatable.php @@ -48,6 +48,9 @@ class Datatable private $protectIdentifiers = FALSE; + /** Array $filter_array */ + private $filter_array; + /** * @params @@ -63,6 +66,8 @@ public function __construct($params) $model = $params['model']; + $this->filter_array = isset($params['filter']) ? $params['filter'] : NULL; + $this->rowIdCol = isset($params['rowIdCol']) ? $params['rowIdCol'] : NULL; $CI->load->model($model); @@ -415,6 +420,14 @@ private function sqlJoinsAndWhere() //append a static where clause to what the user has filtered, if the model tells us to do so $wArray = $this->model->whereClauseArray(); + + //When loading model, can also define filter as a param + if($this->filter_array !== NULL){ + foreach ($this->filter_array as $key=>$filter){ + $wArray[$key] = $filter; + } + } + if (is_null($wArray) === FALSE && is_array($wArray) === TRUE && count($wArray) > 0) { $this->CI->db->where($wArray, $this->protectIdentifiers); }