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("
jqGrid
");
$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;
}
}