Fixed a bug in which jqGrid would fetch data from the current controller, not the controller responsible for populating the data. Added the ability to fetch data based strictly off of an ID list, which is useful for lists that are embedded in other pages, where the list conditions are entirely foreign to the controller responsible for providing the data. To assist with this one jqGrid virtual function needed the model added as a parameter, so I added it to them all and modified the jqGrid functions in the existing derived controllers. Right now the elements (such as contacts.ctp, the only working one) receive a full list of data to populate themselves. I could have simply taken this and passed it directly to jqGrid, with no need for further server interaction. However, this could result in some very large lists, and although pagination will ensure the user is not overwhelmed, the connection or the browser could be. Unless we have a strong performance need, I'll keep it this way. In the meantime, I'll leave the underlying data available to each element, in case I have to switch over. When all is proven out, I can simplify all the queries such that the extra data is never requested in the first place.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@122 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -91,9 +91,9 @@ class AppController extends Controller {
|
||||
$model = $this->jqGridDataModel($params);
|
||||
|
||||
// Establish the basic query and conditions
|
||||
$query = array_intersect_key($this->jqGridDataTables($params),
|
||||
$query = array_intersect_key($this->jqGridDataTables($params, $model),
|
||||
array('link'=>1, 'contain'=>1));
|
||||
$query['conditions'] = $this->jqGridDataConditions($params);
|
||||
$query['conditions'] = $this->jqGridDataConditions($params, $model);
|
||||
|
||||
// Get the number of records prior to pagination
|
||||
$count = $this->jqGridDataRecordCount($params, $model, $query);
|
||||
@@ -105,22 +105,22 @@ class AppController extends Controller {
|
||||
$start = $limit*$page - $limit;
|
||||
|
||||
// Grab the actual records taking pagination into account
|
||||
$query['group'] = $model->alias . '.id';
|
||||
$query['order'] = $this->jqGridDataOrder($params,
|
||||
$query['group'] = $model->alias.'.'.$model->primaryKey;
|
||||
$query['order'] = $this->jqGridDataOrder($params, $model,
|
||||
isset($params['sidx']) ? $params['sidx'] : null,
|
||||
isset($params['sord']) ? $params['sord'] : null);
|
||||
$query['limit'] = $this->jqGridDataLimit($params, $start, $limit);
|
||||
$query['fields'] = $this->jqGridDataFields($params);
|
||||
$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;
|
||||
|
||||
// Finally, dump out the data
|
||||
$this->jqGridDataOutputHeader($params);
|
||||
$this->jqGridDataOutputHeader($params, $model);
|
||||
echo "<?xml version='1.0' encoding='utf-8'?>\n";
|
||||
echo "<rows>\n";
|
||||
$this->jqGridDataOutputSummary($params, $page, $total, $count);
|
||||
$this->jqGridDataOutputSummary($params, $model, $page, $total, $count);
|
||||
$this->jqGridDataOutputRecords($params, $model, $results);
|
||||
echo "</rows>\n";
|
||||
|
||||
@@ -174,11 +174,11 @@ class AppController extends Controller {
|
||||
return $this->{$this->modelClass};
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params) {
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
return array('contain' => false);
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params) {
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
$searches = array();
|
||||
|
||||
if (isset($params['_search']) && $params['_search'] === 'true') {
|
||||
@@ -199,9 +199,6 @@ class AppController extends Controller {
|
||||
'field' => $params['filtField'],
|
||||
'value' => $params['filtValue']);
|
||||
}
|
||||
else {
|
||||
return array();
|
||||
}
|
||||
|
||||
$ops = array('eq' => array('op' => null, 'pre' => '', 'post' => ''),
|
||||
'ne' => array('op' => '<>', 'pre' => '', 'post' => ''),
|
||||
@@ -222,30 +219,34 @@ class AppController extends Controller {
|
||||
$conditions[] = array($field => $value);
|
||||
}
|
||||
|
||||
if (isset($params['action']) && $params['action'] === 'idlist') {
|
||||
$conditions[] = array($model->alias.'.'.$model->primaryKey => unserialize($params['idlist']));
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params) {
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function jqGridDataOrder(&$params, $index, $direction) {
|
||||
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||
return $index ? array($index .' '. $direction) : null;
|
||||
}
|
||||
|
||||
function jqGridDataLimit(&$params, $start, $limit) {
|
||||
function jqGridDataLimit(&$params, &$model, $start, $limit) {
|
||||
return $start . ', ' . $limit;
|
||||
}
|
||||
|
||||
function jqGridDataRecordCount(&$params, $model, $query) {
|
||||
function jqGridDataRecordCount(&$params, &$model, $query) {
|
||||
return $model->find('count', $query);
|
||||
}
|
||||
|
||||
function jqGridDataRecords(&$params, $model, $query) {
|
||||
function jqGridDataRecords(&$params, &$model, $query) {
|
||||
return $model->find('all', $query);
|
||||
}
|
||||
|
||||
function jqGridDataOutputHeader(&$params) {
|
||||
function jqGridDataOutputHeader(&$params, &$model) {
|
||||
if ($params['debug']) {
|
||||
ob_start();
|
||||
}
|
||||
@@ -254,14 +255,14 @@ class AppController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
function jqGridDataOutputSummary(&$params, $page, $total, $records) {
|
||||
function jqGridDataOutputSummary(&$params, &$model, $page, $total, $records) {
|
||||
echo " <params><![CDATA[\n" . print_r($params, true) . "\n]]></params>\n";
|
||||
echo " <page>$page</page>\n";
|
||||
echo " <total>$total</total>\n";
|
||||
echo " <records>$records</records>\n";
|
||||
}
|
||||
|
||||
function jqGridDataOutputRecords(&$params, $model, $records) {
|
||||
function jqGridDataOutputRecords(&$params, &$model, $records) {
|
||||
$model_alias = $model->alias;
|
||||
|
||||
foreach ($records AS $record) {
|
||||
|
||||
Reference in New Issue
Block a user