Renamed jqGridData functions to be just gridData. Restructured the virtual function calls with an anticipated need for gridDataCount to be overridden as a whole, instead of just overriding the individual pieces.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@361 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-22 17:06:44 +00:00
parent 93ebc450fe
commit 7aa026f4e0
13 changed files with 391 additions and 279 deletions

View File

@@ -84,103 +84,83 @@ class AppController extends Controller {
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* helper: jqGridView * helper: gridView
* - called by function to create an index listing * - called by derived controllers to create an index listing
*/ */
function jqGridView($title, $action = null, $element = null) { function gridView($title, $action = null, $element = null) {
$this->set('title', $title); $this->set('title', $title);
// The resulting page will contain a jqGrid, which will // The resulting page will contain a grid, which will
// use ajax to obtain the actual data for this action // use ajax to obtain the actual data for this action
$this->set('action', $action ? $action : $this->params['action']); $this->set('action', $action ? $action : $this->params['action']);
$this->render('/elements/' . ($element ? $element : $this->params['controller'])); $this->render('/elements/' . ($element ? $element : $this->params['controller']));
} }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* action: jqGridData **************************************************************************
* - Fetches the actual data requested by jqGrid as XML **************************************************************************
* action: gridData
* - Fetches the actual data requested by grid as XML
*/ */
function jqGridData() { function gridData() {
// Grab a copy of the parameters that control this request // Grab a copy of the parameters that control this request
$params = array(); $params = array();
if (isset($this->params['url']) && is_array($this->params['url'])) if (isset($this->params['url']) && is_array($this->params['url']))
$params = $this->params['url']; $params = $this->params['url'];
// Do any preliminary setup necessary // Do any preliminary setup necessary
$this->jqGridDataSetup($params); $this->gridDataSetup($params);
// Get the top level model for this grid // Get the top level model for this grid
$model = $this->jqGridDataModel($params); $model = $this->gridDataModel($params);
// Establish the basic query and conditions
$query = array_intersect_key($this->jqGridDataCountTables($params, $model),
array('link'=>1, 'contain'=>1));
$query['conditions'] = $this->jqGridDataCountConditions($params, $model);
$query['group'] = $this->jqGridDataCountGroup($params, $model);
// DEBUG PURPOSES ONLY!
$params['count_query'] = $query;
// Get the number of records prior to pagination // Get the number of records prior to pagination
$count = $this->jqGridDataRecordCount($params, $model, $query); $count = $this->gridDataCount($params, $model);
// Start the query over, this time getting the actual set // Determine pagination configuration (and save to $params)
// of tables needed, not just those needed for counting. $pagination = $this->gridDataPagination($params, $model, $count);
$query = array_intersect_key($this->jqGridDataTables($params, $model),
array('link'=>1, 'contain'=>1));
$query['conditions'] = $this->jqGridDataConditions($params, $model);
// Verify a few parameters and determine our starting row // Retreive the appropriate subset of data
$limit = $params['rows']; $records = $this->gridDataRecords($params, $model, $pagination);
$total = ($count < 0) ? 0 : ceil($count/$limit);
$page = ($params['page'] <= 1) ? 1 : (($params['page'] > $total) ? $total : $params['page']);
$start = $limit*$page - $limit;
// Grab the actual records taking pagination into account
$query['group'] = $this->jqGridDataGroup($params, $model);
$query['order'] = $this->jqGridDataOrder($params, $model,
isset($params['sidx']) ? $params['sidx'] : null,
isset($params['sord']) ? $params['sord'] : null);
$query['limit'] = $this->jqGridDataLimit($params, $model, $start, $limit);
$query['fields'] = $this->jqGridDataFields($params, $model);
$results = $this->jqGridDataRecords($params, $model, $query);
// DEBUG PURPOSES ONLY!
$params['query'] = $query;
// Post process the records // Post process the records
$this->jqGridRecordsPostProcess($params, $model, $results); $this->gridDataPostProcess($params, $model, $records);
// Add in any needed hyperlinks // Output the resulting record set
$this->jqGridRecordLinks($params, $model, $results, array()); $this->gridDataOutput($params, $model, $records, $pagination);
// Finally, dump out the data
$this->jqGridDataOutputHeader($params, $model);
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<rows>\n";
$this->jqGridDataOutputSummary($params, $model, $page, $total, $count);
$this->jqGridDataOutputRecords($params, $model, $results);
echo "</rows>\n";
// Call out to finalize everything // Call out to finalize everything
$this->jqGridDataFinalize($params); $this->gridDataFinalize($params);
} }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtual: jqGridData* functions **************************************************************************
* - These set up the context for the jqGrid data, and will **************************************************************************
* virtual: gridData* functions
* - These set up the context for the grid data, and will
* need to be overridden in the derived class for anything * need to be overridden in the derived class for anything
* other than the most basic of grids. * other than the most basic of grids.
*/ */
function jqGridDataSetup(&$params) { /**************************************************************************
**************************************************************************
**************************************************************************
* gridData SETUP / CLEANUP
*/
function gridDataModel(&$params) {
return $this->{$this->modelClass};
}
function gridDataSetup(&$params) {
// Assume we're debugging. // Assume we're debugging.
// The actual jqGrid request will set this to false // The actual grid request will set this to false
$debug = true; $debug = true;
if (isset($this->passedArgs['debug'])) if (isset($this->passedArgs['debug']))
@@ -188,7 +168,10 @@ class AppController extends Controller {
$params['debug'] = $debug; $params['debug'] = $debug;
if (!$debug) { if ($debug) {
ob_start();
}
else {
$this->layout = null; $this->layout = null;
$this->autoLayout = false; $this->autoLayout = false;
$this->autoRender = false; $this->autoRender = false;
@@ -224,25 +207,117 @@ class AppController extends Controller {
$params['action'] = null; $params['action'] = null;
} }
function jqGridDataModel(&$params) { function gridDataFinalize(&$params) {
return $this->{$this->modelClass}; if ($params['debug']) {
$xml = ob_get_contents();
ob_end_clean();
$xml = preg_replace("/&/", "&amp;", $xml);
$xml = preg_replace("/</", "&lt;", $xml);
$xml = preg_replace("/>/", "&gt;", $xml);
echo ("\n<PRE>\n$xml\n</PRE>\n");
}
} }
function jqGridDataCountTables(&$params, &$model) { /**************************************************************************
// If not overridden, we use the same tables to **************************************************************************
// perform our count as we do to for the actual query **************************************************************************
return $this->jqGridDataTables($params, $model); * gridData COUNTING
*/
function gridDataCount(&$params, &$model) {
// Establish the tables and conditions for counting
$query = array_intersect_key($this->gridDataCountTables($params, $model),
array('link'=>1, 'contain'=>1));
// Add in the conditions and grouping
$query['conditions'] = $this->gridDataCountConditions($params, $model);
$query['group'] = $this->gridDataCountGroup($params, $model);
// DEBUG PURPOSES ONLY!
$params['count_query'] = $query;
// Get the number of records prior to pagination
return $this->gridDataCountExecute($params, $model, $query);
} }
function jqGridDataTables(&$params, &$model) { function gridDataCountExecute(&$params, &$model, $query) {
return $model->find('count', $query);
}
function gridDataCountTables(&$params, &$model) {
// Same tables for counting as for retreiving
return $this->gridDataTables($params, $model);
}
function gridDataCountConditions(&$params, &$model) {
// Same conditions for counting as for retreiving
return $this->gridDataConditions($params, $model);
}
function gridDataCountGroup(&$params, &$model) {
// Grouping will screw up the count, since it
// causes the results to be split into chunks
// based on the GROUP BY clause. We can't have
// more than one row of data in the count query,
// just a _single_ row with the actual count.
return null;
}
/**************************************************************************
**************************************************************************
* gridData PAGINATION
*/
function gridDataPagination(&$params, &$model, $record_count) {
// Retrieve, or calculate, all parameters necesssary for
// pagination. Verify the passed in parameters are valid.
$limit = $params['rows'] > 0 ? $params['rows'] : 10;
$total = ($record_count < 0) ? 0 : ceil($record_count/$limit);
$page = ($params['page'] <= 1) ? 1 : (($params['page'] > $total) ? $total : $params['page']);
$start = $limit * ($page - 1);
return compact('record_count', 'limit', 'page', 'start', 'total');
}
/**************************************************************************
**************************************************************************
* gridData RETREIVAL
*/
function gridDataRecords(&$params, &$model, $pagination) {
// Establish the tables for this query
$query = array_intersect_key($this->gridDataTables($params, $model),
array('link'=>1, 'contain'=>1));
// Add in the conditions and grouping
$query['conditions'] = $this->gridDataConditions($params, $model);
$query['group'] = $this->gridDataGroup($params, $model);
// Grab the actual records taking pagination into account
$query['order'] = $this->gridDataOrder($params, $model,
isset($params['sidx']) ? $params['sidx'] : null,
isset($params['sord']) ? $params['sord'] : null);
$query['limit'] = $this->gridDataLimit($params, $model, $pagination['start'], $pagination['limit']);
$query['fields'] = $this->gridDataFields($params, $model);
// DEBUG PURPOSES ONLY!
$params['query'] = $query;
return $this->gridDataRecordsExecute($params, $model, $query);
}
function gridDataRecordsExecute(&$params, &$model, $query) {
return $model->find('all', $query);
}
function gridDataTables(&$params, &$model) {
return array('contain' => false); return array('contain' => false);
} }
function jqGridDataCountConditions(&$params, &$model) { function gridDataConditions(&$params, &$model) {
return $this->jqGridDataConditions($params, $model);
}
function jqGridDataConditions(&$params, &$model) {
$searches = array(); $searches = array();
if (isset($params['_search']) && $params['_search'] === 'true') { if (isset($params['_search']) && $params['_search'] === 'true') {
@@ -293,38 +368,73 @@ class AppController extends Controller {
return $conditions; return $conditions;
} }
function jqGridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
return null; return null;
} }
function jqGridDataCountGroup(&$params, &$model) { function gridDataGroup(&$params, &$model) {
return null;
}
function jqGridDataGroup(&$params, &$model) {
return $model->alias.'.'.$model->primaryKey; return $model->alias.'.'.$model->primaryKey;
} }
function jqGridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
return $index ? array($index .' '. $direction) : null; return $index ? array($index .' '. $direction) : null;
} }
function jqGridDataLimit(&$params, &$model, $start, $limit) { function gridDataLimit(&$params, &$model, $start, $limit) {
return $start . ', ' . $limit; return $start . ', ' . $limit;
} }
function jqGridDataRecordCount(&$params, &$model, $query) {
return $model->find('count', $query); /**************************************************************************
**************************************************************************
* gridData POST PROCESSING
*/
function gridDataPostProcess(&$params, &$model, &$records) {
// Add grid IDs to each record
$this->gridDataPostProcessGridIDs($params, $model, $records);
// Add the calculated fields (if any), to the model fields
$this->gridDataPostProcessCalculatedFields($params, $model, $records);
// Perform any requested subtotaling of fields
$this->gridDataPostProcessSubtotal($params, $model, $records);
// Add in any needed hyperlinks
$this->gridDataPostProcessLinks($params, $model, $records, array());
// DEBUG PURPOSES ONLY!
//$params['records'] = $records;
} }
function jqGridDataRecords(&$params, &$model, $query) { function gridDataPostProcessGridIDs(&$params, &$model, &$records) {
return $model->find('all', $query);
}
function jqGridRecordsPostProcess(&$params, &$model, &$records) {
$model_alias = $model->alias; $model_alias = $model->alias;
$id = $model->primaryKey; $id = $model->primaryKey;
foreach ($records AS &$record) {
$record['grid_id'] = $record[$model_alias][$id];
}
}
function gridDataPostProcessCalculatedFields(&$params, &$model, &$records) {
$model_alias = $model->alias;
foreach ($records AS &$record) {
// Add the calculated fields (if any), to the model fields
if (isset($record[0])) {
$record[$model_alias] += $record[0];
unset($record[0]);
}
}
}
function gridDataPostProcessSubtotal(&$params, &$model, &$records) {
$model_alias = $model->alias;
// REVISIT <AP>: 20090722
// Horrible solution to something that should be done
// in SQL. But, it works for now, so what the heck...
$subtotals = array(); $subtotals = array();
foreach ($params['fields'] AS $field) { foreach ($params['fields'] AS $field) {
if (preg_match('/subtotal-(.*)$/', $field, $matches)) if (preg_match('/subtotal-(.*)$/', $field, $matches))
@@ -334,13 +444,6 @@ class AppController extends Controller {
} }
foreach ($records AS &$record) { foreach ($records AS &$record) {
$record['jqGrid_id'] = $record[$model_alias][$id];
// Add the calculated fields (if any), to the model fields
if (isset($record[0])) {
$record[$model_alias] += $record[0];
unset($record[0]);
}
foreach ($subtotals AS &$subtotal) { foreach ($subtotals AS &$subtotal) {
$field = $subtotal['field']; $field = $subtotal['field'];
if (preg_match("/\./", $field)) { if (preg_match("/\./", $field)) {
@@ -354,12 +457,9 @@ class AppController extends Controller {
} }
} }
} }
// DEBUG PURPOSES ONLY!
//$params['records'] = $records;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
// Don't create any links if ordered not to. // Don't create any links if ordered not to.
if (isset($params['nolinks'])) if (isset($params['nolinks']))
return; return;
@@ -392,20 +492,44 @@ class AppController extends Controller {
} }
} }
function jqGridDataOutputHeader(&$params, &$model) {
if ($params['debug']) { /**************************************************************************
ob_start(); **************************************************************************
} * gridData OUTPUT
else { */
function gridDataOutput(&$params, &$model, &$records, $pagination) {
$this->gridDataOutputHeader($params, $model);
$this->gridDataOutputXMLHeader($params, $model);
$this->gridDataOutputRootNodeBegin($params, $model);
$this->gridDataOutputSummary($params, $model, $pagination);
$this->gridDataOutputRecords($params, $model, $records);
$this->gridDataOutputRootNodeEnd($params, $model);
}
function gridDataOutputHeader(&$params, &$model) {
if (!$params['debug']) {
header("Content-type: text/xml;charset=utf-8"); header("Content-type: text/xml;charset=utf-8");
} }
} }
function jqGridDataOutputSummary(&$params, &$model, $page, $total, $records) { function gridDataOutputXMLHeader(&$params, &$model) {
echo "<?xml version='1.0' encoding='utf-8'?>\n";
}
function gridDataOutputRootNodeBegin(&$params, &$model) {
echo "<rows>\n";
}
function gridDataOutputRootNodeEnd(&$params, &$model) {
echo "</rows>\n";
}
function gridDataOutputSummary(&$params, &$model, $pagination) {
echo " <params><![CDATA[\n" . print_r($params, true) . "\n]]></params>\n"; echo " <params><![CDATA[\n" . print_r($params, true) . "\n]]></params>\n";
echo " <page>$page</page>\n"; echo " <page>{$pagination['page']}</page>\n";
echo " <total>$total</total>\n"; echo " <total>{$pagination['total']}</total>\n";
echo " <records>$records</records>\n"; echo " <records>{$pagination['record_count']}</records>\n";
if (isset($params['userdata'])) { if (isset($params['userdata'])) {
foreach ($params['userdata'] AS $field => $value) foreach ($params['userdata'] AS $field => $value)
@@ -413,23 +537,23 @@ class AppController extends Controller {
} }
} }
function jqGridDataOutputRecords(&$params, &$model, &$records) { function gridDataOutputRecords(&$params, &$model, &$records) {
$id_field = 'jqGrid_id'; $id_field = 'grid_id';
foreach ($records AS $record) { foreach ($records AS $record) {
$this->jqGridDataOutputRecord($params, $model, $record, $this->gridDataOutputRecord($params, $model, $record,
$record[$id_field], $params['fields']); $record[$id_field], $params['fields']);
} }
} }
function jqGridDataOutputRecord(&$params, &$model, &$record, $id, $fields) { function gridDataOutputRecord(&$params, &$model, &$record, $id, $fields) {
echo " <row id='$id'>\n"; echo " <row id='$id'>\n";
foreach ($fields AS $field) { foreach ($fields AS $field) {
$this->jqGridDataOutputRecordField($params, $model, $record, $field); $this->gridDataOutputRecordField($params, $model, $record, $field);
} }
echo " </row>\n"; echo " </row>\n";
} }
function jqGridDataOutputRecordField(&$params, &$model, &$record, $field) { function gridDataOutputRecordField(&$params, &$model, &$record, $field) {
if (preg_match("/\./", $field)) { if (preg_match("/\./", $field)) {
list($tbl, $col) = explode(".", $field); list($tbl, $col) = explode(".", $field);
$data = $record[$tbl][$col]; $data = $record[$tbl][$col];
@@ -437,10 +561,10 @@ class AppController extends Controller {
else { else {
$data = $record[$model->alias][$field]; $data = $record[$model->alias][$field];
} }
$this->jqGridDataOutputRecordCell($params, $model, $record, $field, $data); $this->gridDataOutputRecordCell($params, $model, $record, $field, $data);
} }
function jqGridDataOutputRecordCell(&$params, &$model, &$record, $field, $data) { function gridDataOutputRecordCell(&$params, &$model, &$record, $field, $data) {
// be sure to put text data in CDATA // be sure to put text data in CDATA
if (preg_match("/^\d*$/", $data)) if (preg_match("/^\d*$/", $data))
echo " <cell>$data</cell>\n"; echo " <cell>$data</cell>\n";
@@ -448,17 +572,5 @@ class AppController extends Controller {
echo " <cell><![CDATA[$data]]></cell>\n"; echo " <cell><![CDATA[$data]]></cell>\n";
} }
function jqGridDataFinalize(&$params) {
if ($params['debug']) {
$xml = ob_get_contents();
ob_end_clean();
$xml = preg_replace("/&/", "&amp;", $xml);
$xml = preg_replace("/</", "&lt;", $xml);
$xml = preg_replace("/>/", "&gt;", $xml);
echo ("\n<PRE>\n$xml\n</PRE>\n");
}
}
} }
?> ?>

View File

@@ -35,34 +35,34 @@ class AccountsController extends AppController {
*/ */
function index() { $this->all(); } function index() { $this->all(); }
function asset() { $this->jqGridView('Asset Accounts'); } function asset() { $this->gridView('Asset Accounts'); }
function liability() { $this->jqGridView('Liability Accounts'); } function liability() { $this->gridView('Liability Accounts'); }
function equity() { $this->jqGridView('Equity Accounts'); } function equity() { $this->gridView('Equity Accounts'); }
function income() { $this->jqGridView('Income Accounts'); } function income() { $this->gridView('Income Accounts'); }
function expense() { $this->jqGridView('Expense Accounts'); } function expense() { $this->gridView('Expense Accounts'); }
function all() { $this->jqGridView('All Accounts', 'all'); } function all() { $this->gridView('All Accounts', 'all'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataSetup(&$params) { function gridDataSetup(&$params) {
parent::jqGridDataSetup($params); parent::gridDataSetup($params);
if (!isset($params['action'])) if (!isset($params['action']))
$params['action'] = 'all'; $params['action'] = 'all';
} }
function jqGridDataCountTables(&$params, &$model) { function gridDataCountTables(&$params, &$model) {
return parent::jqGridDataTables($params, $model); return parent::gridDataTables($params, $model);
} }
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
return array return array
('link' => ('link' =>
array(// Models array(// Models
@@ -74,13 +74,13 @@ class AccountsController extends AppController {
); );
} }
function jqGridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
return array_merge(array('Account.*'), return array_merge(array('Account.*'),
$this->Account->Ledger->LedgerEntry->debitCreditFields(true, 'LedgerEntry', 'CurrentLedger')); $this->Account->Ledger->LedgerEntry->debitCreditFields(true, 'LedgerEntry', 'CurrentLedger'));
} }
function jqGridDataConditions(&$params, &$model) { function gridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model); $conditions = parent::gridDataConditions($params, $model);
if (in_array($params['action'], array('asset', 'liability', 'equity', 'income', 'expense'))) { if (in_array($params['action'], array('asset', 'liability', 'equity', 'income', 'expense'))) {
$conditions[] = array('Account.type' => strtoupper($params['action'])); $conditions[] = array('Account.type' => strtoupper($params['action']));
@@ -89,9 +89,9 @@ class AccountsController extends AppController {
return $conditions; return $conditions;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Account'] = array('name'); $links['Account'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -23,20 +23,20 @@ class ContactsController extends AppController {
*/ */
function index() { $this->all(); } function index() { $this->all(); }
function all() { $this->jqGridView('All Contacts', 'all'); } function all() { $this->gridView('All Contacts', 'all'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
$order = parent::jqGridDataOrder($params, $model, $index, $direction); $order = parent::gridDataOrder($params, $model, $index, $direction);
if ($index === 'Contact.last_name') { if ($index === 'Contact.last_name') {
$order[] = 'Contact.first_name ' . $direction; $order[] = 'Contact.first_name ' . $direction;
} }
@@ -46,9 +46,9 @@ class ContactsController extends AppController {
return $order; return $order;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Contact'] = array('id'); $links['Contact'] = array('id');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -31,25 +31,25 @@ class CustomersController extends AppController {
*/ */
function index() { $this->current(); } function index() { $this->current(); }
function current() { $this->jqGridView('Current Tenants', 'current'); } function current() { $this->gridView('Current Tenants', 'current'); }
function past() { $this->jqGridView('Past Tenants'); } function past() { $this->gridView('Past Tenants'); }
function all() { $this->jqGridView('All Customers'); } function all() { $this->gridView('All Customers'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataSetup(&$params) { function gridDataSetup(&$params) {
parent::jqGridDataSetup($params); parent::gridDataSetup($params);
} }
function jqGridDataCountTables(&$params, &$model) { function gridDataCountTables(&$params, &$model) {
return array return array
('link' => ('link' =>
array(// Models array(// Models
@@ -59,13 +59,13 @@ class CustomersController extends AppController {
); );
} }
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
$link = $this->jqGridDataCountTables($params, $model); $link = $this->gridDataCountTables($params, $model);
$link['link']['StatementEntry'] = array('fields' => array()); $link['link']['StatementEntry'] = array('fields' => array());
return $link; return $link;
} }
function jqGridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
$db = &$model->getDataSource(); $db = &$model->getDataSource();
$fields = $db->fields($model, $model->alias); $fields = $db->fields($model, $model->alias);
$fields[] = ('COUNT(DISTINCT CurrentLease.id) AS lease_count'); $fields[] = ('COUNT(DISTINCT CurrentLease.id) AS lease_count');
@@ -74,8 +74,8 @@ class CustomersController extends AppController {
return $fields; return $fields;
} }
function jqGridDataConditions(&$params, &$model) { function gridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model); $conditions = parent::gridDataConditions($params, $model);
if ($params['action'] === 'current') { if ($params['action'] === 'current') {
$conditions[] = 'CurrentLease.id IS NOT NULL'; $conditions[] = 'CurrentLease.id IS NOT NULL';
@@ -87,24 +87,24 @@ class CustomersController extends AppController {
return $conditions; return $conditions;
} }
function jqGridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
$order = array(); $order = array();
$order[] = parent::jqGridDataOrder($params, $model, $index, $direction); $order[] = parent::gridDataOrder($params, $model, $index, $direction);
if ($index !== 'PrimaryContact.last_name') if ($index !== 'PrimaryContact.last_name')
$order[] = parent::jqGridDataOrder($params, $model, $order[] = parent::gridDataOrder($params, $model,
'PrimaryContact.last_name', $direction); 'PrimaryContact.last_name', $direction);
if ($index !== 'PrimaryContact.first_name') if ($index !== 'PrimaryContact.first_name')
$order[] = parent::jqGridDataOrder($params, $model, $order[] = parent::gridDataOrder($params, $model,
'PrimaryContact.first_name', $direction); 'PrimaryContact.first_name', $direction);
if ($index !== 'Customer.id') if ($index !== 'Customer.id')
$order[] = parent::jqGridDataOrder($params, $model, $order[] = parent::gridDataOrder($params, $model,
'Customer.id', $direction); 'Customer.id', $direction);
return $order; return $order;
} }
function jqGridDataRecordCount(&$params, &$model, $query) { function gridDataCount(&$params, &$model, $query) {
// We don't have a good way to use the query to obtain // We don't have a good way to use the query to obtain
// our count. The problem is that we're relying on the // our count. The problem is that we're relying on the
@@ -112,7 +112,7 @@ class CustomersController extends AppController {
// whether we omit the group by or leave it in. // whether we omit the group by or leave it in.
// So, build a fresh query for counting. // So, build a fresh query for counting.
$query['conditions'] = parent::jqGridDataConditions($params, $model); $query['conditions'] = parent::gridDataConditions($params, $model);
$count = $model->find('count', $count = $model->find('count',
array_merge(array('link' => array_diff_key($query['link'], array_merge(array('link' => array_diff_key($query['link'],
@@ -137,9 +137,9 @@ class CustomersController extends AppController {
return $count; return $count;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Customer'] = array('name'); $links['Customer'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -29,39 +29,39 @@ class LeasesController extends AppController {
*/ */
function index() { $this->all(); } function index() { $this->all(); }
function active() { $this->jqGridView('Active Leases'); } function active() { $this->gridView('Active Leases'); }
function closed() { $this->jqGridView('Closed Leases'); } function closed() { $this->gridView('Closed Leases'); }
function all() { $this->jqGridView('All Leases', 'all'); } function all() { $this->gridView('All Leases', 'all'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataSetup(&$params) { function gridDataSetup(&$params) {
parent::jqGridDataSetup($params); parent::gridDataSetup($params);
if (!isset($params['action'])) if (!isset($params['action']))
$params['action'] = 'all'; $params['action'] = 'all';
} }
function jqGridDataCountTables(&$params, &$model) { function gridDataCountTables(&$params, &$model) {
return array return array
('link' => array('Unit' => array('fields' => array('Unit.id', 'Unit.name')), ('link' => array('Unit' => array('fields' => array('Unit.id', 'Unit.name')),
'Customer' => array('fields' => array('Customer.id', 'Customer.name')))); 'Customer' => array('fields' => array('Customer.id', 'Customer.name'))));
} }
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
$link = $this->jqGridDataCountTables($params, $model); $link = $this->gridDataCountTables($params, $model);
$link['link']['StatementEntry'] = array('fields' => array()); $link['link']['StatementEntry'] = array('fields' => array());
return $link; return $link;
} }
function jqGridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
$db = &$model->getDataSource(); $db = &$model->getDataSource();
$fields = $db->fields($model, $model->alias); $fields = $db->fields($model, $model->alias);
$fields = array_merge($fields, $fields = array_merge($fields,
@@ -69,8 +69,8 @@ class LeasesController extends AppController {
return $fields; return $fields;
} }
function jqGridDataConditions(&$params, &$model) { function gridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model); $conditions = parent::gridDataConditions($params, $model);
if ($params['action'] === 'active') { if ($params['action'] === 'active') {
$conditions[] = 'Lease.close_date IS NULL'; $conditions[] = 'Lease.close_date IS NULL';
@@ -85,7 +85,7 @@ class LeasesController extends AppController {
return $conditions; return $conditions;
} }
function jqGridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
// Do not sort by number, which is type varchar and // Do not sort by number, which is type varchar and
// sorts on an ascii basis. Sort by ID instead. // sorts on an ascii basis. Sort by ID instead.
if ($index === 'Lease.number') if ($index === 'Lease.number')
@@ -96,31 +96,31 @@ class LeasesController extends AppController {
$index = 'Unit.sort_order'; $index = 'Unit.sort_order';
$order = array(); $order = array();
$order[] = parent::jqGridDataOrder($params, $model, $index, $direction); $order[] = parent::gridDataOrder($params, $model, $index, $direction);
// If sorting by anything other than id/number // If sorting by anything other than id/number
// add sorting by id as a secondary condition. // add sorting by id as a secondary condition.
if ($index !== 'Lease.id' && $index !== 'Lease.number') if ($index !== 'Lease.id' && $index !== 'Lease.number')
$order[] = parent::jqGridDataOrder($params, $model, $order[] = parent::gridDataOrder($params, $model,
'Lease.id', $direction); 'Lease.id', $direction);
return $order; return $order;
} }
/* function jqGridRecordsPostProcess(&$params, &$model, &$records) { */ /* function gridDataPostProcess(&$params, &$model, &$records) { */
/* foreach ($records AS &$record) { */ /* foreach ($records AS &$record) { */
/* $record['Lease']['through_date'] */ /* $record['Lease']['through_date'] */
/* = $this->Lease->rentChargeThrough($record['Lease']['id']); */ /* = $this->Lease->rentChargeThrough($record['Lease']['id']); */
/* } */ /* } */
/* parent::jqGridRecordsPostProcess($params, $model, $records); */ /* parent::gridDataPostProcess($params, $model, $records); */
/* } */ /* } */
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Lease'] = array('number'); $links['Lease'] = array('number');
$links['Unit'] = array('name'); $links['Unit'] = array('name');
$links['Customer'] = array('name'); $links['Customer'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -19,19 +19,19 @@ class LedgerEntriesController extends AppController {
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataSetup(&$params) { function gridDataSetup(&$params) {
parent::jqGridDataSetup($params); parent::gridDataSetup($params);
if (isset($params['custom']['collected_account_id'])) if (isset($params['custom']['collected_account_id']))
$params['custom']['account_id'] = $params['custom']['collected_account_id']; $params['custom']['account_id'] = $params['custom']['collected_account_id'];
} }
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
$link = $link =
array(// Models array(// Models
'Account' => 'Account' =>
@@ -97,8 +97,8 @@ class LedgerEntriesController extends AppController {
return array('link' => $link); return array('link' => $link);
} }
function jqGridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
$fields = parent::jqGridDataFields($params, $model); $fields = parent::gridDataFields($params, $model);
if (!isset($fields)) if (!isset($fields))
$fields = array('Entry.*'); $fields = array('Entry.*');
@@ -142,8 +142,8 @@ class LedgerEntriesController extends AppController {
return $fields; return $fields;
} }
function jqGridDataConditions(&$params, &$model) { function gridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model); $conditions = parent::gridDataConditions($params, $model);
if ($params['action'] === 'collected') { if ($params['action'] === 'collected') {
extract($params['custom']); extract($params['custom']);
@@ -225,7 +225,7 @@ class LedgerEntriesController extends AppController {
return $conditions; return $conditions;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Transaction'] = array('id'); $links['Transaction'] = array('id');
$links['Entry'] = array('id'); $links['Entry'] = array('id');
$links['Account'] = array('controller' => 'accounts', 'name'); $links['Account'] = array('controller' => 'accounts', 'name');
@@ -235,17 +235,17 @@ class LedgerEntriesController extends AppController {
$links['Customer'] = array('name'); $links['Customer'] = array('name');
$links['Lease'] = array('number'); $links['Lease'] = array('number');
$links['Unit'] = array('name'); $links['Unit'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }
function jqGridDataGroup(&$params, &$model) { function gridDataGroup(&$params, &$model) {
return parent::jqGridDataGroup($params, $model); return parent::gridDataGroup($params, $model);
} }
function jqGridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
/* if ($index === 'balance') */ /* if ($index === 'balance') */
/* return ($index .' '. $direction); */ /* return ($index .' '. $direction); */
$order = parent::jqGridDataOrder($params, $model, $index, $direction); $order = parent::gridDataOrder($params, $model, $index, $direction);
if ($index === 'Transaction.stamp') { if ($index === 'Transaction.stamp') {
$order[] = 'Entry.id ' . $direction; $order[] = 'Entry.id ' . $direction;
@@ -254,7 +254,7 @@ class LedgerEntriesController extends AppController {
return $order; return $order;
} }
function jqGridDataRecords(&$params, &$model, $query) { function gridDataRecords(&$params, &$model, $query) {
if ($params['action'] === 'collected') { if ($params['action'] === 'collected') {
$tquery = array_diff_key($query, array(/*'fields'=>1,*/'group'=>1,'limit'=>1,'order'=>1)); $tquery = array_diff_key($query, array(/*'fields'=>1,*/'group'=>1,'limit'=>1,'order'=>1));
$tquery['group'] = array('AppliedPayment.id'); $tquery['group'] = array('AppliedPayment.id');
@@ -275,7 +275,7 @@ class LedgerEntriesController extends AppController {
$params['userdata']['balance'] = $total[0]['balance']; $params['userdata']['balance'] = $total[0]['balance'];
} }
return parent::jqGridDataRecords($params, $model, $query); return parent::gridDataRecords($params, $model, $query);
} }

View File

@@ -29,31 +29,31 @@ class LedgersController extends AppController {
*/ */
function index() { $this->all(); } function index() { $this->all(); }
function current() { $this->jqGridView('Current Ledgers'); } function current() { $this->gridView('Current Ledgers'); }
function closed() { $this->jqGridView('Closed Ledgers'); } function closed() { $this->gridView('Closed Ledgers'); }
function all() { $this->jqGridView('All Ledgers', 'all'); } function all() { $this->gridView('All Ledgers', 'all'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataSetup(&$params) { function gridDataSetup(&$params) {
parent::jqGridDataSetup($params); parent::gridDataSetup($params);
if (!isset($params['action'])) if (!isset($params['action']))
$params['action'] = 'all'; $params['action'] = 'all';
} }
function jqGridDataCountTables(&$params, &$model) { function gridDataCountTables(&$params, &$model) {
return array('contain' => false); return array('contain' => false);
} }
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
return array return array
('link' => ('link' =>
array(// Models array(// Models
@@ -64,14 +64,14 @@ class LedgersController extends AppController {
); );
} }
function jqGridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
return array_merge(array('Ledger.*', return array_merge(array('Ledger.*',
'CONCAT(Account.id, "-", Ledger.sequence) AS id_sequence'), 'CONCAT(Account.id, "-", Ledger.sequence) AS id_sequence'),
$this->Ledger->LedgerEntry->debitCreditFields(true)); $this->Ledger->LedgerEntry->debitCreditFields(true));
} }
function jqGridDataConditions(&$params, &$model) { function gridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model); $conditions = parent::gridDataConditions($params, $model);
if ($params['action'] === 'current') { if ($params['action'] === 'current') {
$conditions[] = array('NOT' => array('Ledger.closed')); $conditions[] = array('NOT' => array('Ledger.closed'));
@@ -83,14 +83,14 @@ class LedgersController extends AppController {
return $conditions; return $conditions;
} }
function jqGridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
$id_sequence = false; $id_sequence = false;
if ($index === 'id_sequence') { if ($index === 'id_sequence') {
$id_sequence = true; $id_sequence = true;
$index = 'Ledger.account_id'; $index = 'Ledger.account_id';
} }
$order = parent::jqGridDataOrder($params, $model, $index, $direction); $order = parent::gridDataOrder($params, $model, $index, $direction);
if ($id_sequence) { if ($id_sequence) {
$order[] = 'Ledger.sequence ' . $direction; $order[] = 'Ledger.sequence ' . $direction;
@@ -99,10 +99,10 @@ class LedgersController extends AppController {
return $order; return $order;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Ledger'] = array('id_sequence'); $links['Ledger'] = array('id_sequence');
$links['Account'] = array('name'); $links['Account'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -15,28 +15,28 @@ class MapsController extends AppController {
*/ */
function index() { $this->all(); } function index() { $this->all(); }
function all() { $this->jqGridView('All Maps', 'all'); } function all() { $this->gridView('All Maps', 'all'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
return array return array
('link' => array('SiteArea' => array('fields' => array('SiteArea.id', 'SiteArea.name')), ('link' => array('SiteArea' => array('fields' => array('SiteArea.id', 'SiteArea.name')),
), ),
); );
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Map'] = array('id'); $links['Map'] = array('id');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -24,27 +24,27 @@ class MonetarySourcesController extends AppController {
*/ */
function index() { $this->all(); } function index() { $this->all(); }
function all() { $this->jqGridView('All MonetarySources', 'all'); } function all() { $this->gridView('All MonetarySources', 'all'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
return array return array
('contain' => false, ('contain' => false,
); );
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['MonetarySource'] = array('id'); $links['MonetarySource'] = array('id');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -19,17 +19,17 @@ class StatementEntriesController extends AppController {
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataSetup(&$params) { function gridDataSetup(&$params) {
parent::jqGridDataSetup($params); parent::gridDataSetup($params);
} }
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
$link = $link =
array(// Models array(// Models
'Transaction' => 'Transaction' =>
@@ -67,8 +67,8 @@ class StatementEntriesController extends AppController {
return array('link' => $link); return array('link' => $link);
} }
function jqGridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
$fields = parent::jqGridDataFields($params, $model); $fields = parent::gridDataFields($params, $model);
if (!isset($fields)) if (!isset($fields))
$fields = array('StatementEntry.*'); $fields = array('StatementEntry.*');
@@ -97,8 +97,8 @@ class StatementEntriesController extends AppController {
return $fields; return $fields;
} }
function jqGridDataConditions(&$params, &$model) { function gridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model); $conditions = parent::gridDataConditions($params, $model);
extract($params['custom']); extract($params['custom']);
if (isset($transaction_id)) if (isset($transaction_id))
@@ -138,22 +138,22 @@ class StatementEntriesController extends AppController {
return $conditions; return $conditions;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['StatementEntry'] = array('id'); $links['StatementEntry'] = array('id');
$links['Transaction'] = array('id'); $links['Transaction'] = array('id');
$links['Account'] = array('name'); $links['Account'] = array('name');
$links['Customer'] = array('name'); $links['Customer'] = array('name');
$links['Lease'] = array('number'); $links['Lease'] = array('number');
$links['Unit'] = array('name'); $links['Unit'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }
function jqGridDataGroup(&$params, &$model) { function gridDataGroup(&$params, &$model) {
return parent::jqGridDataGroup($params, $model); return parent::gridDataGroup($params, $model);
} }
function jqGridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
$order = parent::jqGridDataOrder($params, $model, $index, $direction); $order = parent::gridDataOrder($params, $model, $index, $direction);
if ($index === 'Transaction.stamp') if ($index === 'Transaction.stamp')
$order[] = 'StatementEntry.id ' . $direction; $order[] = 'StatementEntry.id ' . $direction;
@@ -161,7 +161,7 @@ class StatementEntriesController extends AppController {
return $order; return $order;
} }
function jqGridDataRecords(&$params, &$model, $query) { function gridDataRecords(&$params, &$model, $query) {
if ($params['action'] === 'collected') { if ($params['action'] === 'collected') {
$tquery = array_diff_key($query, array(/*'fields'=>1,*/'group'=>1,'limit'=>1,'order'=>1)); $tquery = array_diff_key($query, array(/*'fields'=>1,*/'group'=>1,'limit'=>1,'order'=>1));
$tquery['group'] = array('AppliedPayment.id'); $tquery['group'] = array('AppliedPayment.id');
@@ -182,7 +182,7 @@ class StatementEntriesController extends AppController {
$params['userdata']['balance'] = $total[0]['balance']; $params['userdata']['balance'] = $total[0]['balance'];
} }
return parent::jqGridDataRecords($params, $model, $query); return parent::gridDataRecords($params, $model, $query);
} }

View File

@@ -29,21 +29,21 @@ class TransactionsController extends AppController {
*/ */
function index() { $this->all(); } function index() { $this->all(); }
function all() { $this->jqGridView('All Transactions', 'all'); } function all() { $this->gridView('All Transactions', 'all'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Transaction'] = array('id'); $links['Transaction'] = array('id');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -30,28 +30,28 @@ class UnitsController extends AppController {
*/ */
function index() { $this->all(); } function index() { $this->all(); }
function unavailable() { $this->jqGridView('Unavailable Units'); } function unavailable() { $this->gridView('Unavailable Units'); }
function vacant() { $this->jqGridView('Vacant Units'); } function vacant() { $this->gridView('Vacant Units'); }
function occupied() { $this->jqGridView('Occupied Units'); } function occupied() { $this->gridView('Occupied Units'); }
function all() { $this->jqGridView('All Units', 'all'); } function all() { $this->gridView('All Units', 'all'); }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* virtuals: jqGridData * virtuals: gridData
* - With the application controller handling the jqGridData action, * - With the application controller handling the gridData action,
* these virtual functions ensure that the correct data is passed * these virtual functions ensure that the correct data is passed
* to jqGrid. * to jqGrid.
*/ */
function jqGridDataSetup(&$params) { function gridDataSetup(&$params) {
parent::jqGridDataSetup($params); parent::gridDataSetup($params);
if (!isset($params['action'])) if (!isset($params['action']))
$params['action'] = 'all'; $params['action'] = 'all';
} }
function jqGridDataCountTables(&$params, &$model) { function gridDataCountTables(&$params, &$model) {
$link = array $link = array
('link' => ('link' =>
array(// Models array(// Models
@@ -70,8 +70,8 @@ class UnitsController extends AppController {
return $link; return $link;
} }
function jqGridDataTables(&$params, &$model) { function gridDataTables(&$params, &$model) {
$link = $this->jqGridDataCountTables($params, $model); $link = $this->gridDataCountTables($params, $model);
$link['link']['CurrentLease']['LedgerEntry'] = array('fields' => array()); $link['link']['CurrentLease']['LedgerEntry'] = array('fields' => array());
$link['link']['CurrentLease']['LedgerEntry']['Ledger'] = array('fields' => array()); $link['link']['CurrentLease']['LedgerEntry']['Ledger'] = array('fields' => array());
$link['link']['CurrentLease']['LedgerEntry']['Ledger']['Account'] = array('fields' => array()); $link['link']['CurrentLease']['LedgerEntry']['Ledger']['Account'] = array('fields' => array());
@@ -89,7 +89,7 @@ class UnitsController extends AppController {
return $link; return $link;
} }
function jqGridDataFields(&$params, &$model) { function gridDataFields(&$params, &$model) {
$db = &$model->getDataSource(); $db = &$model->getDataSource();
$fields = $db->fields($model, $model->alias); $fields = $db->fields($model, $model->alias);
$fields[] = ("SUM(IF(Account.id IS NULL, 0," . $fields[] = ("SUM(IF(Account.id IS NULL, 0," .
@@ -99,8 +99,8 @@ class UnitsController extends AppController {
return $fields; return $fields;
} }
function jqGridDataConditions(&$params, &$model) { function gridDataConditions(&$params, &$model) {
$conditions = parent::jqGridDataConditions($params, $model); $conditions = parent::gridDataConditions($params, $model);
if ($params['action'] === 'unavailable') { if ($params['action'] === 'unavailable') {
$conditions[] = $this->Unit->conditionUnavailable(); $conditions[] = $this->Unit->conditionUnavailable();
@@ -118,27 +118,27 @@ class UnitsController extends AppController {
return $conditions; return $conditions;
} }
function jqGridDataOrder(&$params, &$model, $index, $direction) { function gridDataOrder(&$params, &$model, $index, $direction) {
// Instead of sorting by name, sort by defined order // Instead of sorting by name, sort by defined order
if ($index === 'Unit.name') if ($index === 'Unit.name')
$index = 'Unit.sort_order'; $index = 'Unit.sort_order';
$order = array(); $order = array();
$order[] = parent::jqGridDataOrder($params, $model, $index, $direction); $order[] = parent::gridDataOrder($params, $model, $index, $direction);
// If sorting by anything other than name (defined order) // If sorting by anything other than name (defined order)
// add the sort-order as a secondary condition // add the sort-order as a secondary condition
if ($index !== 'Unit.name') if ($index !== 'Unit.name')
$order[] = parent::jqGridDataOrder($params, $model, $order[] = parent::gridDataOrder($params, $model,
'Unit.sort_order', $direction); 'Unit.sort_order', $direction);
return $order; return $order;
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) { function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
$links['Unit'] = array('name'); $links['Unit'] = array('name');
$links['UnitSize'] = array('name'); $links['UnitSize'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links); return parent::gridDataPostProcessLinks($params, $model, $records, $links);
} }

View File

@@ -62,7 +62,7 @@ $javascript->link('pmgr_jqGrid', false);
// we'll just pass the desired fields to the controller // we'll just pass the desired fields to the controller
// as part of the data fetch. // as part of the data fetch.
$url = $html->url(array('controller' => $controller, $url = $html->url(array('controller' => $controller,
'action' => 'jqGridData', 'action' => 'gridData',
'debug' => 0, 'debug' => 0,
)); ));