Modified Filtering to have a separate virtual function for Tables and Conditions. This was prompted because a derived controller could override the function to return null to prevent adding a filtering table (such as if the table was already added as a non top-level table), and although the app controller would correctly prevent adding the filter table to the set, it would also prevent adding the filter condition as well. So, making two virtual functions, one for table name when defining filter tables, and one for table name when defining filter conditions, allows the derived controller to stop a table from being added to the set, yet still let the condition through (without having to override the entire filter condition logic).

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@370 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-23 16:51:32 +00:00
parent f8c60ec265
commit 9dccbfeda8

View File

@@ -308,21 +308,29 @@ class AppController extends Controller {
$id = null;
}
$table = $this->gridDataFilterTable($params, $model, $tbl);
$table = $this->gridDataFilterTablesTable($params, $model, $tbl);
if (!$table || $table == $model->alias)
continue;
// If the table is already part of the query, don't replace it
if (isset($query[$link][$table]))
if (isset($query[$link][$table]) || in_array($table, $query[$link]))
continue;
$query[$link][$table]
= $this->gridDataFilterTableConfig($params, $model, $table);
= $this->gridDataFilterTablesConfig($params, $model, $table);
}
return $query;
}
function gridDataFilterTablesTable(&$params, &$model, $table) {
return $this->gridDataFilterTableName($params, $model, $table);
}
function gridDataFilterTablesConfig(&$params, &$model, $table) {
return array('fields' => array());
}
function gridDataFilterConditions(&$params, &$model, $conditions) {
if (empty($params['post']['filter']))
return $conditions;
@@ -339,30 +347,26 @@ class AppController extends Controller {
$id = null;
}
$table = $this->gridDataFilterTable($params, $model, $tbl);
$table = $this->gridDataFilterConditionsTable($params, $model, $tbl);
if (!$table)
continue;
$key = $this->gridDataFilterTableKey($params, $model, $table, $id);
$key = $this->gridDataFilterConditionsKey($params, $model, $table, $id);
if (!$key)
continue;
$conditions[]
= $this->gridDataFilterTableCondition($params, $model, $table, $key, $value);
= $this->gridDataFilterConditionsStatement($params, $model, $table, $key, $value);
}
return $conditions;
}
function gridDataFilterTable(&$params, &$model, $table) {
return Inflector::camelize($table);
function gridDataFilterConditionsTable(&$params, &$model, $table) {
return $this->gridDataFilterTableName($params, $model, $table);
}
function gridDataFilterTableConfig(&$params, &$model, $table) {
return array('fields' => array());
}
function gridDataFilterTableKey(&$params, &$model, $table, $id) {
function gridDataFilterConditionsKey(&$params, &$model, $table, $id) {
// REVISIT <AP>: 20090722
// When $id is null, we could instantiate the table,
// and use the _actual_ primary key. However, I don't
@@ -371,10 +375,14 @@ class AppController extends Controller {
return $id ? $id : 'id';
}
function gridDataFilterTableCondition(&$params, &$model, $table, $key, $value) {
function gridDataFilterConditionsStatement(&$params, &$model, $table, $key, $value) {
return array("{$table}.{$key}" => $value);
}
function gridDataFilterTableName(&$params, &$model, $table) {
return Inflector::camelize($table);
}
/**************************************************************************
**************************************************************************
@@ -697,6 +705,7 @@ class AppController extends Controller {
function gridDataOutputRecordField(&$params, &$model, &$record, $field) {
if (preg_match("/\./", $field)) {
list($tbl, $col) = explode(".", $field);
//pr(compact('record', 'field', 'tbl', 'col'));
$data = $record[$tbl][$col];
}
else {