cvs: pear /Structures_DataGrid DataGrid.php /Structures_DataGrid/DataGrid/Renderer Common.php HTMLTable.php
| From: | Olivier Guilyardi | Date: | Mon, 02 Jan 2006 18:39:28 +0000 |
| Subject: | cvs: pear /Structures_DataGrid DataGrid.php /Structures_DataGrid/DataGrid/Renderer Common.php HTMLTable.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-37264@lists.php.net to get a copy of this message | ||
olivierg Mon Jan 2 18:39:28 2006 UTC
Modified files:
/pear/Structures_DataGrid DataGrid.php
/pear/Structures_DataGrid/DataGrid/Renderer Common.php
HTMLTable.php
Log:
Fixed paging and the 'sortingResetsPaging' option
http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid.php?r1=1.26&r2=1.27&diff_format=u Index: pear/Structures_DataGrid/DataGrid.php diff -u pear/Structures_DataGrid/DataGrid.php:1.26 pear/Structures_DataGrid/DataGrid.php:1.27 --- pear/Structures_DataGrid/DataGrid.php:1.26 Sat Dec 31 00:34:04 2005 +++ pear/Structures_DataGrid/DataGrid.php Mon Jan 2 18:39:28 2006 @@ -13,10 +13,12 @@ // | 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: DataGrid.php,v 1.26 2005/12/31 00:34:04 olivierg Exp $ +// $Id: DataGrid.php,v 1.27 2006/01/02 18:39:28 olivierg Exp $ require_once 'PEAR.php'; @@ -68,8 +70,10 @@ * ?> * </code> * - * @version $Revision: 1.26 $ + * @version $Revision: 1.27 $ * @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 @@ -213,7 +217,7 @@ $file_name = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; if (!include_once($file_name)) { if (!Structures_DataGrid::fileExists($file_name)) { - $msg = "unable to find package '$classNname' file '$file_name'"; + $msg = "unable to find package '$className' file '$file_name'"; } else { $msg = "unable to load driver class '$className' from file '$file_name'"; } @@ -374,6 +378,11 @@ { if (is_subclass_of($renderer, 'structures_datagrid_renderer_common')) { $this->renderer =& $renderer; + if (isset ($this->_dataSource)) { + $this->renderer->setData($this->columnSet, $this->recordSet); + $this->renderer->setLimit($this->page, $this->rowLimit, + $this->getRecordCount()); + } } else { return new PEAR_Error('Invalid renderer type, ' . 'must be a valid renderer driver class'); @@ -577,6 +586,18 @@ { if (is_subclass_of($source, 'structures_datagrid_datasource_common')) { $this->_dataSource =& $source; + if (PEAR::isError($result = $this->fetchDataSource())) { + unset ($this->_dataSource); + return $result; + } + if ($columnSet = $this->_dataSource->getColumns()) { + $this->columnSet = array_merge($this->columnSet, $columnSet); + } + if (isset ($this->renderer)) { + $this->renderer->setData($this->columnSet, $this->recordSet); + $this->renderer->setLimit($this->page, $this->rowLimit, + $this->getRecordCount()); + } } else { return new PEAR_Error('Invalid data source type, ' . 'must be a valid data source driver class'); @@ -804,22 +825,10 @@ function build() { if (isset($this->_dataSource)) { - if (PEAR::isError($result = $this->fetchDataSource())) { - return $result; - } - - if ($columnSet = $this->_dataSource->getColumns()) { - $this->columnSet = array_merge($this->columnSet, $columnSet); - } - - //print_r ($this->recordSet); - //print_r ($this->columnSet); - if (!isset ($this->renderer)) { $this->loadDefaultRenderer(); } - $this->renderer->setData($this->columnSet, $this->recordSet); $this->renderer->build(); $this->_isBuilt = true; } http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/Common.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/Common.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.3 pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.4 --- pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.3 Sat Dec 31 00:34:04 2005 +++ pear/Structures_DataGrid/DataGrid/Renderer/Common.php Mon Jan 2 18:39:28 2006 @@ -17,10 +17,10 @@ // | Olivier Guilyardi <olivier@samalyse.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.3 2005/12/31 00:34:04 olivierg Exp $ +// $Id: Common.php,v 1.4 2006/01/02 18:39:28 olivierg Exp $ /** - * Structures_DataGrid_Renderer Class + * Structures_DataGrid_Renderer_Common Class * * Base class of all Renderer drivers * @@ -55,7 +55,7 @@ * added * * - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * @author Olivier Guilyardi <olivier@samalyse.com> * @access public * @package Structures_DataGrid @@ -235,9 +235,10 @@ $this->_currentSortDirection = $direction; } - function setLimit($currentPage, $rowPerPage) { + function setLimit($currentPage, $rowsPerPage, $totalRowNum) { $this->_page = $currentPage; - $this->_pageLimit = $rowPerPage; + $this->_pageLimit = $rowsPerPage; + $this->_totalRecordsNum = $totalRowNum; } function init () @@ -291,32 +292,22 @@ $this->_columns[$index] = compact('field','label'); } - + if ($this->_records) { if (is_null ($this->_pageLimit)) { $this->_pageLimit = count ($this->_records); } - - assert('$this->_pageLimit >= count($this->_records)'); - - $offset = ($this->_page - 1) * $this->_pageLimit; - - for ($i = $offset; $i < $this->_pageLimit; $i++) { + + for ($i = 0; isset($this->_records[$i]) and $i < $this->_pageLimit; $i++) { $content = array (); foreach ($this->_columnObjects as $column) { $content[] = $column->recordToValue ($this->_records[$i]); } - $this->_records[$i - $offset] = $content; + $this->_records[$i] = $content; } - - $ii = count ($this->_records); - for ($i = $this->_pageLimit - $offset; $i < $ii; $i++) { - unset ($this->_records[$i]); - } - } - + $this->_columnsNum = count ($this->_columns); $this->_recordsNum = count ($this->_records); http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php?r1=1.67&r2=1.68&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.67 pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.68 --- pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.67 Sat Dec 31 00:36:16 2005 +++ pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php Mon Jan 2 18:39:28 2006 @@ -18,7 +18,7 @@ // | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: HTMLTable.php,v 1.67 2005/12/31 00:36:16 olivierg Exp $ +// $Id: HTMLTable.php,v 1.68 2006/01/02 18:39:28 olivierg Exp $ require_once 'Structures/DataGrid/Renderer/Common.php'; require_once 'HTML/Table.php'; @@ -49,7 +49,7 @@ * array(fieldName => array(attribute => value, ...) ... ) * * - * @version $Revision: 1.67 $ + * @version $Revision: 1.68 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @author Olivier Guilyardi <olivier@samalyse.com> * @author Mark Wiesemann <wiesemann@php.net> @@ -328,7 +328,8 @@ $get = array(); $get[$prefix . 'orderBy'] = $field; $get[$prefix . 'direction'] = $direction; - $get[$prefix . 'page'] = 1; + $get[$prefix . 'page'] + = $this->_options['sortingResetsPaging'] ? 1 : $this->_page; // Build Link URL $url = $this->_options['selfPath'] . '?'; @@ -468,7 +469,7 @@ ? $this->_totalRecordsNum : $this->_pageLimit, 'urlVar' => $this->_requestPrefix . 'page', - 'currentPage' => $this->_page); // FIXME + 'currentPage' => $this->_page); $options = array_merge($defaults, $options); $this->_pager =& Pager::factory($options); }
http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid.php?r1=1.26&r2=1.27&diff_format=u Index: pear/Structures_DataGrid/DataGrid.php diff -u pear/Structures_DataGrid/DataGrid.php:1.26 pear/Structures_DataGrid/DataGrid.php:1.27 --- pear/Structures_DataGrid/DataGrid.php:1.26 Sat Dec 31 00:34:04 2005 +++ pear/Structures_DataGrid/DataGrid.php Mon Jan 2 18:39:28 2006 @@ -13,10 +13,12 @@ // | 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: DataGrid.php,v 1.26 2005/12/31 00:34:04 olivierg Exp $ +// $Id: DataGrid.php,v 1.27 2006/01/02 18:39:28 olivierg Exp $ require_once 'PEAR.php'; @@ -68,8 +70,10 @@ * ?> * </code> * - * @version $Revision: 1.26 $ + * @version $Revision: 1.27 $ * @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 @@ -213,7 +217,7 @@ $file_name = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; if (!include_once($file_name)) { if (!Structures_DataGrid::fileExists($file_name)) { - $msg = "unable to find package '$classNname' file '$file_name'"; + $msg = "unable to find package '$className' file '$file_name'"; } else { $msg = "unable to load driver class '$className' from file '$file_name'"; } @@ -374,6 +378,11 @@ { if (is_subclass_of($renderer, 'structures_datagrid_renderer_common')) { $this->renderer =& $renderer; + if (isset ($this->_dataSource)) { + $this->renderer->setData($this->columnSet, $this->recordSet); + $this->renderer->setLimit($this->page, $this->rowLimit, + $this->getRecordCount()); + } } else { return new PEAR_Error('Invalid renderer type, ' . 'must be a valid renderer driver class'); @@ -577,6 +586,18 @@ { if (is_subclass_of($source, 'structures_datagrid_datasource_common')) { $this->_dataSource =& $source; + if (PEAR::isError($result = $this->fetchDataSource())) { + unset ($this->_dataSource); + return $result; + } + if ($columnSet = $this->_dataSource->getColumns()) { + $this->columnSet = array_merge($this->columnSet, $columnSet); + } + if (isset ($this->renderer)) { + $this->renderer->setData($this->columnSet, $this->recordSet); + $this->renderer->setLimit($this->page, $this->rowLimit, + $this->getRecordCount()); + } } else { return new PEAR_Error('Invalid data source type, ' . 'must be a valid data source driver class'); @@ -804,22 +825,10 @@ function build() { if (isset($this->_dataSource)) { - if (PEAR::isError($result = $this->fetchDataSource())) { - return $result; - } - - if ($columnSet = $this->_dataSource->getColumns()) { - $this->columnSet = array_merge($this->columnSet, $columnSet); - } - - //print_r ($this->recordSet); - //print_r ($this->columnSet); - if (!isset ($this->renderer)) { $this->loadDefaultRenderer(); } - $this->renderer->setData($this->columnSet, $this->recordSet); $this->renderer->build(); $this->_isBuilt = true; } http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/Common.php?r1=1.3&r2=1.4&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/Common.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.3 pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.4 --- pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.3 Sat Dec 31 00:34:04 2005 +++ pear/Structures_DataGrid/DataGrid/Renderer/Common.php Mon Jan 2 18:39:28 2006 @@ -17,10 +17,10 @@ // | Olivier Guilyardi <olivier@samalyse.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.3 2005/12/31 00:34:04 olivierg Exp $ +// $Id: Common.php,v 1.4 2006/01/02 18:39:28 olivierg Exp $ /** - * Structures_DataGrid_Renderer Class + * Structures_DataGrid_Renderer_Common Class * * Base class of all Renderer drivers * @@ -55,7 +55,7 @@ * added * * - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * @author Olivier Guilyardi <olivier@samalyse.com> * @access public * @package Structures_DataGrid @@ -235,9 +235,10 @@ $this->_currentSortDirection = $direction; } - function setLimit($currentPage, $rowPerPage) { + function setLimit($currentPage, $rowsPerPage, $totalRowNum) { $this->_page = $currentPage; - $this->_pageLimit = $rowPerPage; + $this->_pageLimit = $rowsPerPage; + $this->_totalRecordsNum = $totalRowNum; } function init () @@ -291,32 +292,22 @@ $this->_columns[$index] = compact('field','label'); } - + if ($this->_records) { if (is_null ($this->_pageLimit)) { $this->_pageLimit = count ($this->_records); } - - assert('$this->_pageLimit >= count($this->_records)'); - - $offset = ($this->_page - 1) * $this->_pageLimit; - - for ($i = $offset; $i < $this->_pageLimit; $i++) { + + for ($i = 0; isset($this->_records[$i]) and $i < $this->_pageLimit; $i++) { $content = array (); foreach ($this->_columnObjects as $column) { $content[] = $column->recordToValue ($this->_records[$i]); } - $this->_records[$i - $offset] = $content; + $this->_records[$i] = $content; } - - $ii = count ($this->_records); - for ($i = $this->_pageLimit - $offset; $i < $ii; $i++) { - unset ($this->_records[$i]); - } - } - + $this->_columnsNum = count ($this->_columns); $this->_recordsNum = count ($this->_records); http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php?r1=1.67&r2=1.68&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.67 pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.68 --- pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.67 Sat Dec 31 00:36:16 2005 +++ pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php Mon Jan 2 18:39:28 2006 @@ -18,7 +18,7 @@ // | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: HTMLTable.php,v 1.67 2005/12/31 00:36:16 olivierg Exp $ +// $Id: HTMLTable.php,v 1.68 2006/01/02 18:39:28 olivierg Exp $ require_once 'Structures/DataGrid/Renderer/Common.php'; require_once 'HTML/Table.php'; @@ -49,7 +49,7 @@ * array(fieldName => array(attribute => value, ...) ... ) * * - * @version $Revision: 1.67 $ + * @version $Revision: 1.68 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @author Olivier Guilyardi <olivier@samalyse.com> * @author Mark Wiesemann <wiesemann@php.net> @@ -328,7 +328,8 @@ $get = array(); $get[$prefix . 'orderBy'] = $field; $get[$prefix . 'direction'] = $direction; - $get[$prefix . 'page'] = 1; + $get[$prefix . 'page'] + = $this->_options['sortingResetsPaging'] ? 1 : $this->_page; // Build Link URL $url = $this->_options['selfPath'] . '?'; @@ -468,7 +469,7 @@ ? $this->_totalRecordsNum : $this->_pageLimit, 'urlVar' => $this->_requestPrefix . 'page', - 'currentPage' => $this->_page); // FIXME + 'currentPage' => $this->_page); $options = array_merge($defaults, $options); $this->_pager =& Pager::factory($options); }