diff --git a/app_controller.php b/app_controller.php index d888160..8de4161 100644 --- a/app_controller.php +++ b/app_controller.php @@ -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 : 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 {