* @copyright 2001-2006 VIKO team and contributors * @license http://www.gnu.org/licenses/gpl.html GPL 2.0 */ /** * This class encapsulates PEAR class HTML_Table */ require_once 'HTML/Table.php'; /** * Only table body is affected */ define("TABLE_BODY_ONLY", 0); /** * Only table footer is affected */ define("TABLE_FOOTER_ONLY", 1); /** * Both table body and footer are affected */ define("TABLE_BODY_AND_FOOTER", 2); /** * Manages creation of HTML data tables for VIKO environment * * The class encapsulates an HTML_Table object to which it adds * some viko-specific attributes. For example all the even rows * in table will have class="even" and odd rows class="odd". * * For example the creation of a table to display scores for * athlets might be done light this: * *
* $table =& new VikoTable( * "100 finalists ordered by score starting with the highest." * ); * * $table->addHeader( "Name", "Score" ); * * $total_score=0; * foreach( $spotsmen as $man ) { * $table->addRow( $man['name'], $man['score'] ); * $total_score += $man['score']; * } * * $table->addFooter( "Total", $total_score ); * * echo $table->toHTML(); ** */ class VikoTable { /** * Reference to the table object * * @access private */ var $_table; /** * Reference to the table header object * * @access private */ var $_header; /** * Reference to the table body object * * @access private */ var $_body; /** * Reference to the table footer object * * @access private */ var $_footer; /** * Constructs new VikoTable instance * * You are not required to specify summary for the table, but for more * complex tables with many columns and rows this may prove helpful. * The summary should describe the organization of the table and * how the table should be used. See the class description for an example. * * @access public * @param string $summary the value for the summary attribute of table */ function VikoTable( $summary = "" ) { // initialize the encapsulated table object $this->_table =& new HTML_Table( array("summary" => $summary) ); $this->_header =& $this->_table->getHeader(); $this->_body =& $this->_table->getBody(); $this->_footer =& $this->_table->getFooter(); } /** * Adds new row to the body of the table * * The function takes variable number of arguments, * each representing the contents of one cell. * * You may also pass the cell contents as an array - * then the function takes only one argument - this array. * When passing an array, you may after the array pass also a string, * that will be used as a classname for the added row. * * @access public */ function addRow() { if ( func_num_args() == 1 && is_array( func_get_arg(0) ) ) { $this->_body->addRow( func_get_arg(0) ); } elseif ( func_num_args() == 2 && is_array( func_get_arg(0) ) ) { $classname = func_get_arg(1); $this->_body->addRow( func_get_arg(0), array( 'class' => $classname ), 'td', true ); } else { $this->_body->addRow( func_get_args() ); } } /** * Adds new row to the header of the table * * The function takes variable number of arguments, * each representing the contents of one cell. * * You may also pass the cell contents as an array - * then the function takes only one argument - this array. * * @access public */ function addHeader() { if ( func_num_args() == 1 && is_array( func_get_arg(0) ) ) { $this->_header->addRow( func_get_arg(0), null, 'th' ); } else { $this->_header->addRow( func_get_args(), null, 'th' ); } } /** * Adds new row to the footer of the table * * The function takes variable number of arguments, * each representing the contents of one cell. * * You may also pass the cell contents as an array - * then the function takes only one argument - this array. * * @access public */ function addFooter() { if ( func_num_args() == 1 && is_array( func_get_arg(0) ) ) { $this->_footer->addRow( func_get_arg(0) ); } else { $this->_footer->addRow( func_get_args() ); } } /** * Defines the columns to be have specified value of class attribute * * To the table cells that belong to the columns with indexes listed * in $column_indexes will be assigned class="$class". But that only * affects the cells in table body and/or footer sections. * * $table_part attribute specifies the affected part of the table: * *