Source for file dblist.php
Documentation is available at dblist.php
* generic database list/export class
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @subpackage FormsLibrary
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
/** uses an OutputFormatter to format the data */
require_once 'inc/formslib/outputformatter.php';
/** export formatting codes */
require_once 'inc/exportcodes.php';
* generic database list/export class
* @subpackage FormsLibrary
* Create a new DBList object
* @param string $table name of (primary) table to be interrogated
* @param mixed $returnFields single column name or list of column names to be returned from the db
* @param mixed $restriction single or list of restrictions to be 'AND'ed together
* @param boolean $distinct select only DISTINCT rows from the db
function DBList($table, $returnFields, $restriction, $distinct=
false) {
// calculate some values in advance and cache them to speed this class with large datasets
$this->returnFieldAliases =
array();
$this->returnFieldCells =
array();
$this->returnFieldAliases[$this->returnFields[$i]->alias] =
$i;
$this->returnFieldCells[$this->returnFields[$i]->alias] =
$cell;
* Fill the object from the database
foreach ($this->union as $u) {
$union[] =
$u->_getSQLsyntax();
$q =
'('.
join($union, ') UNION ALL (').
')';
if (isset
($this->manualGroup) &&
$this->manualGroup !=
'') {
while ($row <
$numrows) {
$current =
$data[$row][$this->manualGroup];
$currentRow =
$data[$row];
foreach ($this->manualSum as $col) {
while ($row <
$numrows &&
$data[$row][$this->manualGroup] ==
$current) {
foreach ($this->manualSum as $col) {
$sums[$col] +=
$data[$row][$col];
foreach ($this->manualSum as $col) {
$currentRow[$col] =
$sums[$col];
$sumdata[] =
$currentRow;
* generate the appropriate SQL syntax for this query
* @return string SQL query for this object
$fields[] =
$v->name .
(isset
($v->alias) ?
' AS '.
$v->alias :
'');
$q =
'SELECT '.
($this->distinct ?
'DISTINCT ' :
' ')
.
' FROM '.
$TABLEPREFIX.
$this->table.
' AS '.
$this->table.
' ';
foreach ($this->join as $t) {
$q .=
' LEFT JOIN '.
$TABLEPREFIX.
$t['table'].
' AS '.
(isset
($t['alias']) ?
$t['alias'] :
$t['table'])
* format the list using the designated formats into another list
//preDump($this->omitFields);
for ($i=
0; $i<
$numdata; $i++
) {
* @param array $data name=>value pairs of data
* @return string formatter line of data
function format($data/*, $isHeader=false*/) {
// performance of array_key_exists() can be a problem
// see http://bugs.php.net/37563
//if (! array_key_exists($f, $this->omitFields)) {
array('\\"', '"$1"' ), $d), ',');
* @return string formatter header row
$d[$f->alias] =
$f->heading;
return $this->format($d/*, true*/);
* create a row of data with the value and some formatting data for use by the Array/HTML/PDF Export
* @return array list of array(value=>$value, format=>$format, width=>$width)
foreach ($d as $alias =>
$val) {
$cell =
$this->returnFieldCells[$alias];
// use the cached reverse mapping of field aliases/names back to the field number
//$f = $this->returnFields[$this->returnFieldAliases[$alias]];
//$cell['value'] = $this->formatVal($val, $f->format, $isHeader);
// $cell['format'] = $f->format;
// $cell['width'] = isset($f->width) ? $f->width : 10;
* Create a set of OutputFormatter objects to handle the display of this object.
* @param string $f1 sprintf format (see PHP manual)
* @param array $v1 array of indices that will be used to fill the fields in the sprintf format from a $data array passed to the formatter later.
Documentation generated on Tue, 06 Mar 2007 10:01:19 +0000 by phpDocumentor 1.3.0