From a73f5c31f252565cf8d696585b695c07d1c26b90 Mon Sep 17 00:00:00 2001 From: Anyelo Date: Mon, 10 Feb 2014 03:38:41 +0100 Subject: [PATCH] Update Component for check if a query exists. To avoid the undefined index notice. --- src/DataTableComponent.php | 46 ++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/DataTableComponent.php b/src/DataTableComponent.php index dabbadf..3dd6615 100644 --- a/src/DataTableComponent.php +++ b/src/DataTableComponent.php @@ -208,37 +208,39 @@ private function getWhereConditions(){ foreach($fields as $x => $column){ // only create conditions on bSearchable fields - if( $this->controller->request->query['bSearchable_'.$x] == 'true' ){ + if (isset($this->controller->request->query['bSearchable_'.$x])) { // check if the parameter exists in query. + if( $this->controller->request->query['bSearchable_'.$x] == 'true' ){ - list($table, $field) = explode('.', $column); - - // attempt using definitions in $model->validate to build intelligent conditions - if( $this->conditionsByValidate == 1 && array_key_exists($column,$this->model->validate) ){ + list($table, $field) = explode('.', $column); + + // attempt using definitions in $model->validate to build intelligent conditions + if( $this->conditionsByValidate == 1 && array_key_exists($column,$this->model->validate) ){ - if( !empty($this->controller->paginate['contain']) ){ - if(array_key_exists($table, $this->controller->paginate['contain']) && in_array($field, $this->controller->paginate['contain'][$table]['fields'])){ - $conditions[$table]['conditions'][] = $this->conditionByDataType($column); + if( !empty($this->controller->paginate['contain']) ){ + if(array_key_exists($table, $this->controller->paginate['contain']) && in_array($field, $this->controller->paginate['contain'][$table]['fields'])){ + $conditions[$table]['conditions'][] = $this->conditionByDataType($column); + } + } + else{ + $conditions['OR'][] = $this->conditionByDataType($column); } } else{ - $conditions['OR'][] = $this->conditionByDataType($column); - } - } - else{ - - if( !empty($this->controller->paginate['contain']) ){ + + if( !empty($this->controller->paginate['contain']) ){ - if(array_key_exists($table, $this->controller->paginate['contain']) && in_array($field, $this->controller->paginate['contain'][$table]['fields'])){ - $conditions[$table]['conditions'][] = $column.' LIKE "%'.$this->controller->request->query['sSearch'].'%"'; + if(array_key_exists($table, $this->controller->paginate['contain']) && in_array($field, $this->controller->paginate['contain'][$table]['fields'])){ + $conditions[$table]['conditions'][] = $column.' LIKE "%'.$this->controller->request->query['sSearch'].'%"'; + } + } + else{ + $conditions['OR'][] = array( + $column.' LIKE' => '%'.$this->controller->request->query['sSearch'].'%' + ); } - } - else{ - $conditions['OR'][] = array( - $column.' LIKE' => '%'.$this->controller->request->query['sSearch'].'%' - ); } } - } + } } return $conditions; }