Source for file Table.php
Documentation is available at Table.php
* A Framework for Creating and Using Complex Web Elements
* The purpose of this framework is to provide a library of high-level objects
* to facilitate common HTML coding tasks, such as menus, tables, and forms.
* The intent is to reduce repetitive HTML coding as much as possible, replacing
* it with a combination of configuration files and style sheets with
* standardized naming conventions.
* This framework is built on and requires the
* {@link http://framework.zend.com/ Zend Framework}.
* @author Lyle Frost <lfrost@cnz.com>
* @copyright Copyright (c) 2006-2007 Citadel Network <{@link http://www.citadelnetwork.com/}>
* @license http://www.citadelnetwork.com/license/cnzframework New BSD License
* @version $Id: Table.php 27 2007-07-19 18:47:54Z lfrost $
Zend_Loader::loadClass('Cnz_Html_Element');
Zend_Loader::loadClass('Cnz_Html_Table_Button');
Zend_Loader::loadClass('Cnz_Html_Table_Column');
Zend_Loader::loadClass('Zend_Filter');
Zend_Loader::loadClass('Zend_Filter_Alnum');
Zend_Loader::loadClass('Zend_Filter_Int');
* If greenbar is true, the style suffix 'hilight' is used for even-numbered
* [HtmlTable-team : HtmlTable]
* caption = "The CF Demo Team"
* column.1.heading = Name
* column.2.heading = Number
* column.3.name = position
* column.3.heading = Position
* [HtmlTable-directory : HtmlTable]
* order = name_last,name_first
* column.name.heading = Name
* column.name.name = name
* column.name.expression = "name_first||' '||name_last"
* column.email.heading = Email
* column.email.name = email
* column.email.link = mailto
* Cnz_Html::loadAndDisplay('Cnz_Html_Table_Csv', array('name' => 'team', 'filename' => 'table.ini', 'config' => true), 'float:right;');
/*====================================================================*/
private $headerRowFlag = false;
private $greenbarFlag = false;
/** Records are in columns */
private $transposeFlag = false;
private $greenbarBandSize = 1;
/* Getters/Setters ===================================================*/
* @param string New order
/* Generators ========================================================*/
* @return array Sequential array of column names
$cna[] = $column->getName();
/* Methods ===========================================================*/
* @param array $options Options
// Process configuration.
if (isset ($this->config->caption)) $this->caption = $this->config->caption;
if (isset ($this->config->greenbarBandSize)) $this->greenbarBandSize = (int) $this->config->greenbarBandSize;
// Create buttons and columns.
if (isset ($this->config->column))
for ($this->config->column->rewind(); $this->config->column->valid(); $this->config->column->next())
$options['name'] = $this->config->column->key();
if (isset ($this->config->button))
for ($this->config->button->rewind(); $this->config->button->valid(); $this->config->button->next())
$options['name'] = $this->config->button->key();
if (isset ($_GET['offset']))
$filter = new Zend_Filter_Int();
$this->offset = $filter->filter($_GET['offset']);
if (isset ($_GET['order']))
$filter = new Zend_Filter_Alnum();
$order = $filter->filter($_GET['order']);
if (isset ($_GET['where']))
$filter = new Zend_Filter_Alnum();
$this->whereAdd = $filter->filter($_GET['where']);
* @param string $style Value for outermost style attribute
public function display($style = NULL)
//if (!empty($this->whereAdd)) echo '<p>', $this->whereAdd, '</p>';
echo $indent, '<div class = "', $this->genStyles(), '"';
if (!empty($style)) echo ' style = "', $style, '"';
echo $indent, '<table class = "', $this->genStyles(), '" style = "width:100%;">', "\n";
if (isset ($this->caption))
echo $indent, '<caption class = "', $this->genStyles(), '">';
for ($rowNumber = 0; $rowNumber < $rowCount; $rowNumber++ )
$this->displayRow($rowNumber);
echo $indent, '</table>', "\n";
echo $indent, '<div style = "text-align: center;">';
echo '<a href = ""><img alt = "[First]" src = "', Cnz_Html::getButtonDir(), self::FIRST_BUTTON, '" style = "border:none;"/></a>';
echo '<a href = "?offset=' . $prev_offset;
echo '"><img alt = "[Previous]" src = "', Cnz_Html::getButtonDir(), self::PREV_BUTTON, '" style = "border:none;"/></a> ';
echo ' <a href = "?offset=' . $next_offset;
echo '"><img alt = "[Next]" src = "', Cnz_Html::getButtonDir(), self::NEXT_BUTTON, '" style = "border:none;"/></a>';
echo '"><img alt = "[Last]" src = "', Cnz_Html::getButtonDir(), self::LAST_BUTTON, '" style = "border:none;"/></a>';
echo $indent, '</div>', "\n";
* @param string $name Column name
* @return int Column number, or false on error
for ($i = 0; $i < $n; $i++ )
if ($name == $this->columnArray[$i]->getName()) return $i;
* Defined by the Countable interface
private function displayHeader()
echo $indent, '<tr class = "', $this->genStyles(), '">', "\n";
echo $indent, $is, '<th class = "', $this->genStyles(), '">';
$order = $column->getOrder();
echo '<a href = "?offset=', $this->offset, '&order=', $order, '">';
echo $column->getHeading();
echo $column->getHeading();
echo $indent, '</tr>', "\n";
private function displayRow($rowNumber)
$bandNum = (int) ($rowNumber / $this->greenbarBandSize);
echo $indent, '<tr class = "', $this->genStyles(), '">', "\n";
if ($this->transposeFlag)
echo $indent, $is, '<th class = "', $this->genStyles(), '">', "\n";
if ($bandNum % 2 == 1) $styleSuffix = 'hilight';
echo $indent, $is, '<td class = "', $this->genStyles(NULL, $styleSuffix), '">', "\n";
echo $indent, $is, '</td>', "\n";
for ($colNum = 0; $colNum < $colCount; $colNum++ )
$align = $column->getAlign();
if (!empty($align)) $style = ' style = "text-align:' . $align . ';"';
echo $indent, $is, '<td class = "', $this->genStyles(NULL, $styleSuffix), '"', $style;
if ($column->getNoWrap()) echo ' style = "white-space:nowrap;"';
$link = $column->getLink();
if (!empty($link) && !empty($cell))
echo $indent, '</tr>', "\n";
|