Modified the filtering behavior; A filter specified as 'Table.field' results in the obvious split (Table, field); 'Table' results in (Table, id); 'field' results in (ModelTable, field). Fixed a bug in the app controller which was allowing 'fields' to leak into the top level of 'link'

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@430 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-30 19:45:19 +00:00
parent 07232c77d5
commit 63de30d392
12 changed files with 33 additions and 26 deletions

View File

@@ -309,20 +309,26 @@ class AppController extends Controller {
foreach ($params['post']['filter'] AS $filter => $value) {
$split = $this->gridDataFilterSplit($params, $model, $filter);
/* pr(array('AppController::gridDataFilterTable' => */
/* array('checkpoint' => "Filter split") */
/* + compact('split'))); */
$table = $this->gridDataFilterTablesTable($params, $model, $split['table']);
if (!$table)
continue;
$config = $this->gridDataFilterTablesConfig($params, $model, $split['table']);
/* pr(array('pre-filter-table-config' => */
/* array('query[link]' => $query[$link], */
/* 'config' => $config))); */
/* pr(array('AppController::gridDataFilterTable' => */
/* array('checkpoint' => "Add filter config to query") */
/* + array('query[link]' => $query[$link]) */
/* + compact('config'))); */
// If the table is already part of the query, append to it
if ($table == $model->alias) {
$query[$link] =
array_merge_recursive($config, $query[$link]);
array_merge_recursive(array_diff_key($config, array('fields'=>1)),
$query[$link]);
}
elseif (isset($query[$link][$table])) {
$query[$link][$table] =
@@ -413,13 +419,14 @@ class AppController extends Controller {
if (preg_match("/\./", $filter)) {
list($table, $field) = explode(".", $filter);
}
elseif (preg_match('/^(.*)_(id)$/', $filter, $matches)) {
list($table, $field) = array_slice($matches, 1);
}
else {
elseif (preg_match('/^[A-Z]/', $filter)) {
$table = $filter;
$field = null;
}
else {
$table = $model->alias;
$field = $filter;
}
return array('table' => $table, 'field' => $field);
}

View File

@@ -83,7 +83,7 @@ class LedgerEntriesController extends AppController {
}
function gridDataFilterConditionsStatement(&$params, &$model, $table, $key, $value) {
pr(compact('table', 'key', 'value'));
//pr(compact('table', 'key', 'value'));
if ($table == 'Account' && $value == '-AR-')
$value = $this->LedgerEntry->Ledger->Account->accountReceivableAccountID();
return parent::gridDataFilterConditionsStatement($params, $model, $table, $key, $value);

View File

@@ -66,7 +66,7 @@ echo $this->element('ledgers', array
(// Grid configuration
'config' => array
('caption' => $account['name'] . " Ledgers",
'filter' => array('account_id' => $account['id']),
'filter' => array('Account.id' => $account['id']),
)));
@@ -80,7 +80,7 @@ echo $this->element('ledger_entries', array
('grid_div_id' => 'ledger-ledger-entry-list',
'caption' => ("Current Ledger: " .
"(". $current_ledger['name'] .")"),
'filter' => array('ledger_id' => $current_ledger['id']),
'filter' => array('Ledger.id' => $current_ledger['id']),
'exclude' => array('Account', 'Amount', 'Cr/Dr', 'Balance'),
'include' => array('Debit', 'Credit', 'Sub-Total'),
)));
@@ -97,7 +97,7 @@ echo $this->element('ledger_entries', array
('grid_div_id' => 'account-ledger-entry-list',
'grid_setup' => array('hiddengrid' => true),
'caption' => "Entire Ledger",
'filter' => array('account_id' => $account['id']),
'filter' => array('Account.id' => $account['id']),
'exclude' => array('Account', 'Amount', 'Cr/Dr', 'Balance'),
'include' => array('Debit', 'Credit', 'Sub-Total'),
)));

View File

@@ -134,7 +134,7 @@ echo $this->element('customers', array
(// Grid configuration
'config' => array
('caption' => 'Related Customers',
'filter' => array('contact_id' => $contact['id']),
'filter' => array('Contact.id' => $contact['id']),
)));

View File

@@ -13,7 +13,7 @@ $cols['Comment'] = array('index' => 'Customer.comment', 'formatt
// Certain fields are only valid with a particular context
if (!isset($config['filter']['contact_id']) && !isset($config['filter']['Contact.id']))
if (!isset($config['filter']['Contact.id']))
$grid->invalidFields('Relationship');
// Render the grid

View File

@@ -85,7 +85,7 @@ echo $this->element('statement_entries', array
(// Grid configuration
'config' => array
('caption' => 'Account',
'filter' => array('lease_id' => $lease['id']),
'filter' => array('Lease.id' => $lease['id']),
'include' => array('Through'),
'exclude' => array('Customer', 'Lease', 'Unit'),
)));

View File

@@ -69,7 +69,7 @@ echo $this->element('ledger_entries', array
(// Grid configuration
'config' => array
('caption' => "Ledger Entries",
'filter' => array('ledger_id' => $ledger['id']),
'filter' => array('Ledger.id' => $ledger['id']),
'exclude' => array('Ledger', 'Account', 'Amount', 'Cr/Dr', 'Balance'),
'include' => array('Debit', 'Credit', 'Sub-Total'),
)));

View File

@@ -111,7 +111,7 @@ echo $this->element('statement_entries', array
// Grid configuration
'config' => array
('caption' => 'Entries Applied',
//'filter' => array('statement_entry_id' => $entry['id']),
//'filter' => array('id' => $entry['id']),
'exclude' => array('Entry'),
)));

View File

@@ -63,8 +63,8 @@ foreach ($depositTypes AS $type) {
'grid_setup' => array('hiddengrid' => true),
'caption' => ('<A HREF="#" ONCLICK="$(\'#'.$grid_div_id.' .HeaderButton\').click();'.
' return false;">Items in '.$type['name'].' Ledger</A>'),
'filter' => array('Tender.deposit_transaction_id' => null,
'Tender.tender_type_id' => $type['id']),
'filter' => array('deposit_transaction_id' => null,
'TenderType.id' => $type['id']),
'exclude' => array('Type'),
),
));

View File

@@ -88,7 +88,7 @@ echo $this->element('ledger_entries', array
(// Grid configuration
'config' => array
('caption' => "Ledger Entries",
'filter' => array('tender_id' => $tender['id']),
'filter' => array('Tender.id' => $tender['id']),
'exclude' => array('Tender'),
)));

View File

@@ -42,9 +42,9 @@ if (0) {
(
'grid_div_id' => "tenders-{$type['id']}-list",
'caption' => $type['name'] . ' Items',
'filter' => array('Tender.deposit_transaction_id'
'filter' => array('deposit_transaction_id'
=> $deposit['Transaction']['id'],
'Tender.tender_type_id'
'TenderType.id'
=> $type['id'],
),
'exclude' => array('Type'),
@@ -57,7 +57,7 @@ else {
'config' => array
(
'caption' => 'Deposited Items',
'filter' => array('Tender.deposit_transaction_id'
'filter' => array('deposit_transaction_id'
=> $deposit['Transaction']['id'],
),
)));

View File

@@ -73,7 +73,7 @@ if ($transaction['type'] === 'INVOICE' || $transaction['type'] === 'RECEIPT') {
'config' => array
(
'caption' => 'Statement Entries',
'filter' => array('transaction_id' => $transaction['id']),
'filter' => array('Transaction.id' => $transaction['id']),
'exclude' => array('Transaction'),
)));
}
@@ -88,7 +88,7 @@ echo $this->element('ledger_entries', array
'config' => array
(
'caption' => 'Ledger Entries',
'filter' => array('transaction_id' => $transaction['id'],
'filter' => array('Transaction.id' => $transaction['id'],
'Account.id !=' => $account['id']),
'exclude' => array('Transaction'),
)));
@@ -104,7 +104,7 @@ echo $this->element('ledger_entries', array
/* 'config' => array */
/* ( */
/* 'caption' => 'Deposited Items', */
/* 'filter' => array('Tender.deposit_transaction_id' => $transaction['id']), */
/* 'filter' => array('deposit_transaction_id' => $transaction['id']), */
/* ))); */
/* } */