cvs: pear /Structures_DataGrid/DataGrid/Renderer Console.php
| From: | Mark Wiesemann | Date: | Fri, 24 Feb 2006 16:59:19 +0000 |
| Subject: | cvs: pear /Structures_DataGrid/DataGrid/Renderer Console.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-38569@lists.php.net to get a copy of this message | ||
wiesemann Fri Feb 24 16:59:19 2006 UTC
Modified files:
/pear/Structures_DataGrid/DataGrid/Renderer Console.php
Log:
more refactoring (Console_Table renderer)
http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/Console.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/Console.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/Console.php:1.3 pear/Structures_DataGrid/DataGrid/Renderer/Console.php:1.4 --- pear/Structures_DataGrid/DataGrid/Renderer/Console.php:1.3 Tue Oct 11 00:40:01 2005 +++ pear/Structures_DataGrid/DataGrid/Renderer/Console.php Fri Feb 24 16:59:19 2006 @@ -13,60 +13,52 @@ // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ -// | Author: Andrew Nagy <asnagy@webitecture.org> | +// | Authors: Andrew Nagy <asnagy@webitecture.org> | +// | Olivier Guilyardi <olivier@samalyse.com> | +// | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Console.php,v 1.3 2005/10/11 00:40:01 olivierg Exp $ +// $Id: Console.php,v 1.4 2006/02/24 16:59:19 wiesemann Exp $ +require_once 'Structures/DataGrid/Renderer/Common.php'; require_once 'Console/Table.php'; /** * Structures_DataGrid_Renderer_Console Class * - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * @author Andrew S. Nagy <asnagy@webitecture.org> + * @author Olivier Guilyardi <olivier@samalyse.com> + * @author Mark Wiesemann <wiesemann@php.net> * @access public * @package Structures_DataGrid * @category Structures */ -class Structures_DataGrid_Renderer_Console +class Structures_DataGrid_Renderer_Console extends Structures_DataGrid_Renderer_Common { - /** - * The Datagrid object to render - * @var object Structures_DataGrid - */ - var $_dg; - - /** - * Use the table header - * @var bool - */ - var $header = true; - - /** - * The console_table object - * @var object Console_Table - */ - var $_table; - - /** - * A switch to determine the state of the table - * @var bool - */ - var $_rendered = false; /** * Constructor * * Build default values * - * @param object Structures_DataGrid $dg The datagrid to render. * @access public */ - function Structures_DataGrid_Renderer_Console(&$dg) + function Structures_DataGrid_Renderer_Console() + { + parent::Structures_DataGrid_Renderer_Common(); + } + + /** + * Initialize Console_Table instance if it is not already existing + * + * @access protected + */ + function init() { - $this->_dg =& $dg; - $this->_table = new Console_Table(); + if (is_null($this->_container)) { + $this->_container = new Console_Table(); + } } /** @@ -77,14 +69,9 @@ */ function useHeader($bool) { - $this->header = (bool)$bool; + $this->_options['buildHeader'] = (bool)$bool; } - /** - * Prints the console text for the DataGrid - * - * @access public - */ function render() { echo $this->toAscii(); @@ -92,118 +79,70 @@ function toAscii() { - $table = $this->getTable(); - return $table->getTable(); + return $this->getOutput(); +# $table = $this->getTable(); +# return $table->getTable(); } /** - * Gets the Console_Table ascii text for the DataGrid + * Gets the Console_Table object for the DataGrid * + * OBSOLETE + * * @access public - * @return string The console table ascii text for the DataGrid + * @return object Console_Table The Console_Table object for the DataGrid */ function getTable() { - $dg =& $this->_dg; - - if (!$this->_rendered) { - /* - // Get the data to be rendered - $dg->fetchDataSource(); - */ - - // Check to see if column headers exist, if not create them - // This must follow after any fetch method call - $dg->_setDefaultHeaders(); - - // Define Table Header - if ($this->header) { - $this->_buildTableHeader(); - } - - // Build Table Data - $this->_buildTableBody(); - - $this->_rendered = true; - } - - return $this->_table; - } - - /** - * Sets the rendered status. This can be used to "flush the cache" in case - * you need to render the datagrid twice with the second time having changes - * - * @access public - * @params bool $status The rendered status of the DataGrid - */ - function setRendered($status) - { - $this->_rendered = (bool)$status; + return $this->_container; } /** * Handles building the header of the table * - * @access private + * @access protected * @return void */ - function _buildTableHeader() + function buildHeader() { $columnList = array(); - foreach ($this->_dg->columnSet as $column) { - $columnList[] = $column->columnName; + for ($col = 0; $col < $this->_columnsNum; $col++) { + $columnList[] = $this->_columns[$col]['label']; } - $this->_table->setHeaders($columnList); + $this->_container->setHeaders($columnList); } /** * Handles building the body of the table * - * @access private + * @access protected * @return void */ - function _buildTableBody() + function buildBody() { - if ($this->_dg->recordSet) { - if (!isset($this->_dg->rowLimit)) { - $this->_dg->rowLimit = count($this->_dg->recordSet); - } - - // Begin loop - for ($i = 0; $i < $this->_dg->rowLimit; $i++) { - if (isset($this->_dg->recordSet[$i])) { - $cellList = array(); - $row = $this->_dg->recordSet[$i]; - foreach ($this->_dg->columnSet as $column) { - $rowCnt = $i+1; - - // Build Content - if (isset($column->formatter)) { - //Use Formatter - $content = $column->formatter($row); - } elseif (!isset($column->fieldName)) { - if ($column->autoFillValue != '') { - // Use AutoFill - $content = $column->autoFillValue; - } else { - // Use Column Name - $content = $column->columnName; - } - } else { - // Use Record Data - $content = $row[$column->fieldName]; - } - - $cellList[] = $content; - } - $this->_table->addRow($cellList); - } + // FIXME: don't start in row 0; instead start after the last existing + // row in the table (requires a patch [new method getRowCount()] for + // Console_Table and a new release of this package, of course) + for ($row = 0; $row < $this->_recordsNum; $row++) { + $cellList = array(); + for ($col = 0; $col < $this->_columnsNum; $col++) { + $cellList[] = $this->_records[$row][$col]; } + $this->_container->addRow($cellList); } } + /** + * Retrieve output from the container object + * + * @return mixed Output + * @access protected + */ + function flatten() + { + return $this->_container->getTable(); + } }
http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/Console.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/Console.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/Console.php:1.3 pear/Structures_DataGrid/DataGrid/Renderer/Console.php:1.4 --- pear/Structures_DataGrid/DataGrid/Renderer/Console.php:1.3 Tue Oct 11 00:40:01 2005 +++ pear/Structures_DataGrid/DataGrid/Renderer/Console.php Fri Feb 24 16:59:19 2006 @@ -13,60 +13,52 @@ // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ -// | Author: Andrew Nagy <asnagy@webitecture.org> | +// | Authors: Andrew Nagy <asnagy@webitecture.org> | +// | Olivier Guilyardi <olivier@samalyse.com> | +// | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Console.php,v 1.3 2005/10/11 00:40:01 olivierg Exp $ +// $Id: Console.php,v 1.4 2006/02/24 16:59:19 wiesemann Exp $ +require_once 'Structures/DataGrid/Renderer/Common.php'; require_once 'Console/Table.php'; /** * Structures_DataGrid_Renderer_Console Class * - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * @author Andrew S. Nagy <asnagy@webitecture.org> + * @author Olivier Guilyardi <olivier@samalyse.com> + * @author Mark Wiesemann <wiesemann@php.net> * @access public * @package Structures_DataGrid * @category Structures */ -class Structures_DataGrid_Renderer_Console +class Structures_DataGrid_Renderer_Console extends Structures_DataGrid_Renderer_Common { - /** - * The Datagrid object to render - * @var object Structures_DataGrid - */ - var $_dg; - - /** - * Use the table header - * @var bool - */ - var $header = true; - - /** - * The console_table object - * @var object Console_Table - */ - var $_table; - - /** - * A switch to determine the state of the table - * @var bool - */ - var $_rendered = false; /** * Constructor * * Build default values * - * @param object Structures_DataGrid $dg The datagrid to render. * @access public */ - function Structures_DataGrid_Renderer_Console(&$dg) + function Structures_DataGrid_Renderer_Console() + { + parent::Structures_DataGrid_Renderer_Common(); + } + + /** + * Initialize Console_Table instance if it is not already existing + * + * @access protected + */ + function init() { - $this->_dg =& $dg; - $this->_table = new Console_Table(); + if (is_null($this->_container)) { + $this->_container = new Console_Table(); + } } /** @@ -77,14 +69,9 @@ */ function useHeader($bool) { - $this->header = (bool)$bool; + $this->_options['buildHeader'] = (bool)$bool; } - /** - * Prints the console text for the DataGrid - * - * @access public - */ function render() { echo $this->toAscii(); @@ -92,118 +79,70 @@ function toAscii() { - $table = $this->getTable(); - return $table->getTable(); + return $this->getOutput(); +# $table = $this->getTable(); +# return $table->getTable(); } /** - * Gets the Console_Table ascii text for the DataGrid + * Gets the Console_Table object for the DataGrid * + * OBSOLETE + * * @access public - * @return string The console table ascii text for the DataGrid + * @return object Console_Table The Console_Table object for the DataGrid */ function getTable() { - $dg =& $this->_dg; - - if (!$this->_rendered) { - /* - // Get the data to be rendered - $dg->fetchDataSource(); - */ - - // Check to see if column headers exist, if not create them - // This must follow after any fetch method call - $dg->_setDefaultHeaders(); - - // Define Table Header - if ($this->header) { - $this->_buildTableHeader(); - } - - // Build Table Data - $this->_buildTableBody(); - - $this->_rendered = true; - } - - return $this->_table; - } - - /** - * Sets the rendered status. This can be used to "flush the cache" in case - * you need to render the datagrid twice with the second time having changes - * - * @access public - * @params bool $status The rendered status of the DataGrid - */ - function setRendered($status) - { - $this->_rendered = (bool)$status; + return $this->_container; } /** * Handles building the header of the table * - * @access private + * @access protected * @return void */ - function _buildTableHeader() + function buildHeader() { $columnList = array(); - foreach ($this->_dg->columnSet as $column) { - $columnList[] = $column->columnName; + for ($col = 0; $col < $this->_columnsNum; $col++) { + $columnList[] = $this->_columns[$col]['label']; } - $this->_table->setHeaders($columnList); + $this->_container->setHeaders($columnList); } /** * Handles building the body of the table * - * @access private + * @access protected * @return void */ - function _buildTableBody() + function buildBody() { - if ($this->_dg->recordSet) { - if (!isset($this->_dg->rowLimit)) { - $this->_dg->rowLimit = count($this->_dg->recordSet); - } - - // Begin loop - for ($i = 0; $i < $this->_dg->rowLimit; $i++) { - if (isset($this->_dg->recordSet[$i])) { - $cellList = array(); - $row = $this->_dg->recordSet[$i]; - foreach ($this->_dg->columnSet as $column) { - $rowCnt = $i+1; - - // Build Content - if (isset($column->formatter)) { - //Use Formatter - $content = $column->formatter($row); - } elseif (!isset($column->fieldName)) { - if ($column->autoFillValue != '') { - // Use AutoFill - $content = $column->autoFillValue; - } else { - // Use Column Name - $content = $column->columnName; - } - } else { - // Use Record Data - $content = $row[$column->fieldName]; - } - - $cellList[] = $content; - } - $this->_table->addRow($cellList); - } + // FIXME: don't start in row 0; instead start after the last existing + // row in the table (requires a patch [new method getRowCount()] for + // Console_Table and a new release of this package, of course) + for ($row = 0; $row < $this->_recordsNum; $row++) { + $cellList = array(); + for ($col = 0; $col < $this->_columnsNum; $col++) { + $cellList[] = $this->_records[$row][$col]; } + $this->_container->addRow($cellList); } } + /** + * Retrieve output from the container object + * + * @return mixed Output + * @access protected + */ + function flatten() + { + return $this->_container->getTable(); + } }