Added mechanism to easily create links in the listing grids. I'm not very keen on how it works, but it's good enough for the moment, unless/until I figure out how to push this to the view. If it should stay in the controller, I'm sure a more sophisticated mechanism will be required.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@128 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-15 02:50:21 +00:00
parent 3c5a31aaff
commit 4537174873
3 changed files with 39 additions and 3 deletions

View File

@@ -113,6 +113,9 @@ class AppController extends Controller {
$query['fields'] = $this->jqGridDataFields($params, $model);
$results = $this->jqGridDataRecords($params, $model, $query);
// Add in any needed hyperlinks
$this->jqGridRecordLinks($params, $model, $results, array());
// DEBUG PURPOSES ONLY
$params['query'] = $query;
@@ -246,6 +249,28 @@ class AppController extends Controller {
return $model->find('all', $query);
}
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
foreach ($links AS $table => $fields) {
$controller = Inflector::pluralize(strtolower($table));
$id = 'id';
if (isset($fields['id']))
$id = $fields['id'];
foreach ($records AS &$record) {
foreach (array_diff_key($fields, array('id'=>1)) AS $field) {
$params['linkrecord'][] = compact('table', 'field', 'id', 'controller', 'record');
$record[$table][$field] =
'<A HREF="' .
Router::url(array('controller' => $controller,
'action' => 'view',
$record[$table][$id])) .
'">' .
$record[$table][$field] .
'</A>';
}
}
}
}
function jqGridDataOutputHeader(&$params, &$model) {
if ($params['debug']) {
ob_start();
@@ -262,7 +287,7 @@ class AppController extends Controller {
echo " <records>$records</records>\n";
}
function jqGridDataOutputRecords(&$params, &$model, $records) {
function jqGridDataOutputRecords(&$params, &$model, &$records) {
$model_alias = $model->alias;
foreach ($records AS $record) {