Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down Expand Up @@ -132,6 +133,10 @@ Basic DatatableModel Implementation

public function whereClauseArray(){
return NULL;
}

public function whereOrClauseArray(){
return null;
}
}
```
Expand Down Expand Up @@ -166,6 +171,10 @@ More Advanced DatatableModel Implementation
return array(
'u.id' => $this -> ion_auth -> get_user_id()
);
}

public function whereOrClauseArray(){
return null;
}
}
```
Expand Down
14 changes: 14 additions & 0 deletions libraries/Datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down