Tweaked filtering to allow for non-trivial conditions
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@431 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -306,8 +306,8 @@ class AppController extends Controller {
|
|||||||
if (empty($params['post']['filter']))
|
if (empty($params['post']['filter']))
|
||||||
return $query;
|
return $query;
|
||||||
|
|
||||||
foreach ($params['post']['filter'] AS $filter => $value) {
|
foreach ($params['post']['filter'] AS $filter => $filter_value) {
|
||||||
$split = $this->gridDataFilterSplit($params, $model, $filter);
|
$split = $this->gridDataFilterSplit($params, $model, $filter, $filter_value);
|
||||||
|
|
||||||
/* pr(array('AppController::gridDataFilterTable' => */
|
/* pr(array('AppController::gridDataFilterTable' => */
|
||||||
/* array('checkpoint' => "Filter split") */
|
/* array('checkpoint' => "Filter split") */
|
||||||
@@ -379,19 +379,16 @@ class AppController extends Controller {
|
|||||||
if (empty($params['post']['filter']))
|
if (empty($params['post']['filter']))
|
||||||
return $conditions;
|
return $conditions;
|
||||||
|
|
||||||
foreach ($params['post']['filter'] AS $filter => $value) {
|
foreach ($params['post']['filter'] AS $filter => $filter_value) {
|
||||||
$split = $this->gridDataFilterSplit($params, $model, $filter);
|
$split = $this->gridDataFilterSplit($params, $model, $filter, $filter_value);
|
||||||
|
|
||||||
$table = $this->gridDataFilterConditionsTable($params, $model, $split['table']);
|
$table = $this->gridDataFilterConditionsTable($params, $model, $split['table']);
|
||||||
if (!$table)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
$key = $this->gridDataFilterConditionsKey($params, $model, $split['table'], $split['field']);
|
$key = $this->gridDataFilterConditionsKey($params, $model, $split['table'], $split['field']);
|
||||||
if (!$key)
|
if (!$key)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$conditions[]
|
$conditions[]
|
||||||
= $this->gridDataFilterConditionsStatement($params, $model, $split['table'], $key, $value);
|
= $this->gridDataFilterConditionsStatement($params, $model, $table, $key, $split['value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $conditions;
|
return $conditions;
|
||||||
@@ -411,24 +408,39 @@ class AppController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function gridDataFilterConditionsStatement(&$params, &$model, $table, $key, $value) {
|
function gridDataFilterConditionsStatement(&$params, &$model, $table, $key, $value) {
|
||||||
return array("{$table}.{$key}" => $value);
|
$key = (empty($table)?"":"{$table}.") . $key;
|
||||||
|
if (isset($value))
|
||||||
|
return array($key => $value);
|
||||||
|
else
|
||||||
|
return array($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function gridDataFilterSplit(&$params, &$model, $filter, $value) {
|
||||||
|
if (!is_string($filter)) {
|
||||||
|
// only a filter condition was set, not filter=>value
|
||||||
|
$filter = $value;
|
||||||
|
$value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function gridDataFilterSplit(&$params, &$model, $filter) {
|
|
||||||
$table = $field = null;
|
$table = $field = null;
|
||||||
if (preg_match("/\./", $filter)) {
|
if (preg_match("/^\w+\.\w+$/", $filter)) {
|
||||||
list($table, $field) = explode(".", $filter);
|
list($table, $field) = explode(".", $filter);
|
||||||
}
|
}
|
||||||
elseif (preg_match('/^[A-Z]/', $filter)) {
|
elseif (preg_match('/^[A-Z][A-Za-z]*$/', $filter)) {
|
||||||
$table = $filter;
|
$table = $filter;
|
||||||
$field = null;
|
$field = null;
|
||||||
}
|
}
|
||||||
else {
|
elseif (preg_match('/^\w+$/', $filter)) {
|
||||||
$table = $model->alias;
|
$table = $model->alias;
|
||||||
$field = $filter;
|
$field = $filter;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// $filter must be a function or other complicated condition
|
||||||
|
$table = null;
|
||||||
|
$field = $filter;
|
||||||
|
}
|
||||||
|
|
||||||
return array('table' => $table, 'field' => $field);
|
return array('table' => $table, 'field' => $field, 'value' => $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function gridDataFilterTableName(&$params, &$model, $table) {
|
function gridDataFilterTableName(&$params, &$model, $table) {
|
||||||
|
|||||||
Reference in New Issue
Block a user