diff --git a/app_controller.php b/app_controller.php index 2b16f7a..ccbddce 100644 --- a/app_controller.php +++ b/app_controller.php @@ -307,22 +307,13 @@ class AppController extends Controller { return $query; foreach ($params['post']['filter'] AS $filter => $value) { - if (preg_match("/\./", $filter)) { - list($tbl, $id) = explode(".", $filter); - } - elseif (preg_match('/^(.*)_(id)$/', $filter, $matches)) { - list($tbl, $id) = array_slice($matches, 1); - } - else { - $tbl = $filter; - $id = null; - } + $split = $this->gridDataFilterSplit($params, $model, $filter); - $table = $this->gridDataFilterTablesTable($params, $model, $tbl); + $table = $this->gridDataFilterTablesTable($params, $model, $split['table']); if (!$table) continue; - $config = $this->gridDataFilterTablesConfig($params, $model, $tbl); + $config = $this->gridDataFilterTablesConfig($params, $model, $split['table']); /* pr(array('pre-filter-table-config' => */ /* array('query[link]' => $query[$link], */ @@ -383,27 +374,18 @@ class AppController extends Controller { return $conditions; foreach ($params['post']['filter'] AS $filter => $value) { - if (preg_match("/\./", $filter)) { - list($tbl, $id) = explode(".", $filter); - } - elseif (preg_match('/^(.*)_(id)$/', $filter, $matches)) { - list($tbl, $id) = array_slice($matches, 1); - } - else { - $tbl = $filter; - $id = null; - } + $split = $this->gridDataFilterSplit($params, $model, $filter); - $table = $this->gridDataFilterConditionsTable($params, $model, $tbl); + $table = $this->gridDataFilterConditionsTable($params, $model, $split['table']); if (!$table) continue; - $key = $this->gridDataFilterConditionsKey($params, $model, $tbl, $id); + $key = $this->gridDataFilterConditionsKey($params, $model, $split['table'], $split['field']); if (!$key) continue; $conditions[] - = $this->gridDataFilterConditionsStatement($params, $model, $tbl, $key, $value); + = $this->gridDataFilterConditionsStatement($params, $model, $split['table'], $key, $value); } return $conditions; @@ -426,6 +408,22 @@ class AppController extends Controller { return array("{$table}.{$key}" => $value); } + function gridDataFilterSplit(&$params, &$model, $filter) { + $table = $field = null; + if (preg_match("/\./", $filter)) { + list($table, $field) = explode(".", $filter); + } + elseif (preg_match('/^(.*)_(id)$/', $filter, $matches)) { + list($table, $field) = array_slice($matches, 1); + } + else { + $table = $filter; + $field = null; + } + + return array('table' => $table, 'field' => $field); + } + function gridDataFilterTableName(&$params, &$model, $table) { return Inflector::camelize($table); }