Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flexigrid/bootstrap theme -> WHERE clause AND (search term_n OR search term_n+1...etc.), not OR #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
set_ajax_list_queries AND where
Modification of set_ajax_list_queries function in grocery_CRUD_Model_Driver to ensure that the WHERE clause set in the controller is taken as an AND condition, in combination with the query terms flexigrid/bootstrap theme sends as ajax request.

It is to fix the unexpected behaviour that, when you set the where clause in the controller (for example to only show records for a specific user) and enter some search terms in the flexigrid/bootstrap theme table, records are shown outside of the WHERE clause.

I believe this modification results is the behaviour that is more expected of grocery crud.
  • Loading branch information
Pimnr47 authored Jul 9, 2017
commit 25399f293de33158828dabf6c4c07a696922a448
49 changes: 25 additions & 24 deletions application/libraries/Grocery_CRUD.php
Original file line number Diff line number Diff line change
@@ -636,31 +636,32 @@ protected function set_ajax_list_queries($state_info = null)
foreach($this->where as $where)
$this->basic_model->having($where[0],$where[1],$where[2]);

foreach($columns as $column)
{
if(isset($temp_relation[$column->field_name]))
{
if(is_array($temp_relation[$column->field_name]))
{
foreach($temp_relation[$column->field_name] as $search_field)
{
$this->or_like($search_field, $search_text);
}
}
else
{
$this->or_like($temp_relation[$column->field_name], $search_text);
}
}
elseif(isset($this->relation_n_n[$column->field_name]))
{
//@todo have a where for the relation_n_n statement
}
elseif (isset($field_types[$column->field_name])
&& !in_array($field_types[$column->field_name]->type, array('date', 'datetime', 'timestamp')))
{
$this->or_like($column->field_name, $search_text);
$likes = array();

foreach ($columns as $column) {
if (isset($temp_relation[$column->field_name])) {
if (is_array($temp_relation[$column->field_name])) {
foreach ($temp_relation[$column->field_name] as $search_field) {
$likes[$search_field] = $search_text;
}
} else {
$likes[$temp_relation[$column->field_name]] = $search_text;
}
} elseif (isset($this->relation_n_n[$column->field_name])) {
//@todo have a where for the relation_n_n statement
} else {
$likes[$column->field_name] = $search_text;
}
}

$where_clause = "";
foreach ($likes as $field => $search_text) {
$where_clause = $where_clause. " OR ".$field. " LIKE '%".$this->basic_model->escape_like_str($search_text)."%' ESCAPE '!'";
}

if(sizeof($likes)>0){
$where_clause = "(".substr($where_clause, 4).")";
$this->basic_model->where($where_clause);
}
}
}