Actually, we need to get away from calling things jqGrid except at the lowest point. We don't want to switch vendors and have all these items continuing to be called jqGrid. Just Grid will work.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@258 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-08 17:35:36 +00:00
parent 4e2b073110
commit 6c62d66068
2 changed files with 2 additions and 2 deletions

97
views/helpers/grid.php Normal file
View File

@@ -0,0 +1,97 @@
<?php
class GridHelper extends AppHelper {
var $jqGrid_options;
var $included;
var $columns;
function __construct() {
$this->reset();
}
function reset() {
$this->jqGrid_options
= array('limit' => 20);
$this->columns = array();
$this->included = array();
return $this;
}
// Add to the set of columns for this grid
function columns($columns) {
if (isset($columns)) {
if (is_array($columns))
$this->columns += $columns;
else
array_push($this->columns, $columns);
}
return $this;
}
// Included fields will be included unless excluded.
function included($fields) {
if (isset($fields)) {
if (is_array($fields))
$this->included = array_merge($this->included, $fields);
else
array_push($this->included, $fields);
}
return $this;
}
function limit() {
$this->jqGrid_options['limit'] = 20;
return $this;
}
function id_list($items) {
$this->jqGrid_options
+= array('custom_ids' =>
array_map(create_function('$data',
'return $data["id"];'),
$items));
return $this;
}
function render($included = array(), $excluded = array()) {
pr("<H2>jqGrid</H2>");
$columns = $this->columns;
$we_want = $this->included;
$they_want = $included;
$we_dont_want = array_diff(array_keys($this->columns), $this->included);
$they_dont_want = $excluded;
if (is_bool($included) && $included)
$included = array_keys($columns);
elseif (is_bool($included) && !$included)
$included = array();
if (is_bool($excluded) && $excluded)
$excluded = array_keys($columns);
elseif (is_bool($excluded) && !$excluded)
$excluded = array();
$hopefully_wanted = array_merge($this->included, $included);
$hopefully_get = array_diff(array_merge($this->included, $included), $excluded);
$actually_get = array_intersect(array_keys($this->columns), $hopefully_get);
$actually_dont_get = array_diff(array_keys($this->columns), $hopefully_get);
pr(compact('we_want', 'they_want', 'we_dont_want', 'they_dont_want',
'hopefully_wanted', 'hopefully_get',
'actually_get', 'actually_dont_get'));
// Since we only have one instance of this class
// as a helper, we must assume it could be used
// again later to render an entirely different grid.
// Reset the variables to prevent contamination.
$this->reset();
return $this;
}
}