cvs: pear /Structures_DataGrid DataGrid.php /Structures_DataGrid/DataGrid Renderer.php /Structures_DataGrid/DataGrid/Renderer HTMLTable.php

From: Date: Thu, 16 Mar 2006 14:05:48 +0000
Subject: cvs: pear /Structures_DataGrid DataGrid.php /Structures_DataGrid/DataGrid Renderer.php /Structures_DataGrid/DataGrid/Renderer HTMLTable.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-39124@lists.php.net to get a copy of this message
olivierg Thu Mar 16 14:05:48 2006 UTC Modified files: /pear/Structures_DataGrid DataGrid.php /pear/Structures_DataGrid/DataGrid Renderer.php /pear/Structures_DataGrid/DataGrid/Renderer HTMLTable.php Log: Refactored paging : - moved _buildPaging() into Renderer_Common - made getPaging() an abstract method that all drivers may implement - added a handy DataGrid::getPaging() method

http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid.php?r1=1.47&r2=1.48&diff_format=u Index: pear/Structures_DataGrid/DataGrid.php diff -u pear/Structures_DataGrid/DataGrid.php:1.47 pear/Structures_DataGrid/DataGrid.php:1.48 --- pear/Structures_DataGrid/DataGrid.php:1.47 Thu Mar 16 13:07:05 2006 +++ pear/Structures_DataGrid/DataGrid.php Thu Mar 16 14:05:48 2006 @@ -18,7 +18,7 @@ // | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: DataGrid.php,v 1.47 2006/03/16 13:07:05 olivierg Exp $ +// $Id: DataGrid.php,v 1.48 2006/03/16 14:05:48 olivierg Exp $ require_once 'PEAR.php'; @@ -75,7 +75,7 @@ * ?> * </code> * - * @version $Revision: 1.47 $ + * @version $Revision: 1.48 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @author Olivier Guilyardi <olivier@samalyse.com> * @author Mark Wiesemann <wiesemann@php.net> @@ -1076,6 +1076,35 @@ return PEAR::raiseError('Unable to set options ; No datasource loaded.'); } } + + /** + * Return paging links + * + * This method will return paging links if the renderer driver supports + * generating them. + * + * Useful options (See Pager's documentation for more) : + * mode : The mode of pager to use + * separator : The string to use to separate each page link + * prevImg : The string for the previous page link + * nextImg : The string for the forward page link + * delta : The number of pages to display before and + * after the current page + * + * Notice : Some drivers may not use HTML::Pager. In a such case, the above + * options may not be supported. See the driver-specific documentation for + * more. + * + * @param array $options Paging options as supported by the driver + * @return mixed Links as a string, array,... (driver-specific) + * or a PEAR_Error if not implemented + * @access public + */ + function getPaging($options = array()) + { + isset($this->_renderer) or $this->setRenderer(DATAGRID_RENDER_DEFAULT); + return $this->_renderer->getPaging($options); + } } ?> http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer.php?r1=1.33&r2=1.34&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer.php diff -u pear/Structures_DataGrid/DataGrid/Renderer.php:1.33 pear/Structures_DataGrid/DataGrid/Renderer.php:1.34 --- pear/Structures_DataGrid/DataGrid/Renderer.php:1.33 Thu Mar 16 13:07:05 2006 +++ pear/Structures_DataGrid/DataGrid/Renderer.php Thu Mar 16 14:05:48 2006 @@ -17,7 +17,7 @@ // | Olivier Guilyardi <olivier@samalyse.com> | // +----------------------------------------------------------------------+ // -// $Id: Renderer.php,v 1.33 2006/03/16 13:07:05 olivierg Exp $ +// $Id: Renderer.php,v 1.34 2006/03/16 14:05:48 olivierg Exp $ require_once 'PHP/Compat/Function/http_build_query.php'; @@ -58,6 +58,7 @@ * - finalize() * - flatten() * - render() + * - getPaging() * * Properties (all read-only) : * - $_columns @@ -77,7 +78,7 @@ * - fillWithEmptyRows * - numberAlign * - * @version $Revision: 1.33 $ + * @version $Revision: 1.34 $ * @author Olivier Guilyardi <olivier@samalyse.com> * @access public * @package Structures_DataGrid @@ -836,6 +837,74 @@ } } + /** + * Return paging links as generated by the driver + * + * Drivers that need paging should implement this method. It is not meant + * to be HTML specific, it can return anything that the user can use to + * provide a paging mechanism. + * + * @param array $options Paging options as supported by the driver (these + * usually are HTML::Pager options, but can be other + * sort of options, if the driver implements paging + * without HTML::Pager) + * @return mixed Links as a string, array,... (driver-specific) + * or a PEAR_Error if not implemented + * @access public + * @abstract + */ + function getPaging($options = array()) + { + return $this->_noSupport(__FUNCTION__); + } + + /** + * Generate the Pager object + * + * This is useful for drivers that need to provide a paging feature. This + * method sets up the $_pager protected property according to the $_page, + * $_pageLimit and $_totalRecordsNum properties. + * + * This method takes the global "excludeVars", "includeVars" options as + * well as the $_requestPrefix property into account. + * + * It is a somewhat HTML specific method, but since Pager offers a wide + * range of methods, chances are that the generated $_pager property + * can be used for non-HTML rendering. + * + * @param array $options Array of HTML::Pager options + * @access private + * @return void + */ + function _buildPaging($options) + { + require_once 'Pager/Pager.php'; + + $defaults = array('totalItems' => $this->_totalRecordsNum, + 'perPage' => is_null($this->_pageLimit) + ? $this->_totalRecordsNum + : $this->_pageLimit, + 'urlVar' => $this->_requestPrefix . 'page', + 'currentPage' => $this->_page); + + $options = array_merge($defaults, $options); + + if (isset ($options['extraVars'])) { + $options['extraVars'] = array_merge($options['extraVars'], + $this->_options['extraVars']); + } else { + $options['extraVars'] = $this->_options['extraVars']; + } + + if (isset ($options['excludeVars'])) { + $options['excludeVars'] = array_merge($options['excludeVars'], + $this->_options['excludeVars']); + } else { + $options['excludeVars'] = $this->_options['excludeVars']; + } + + $this->_pager =& Pager::factory($options); + } } ?> http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php?r1=1.94&r2=1.95&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.94 pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.95 --- pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.94 Thu Mar 16 12:37:20 2006 +++ pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php Thu Mar 16 14:05:48 2006 @@ -18,7 +18,7 @@ // | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: HTMLTable.php,v 1.94 2006/03/16 12:37:20 olivierg Exp $ +// $Id: HTMLTable.php,v 1.95 2006/03/16 14:05:48 olivierg Exp $ require_once 'Structures/DataGrid/Renderer.php'; require_once 'HTML/Table.php'; @@ -51,7 +51,7 @@ * - sortingResetsPaging: whether sorting HTTP queries reset paging * (default : true) * - * @version $Revision: 1.94 $ + * @version $Revision: 1.95 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @author Olivier Guilyardi <olivier@samalyse.com> * @author Mark Wiesemann <wiesemann@php.net> @@ -475,73 +475,55 @@ /** * Handles the building of the page list for the DataGrid in HTML. + * * This method uses the HTML::Pager class * + * Useful options (See Pager's documentation for more) : + * mode : The mode of pager to use + * separator : The string to use to separate each page link + * prevImg : The string for the previous page link + * nextImg : The string for the forward page link + * delta : The number of pages to display before and + * after the current page + * * @access public - * @param string $mode The mode of pager to use - * @param string $separator The string to use to separate each page link - * @param string $prev The string for the previous page link - * @param string $next The string for the forward page link - * @param string $delta The number of pages to display before and - * after the current page - * @param array $attrs Additional attributes for the Pager class - * @return string The HTML for the page links + * @param array $options Array of HTML::Pager options + * @return string The HTML for the page links * @see HTML::Pager */ - function getPaging($mode = 'Sliding', $separator = '|', $prev = '<<', - $next = '>>', $delta = 5, $attrs = null) + function getPaging($options = array()) { - require_once 'Pager/Pager.php'; - - // Generate Paging - $options = array('mode' => $mode, - 'delta' => $delta, - 'separator' => $separator, - 'prevImg' => $prev, - 'nextImg' => $next); - - if (is_array($attrs)) { - $options = array_merge($options, $attrs); - } - - if (isset ($options['extraVars'])) { - $options['extraVars'] = array_merge($options['extraVars'], - $this->_options['extraVars']); - } else { - $options['extraVars'] = $this->_options['extraVars']; - } - - if (isset ($options['excludeVars'])) { - $options['excludeVars'] = array_merge($options['excludeVars'], - $this->_options['excludeVars']); - } else { - $options['excludeVars'] = $this->_options['excludeVars']; + $defaults = array('mode' => 'Sliding', + 'delta' => 5, + 'separator' => '|', + 'prevImg' => '<<', + 'nextImg' => '>>'); + + // This is a BC workaround for the old version of this method + // FIXME: needs testing + if (is_string($options)) { + $argsNum = func_get_args(); + $args = func_get_args(); + for ($i = 0; $i < $argsNum; $i++) { + switch ($i) { + case 0 : $options['mode'] = $args[$i]; break; + case 1 : $options['separator'] = $args[$i]; break; + case 2 : $options['prevImg'] = $args[$i]; break; + case 3 : $options['nextImg'] = $args[$i]; break; + case 4 : $options['delta'] = $args[$i]; break; + case 5 : $options = array_merge($options, $args[$i]); break; + } + } } - + + $options = array_merge($defaults, $options); + $this->_buildPaging($options); // Return paging html return $this->_pager->links; } - /** - * Handles generating the paging object - * - * @param array $options Array of HTML::Pager options - * @access private - * @return void - */ - function _buildPaging($options) - { - $defaults = array('totalItems' => $this->_totalRecordsNum, - 'perPage' => is_null($this->_pageLimit) - ? $this->_totalRecordsNum - : $this->_pageLimit, - 'urlVar' => $this->_requestPrefix . 'page', - 'currentPage' => $this->_page); - $options = array_merge($defaults, $options); - $this->_pager =& Pager::factory($options); - } } ?>
« previous php.pear.cvs (#39124) next »