cvs: pear /Structures_DataGrid DataGrid.php package.xml /Structures_DataGrid/DataGrid/Renderer Common.php HTMLTable.php XUL.php

From: Date: Wed, 01 Mar 2006 15:16:08 +0000
Subject: cvs: pear /Structures_DataGrid DataGrid.php package.xml /Structures_DataGrid/DataGrid/Renderer Common.php HTMLTable.php XUL.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-38788@lists.php.net to get a copy of this message
olivierg Wed Mar 1 15:16:08 2006 UTC Modified files: /pear/Structures_DataGrid DataGrid.php package.xml /pear/Structures_DataGrid/DataGrid/Renderer Common.php HTMLTable.php XUL.php Log: Improved sorting support (more below...) - Added support for multiple fields sort at the core and renderer levels as mentionned in Req #4565 "Multiple field sort and record grouping" - The renderer interface now allows to make a difference between sortable and unsortable fields. The HTMLTable and XUL drivers support this. - Some cleanup in the buildBody() method of the HTMLTable driver

http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid.php?r1=1.41&r2=1.42&diff_format=u Index: pear/Structures_DataGrid/DataGrid.php diff -u pear/Structures_DataGrid/DataGrid.php:1.41 pear/Structures_DataGrid/DataGrid.php:1.42 --- pear/Structures_DataGrid/DataGrid.php:1.41 Mon Feb 27 22:41:37 2006 +++ pear/Structures_DataGrid/DataGrid.php Wed Mar 1 15:16:08 2006 @@ -18,7 +18,7 @@ // | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: DataGrid.php,v 1.41 2006/02/27 22:41:37 olivierg Exp $ +// $Id: DataGrid.php,v 1.42 2006/03/01 15:16:08 olivierg Exp $ require_once 'PEAR.php'; @@ -72,7 +72,7 @@ * ?> * </code> * - * @version $Revision: 1.41 $ + * @version $Revision: 1.42 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @author Olivier Guilyardi <olivier@samalyse.com> * @author Mark Wiesemann <wiesemann@php.net> @@ -111,12 +111,19 @@ var $_dataSource; /** - * An array of fields to sort by. Each field is an array of the field name - * and the direction, either ASC or DESC. + * Fields/directions to sort the data by + * + * This is an array of the form : + * array ( + * 0 => array ('field' => 'field1', 'direction' => 'ASC'), + * 1 => array ('field' => 'field2', 'direction' => 'DESC'), + * etc... + * ); + * * @var array * @access private */ - var $sortArray; + var $sortSpec = array(); /** * Limit of records to show per page. @@ -333,8 +340,8 @@ $driver->setRequestPrefix($this->_requestPrefix); } - if (isset($this->sortArray)) { - $driver->setCurrentSorting($this->sortArray[0], $this->sortArray[1]); + if ($this->sortSpec) { + $driver->setCurrentSorting($this->sortSpec); } return $driver; @@ -601,8 +608,8 @@ * to pass them again to the renderer */ $this->_renderer->setLimit($this->page, $this->rowLimit, $this->getRecordCount()); - if (isset($this->sortArray)) { - $this->_renderer->setCurrentSorting($this->sortArray[0], $this->sortArray[1]); + if ($this->sortSpec) { + $this->_renderer->setCurrentSorting($this->sortSpec); } } } @@ -710,10 +717,17 @@ $page = $this->page ? $this->page - 1 : 0; // Fetch the Data - $recordSet = $this->_dataSource->fetch( - ($page * $this->rowLimit), - $this->rowLimit, $this->sortArray[0], - $this->sortArray[1]); + if ($this->sortSpec) { + $recordSet = $this->_dataSource->fetch( + ($page * $this->rowLimit), + $this->rowLimit, + $this->sortSpec[0]['field'], + $this->sortSpec[0]['direction']); + } else { + $recordSet = $this->_dataSource->fetch( + ($page * $this->rowLimit), + $this->rowLimit); + } if (PEAR::isError($recordSet)) { return $recordSet; @@ -772,7 +786,7 @@ */ function sortRecordSet($sortBy, $direction = 'ASC') { - $this->sortArray = array($sortBy, $direction); + $this->sortSpec = array(array('field' => $sortBy, 'direction' => $direction)); if ($this->_dataSource) { $this->_dataSource->sort($sortBy, $direction); } else { @@ -790,9 +804,9 @@ */ function _sort($a, $b) { - $bool = strnatcasecmp($a[$this->sortArray[0]], $b[$this->sortArray[0]]); + $bool = strnatcasecmp($a[$this->sortSpec[0]['field']], $b[$this->sortSpec[0]['field']]); - if ($this->sortArray[1] == 'DESC') { + if ($this->sortSpec[0]['direction'] == 'DESC') { $bool = $bool * -1; } @@ -833,22 +847,22 @@ if (isset($_REQUEST[$prefix . 'orderBy'])) { // Use POST, GET, or COOKIE value in respective order if (isset($_POST[$prefix . 'orderBy'])) { - $this->sortArray[0] = $_POST[$prefix . 'orderBy']; + $this->sortSpec[0]['field'] = $_POST[$prefix . 'orderBy']; } elseif (isset($_GET[$prefix . 'orderBy'])) { - $this->sortArray[0] = $_GET[$prefix . 'orderBy']; + $this->sortSpec[0]['field'] = $_GET[$prefix . 'orderBy']; } elseif (isset($_COOKIE[$prefix . 'orderBy'])) { - $this->sortArray[0] = $_COOKIE[$prefix . 'orderBy']; + $this->sortSpec[0]['field'] = $_COOKIE[$prefix . 'orderBy']; } } if (isset($_REQUEST[$prefix . 'direction'])) { // Use POST, GET, or COOKIE value in respective order if (isset($_POST[$prefix . 'direction'])) { - $this->sortArray[1] = $_POST[$prefix . 'direction']; + $this->sortSpec[0]['direction'] = $_POST[$prefix . 'direction']; } elseif (isset($_GET[$prefix . 'direction'])) { - $this->sortArray[1] = $_GET[$prefix . 'direction']; + $this->sortSpec[0]['direction'] = $_GET[$prefix . 'direction']; } elseif (isset($_COOKIE[$prefix . 'direction'])) { - $this->sortArray[1] = $_COOKIE[$prefix . 'direction']; + $this->sortSpec[0]['direction'] = $_COOKIE[$prefix . 'direction']; } } } http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/package.xml?r1=1.41&r2=1.42&diff_format=u Index: pear/Structures_DataGrid/package.xml diff -u pear/Structures_DataGrid/package.xml:1.41 pear/Structures_DataGrid/package.xml:1.42 --- pear/Structures_DataGrid/package.xml:1.41 Thu Feb 23 14:09:36 2006 +++ pear/Structures_DataGrid/package.xml Wed Mar 1 15:16:08 2006 @@ -42,66 +42,85 @@ # is now required to use the Structures_DataGrid::getRenderer() method # # in order to access the renderer object. # ########################################################################## - - Req #4254 : - Completed integration of the DBTable datasource driver - Req #4379 : - Completed integration of the DBQuery datasource driver - Thanks Mark Wiesemann &lt;wiesemann at php dot net&gt; - Bug #4415 : + ########################################################################## + # BUGS # + ########################################################################## + + Bug #4415 "Docs directory goes into wrong directory" : Example files were installed in the package directory, now they will be installed into DOCS/Structures_DataGrid/docs/examples/ - Req #4709 : - Added support for grouping into &lt;thead&gt;, &lt;tfoot&gt; and &lt;tbody&gt; - (HTMLTable renderer) - Thanks Mark Wiesemann &lt;wiesemann at php dot net&gt; - - Bug #5723 : + Bug #5723 "Smarty Renderer Error" : Fixed the return value of Renderer_Smarty::getSmarty() Thanks &lt;adrian dot rotea at gmail dot com&gt; - Req #5758 : - New parameters for Structures_DataGrid_Column::formatter() callback: - 'fieldName', 'columnName', 'orderBy', 'attribs' - - Req #5806 and #5808 : - Added support for custom Excel Writer and Format objects - Thanks Vincent Vermersch for these requests - - Bug #5829 : + Bug #5829 "SDG 0.6.3 htmlentities make multibyte char unreadable" : The HTMLTable renderer is now compatible with multi-bytes caracters Thanks &lt;kenchou77 at gmail dot com&gt; - Bug #5858 : + Bug #5858 "do not use @ before include_once" : Removed @ before include() in DataSource.php (could crash silently) Thanks Mark Wiesemann &lt;wiesemann at php dot net&gt; - Bug #6582: + Bug #6582 "malfunction sort" : The method sort() in Array DataSource driver can no longer be called statically. (Not a BC break, as this should have been used only internal.) - Req #6621: - New method getColumnByName() that returns a reference to a column object. - - Bug #6624: + Bug #6624 "formatter doesn't handle parameters and object methods at the same time" : Column formatters using class names didn't handle parameters and class methods at the same time. - Bug #6031: + Bug #6031 "charset GB2312 display not correctly" : New HTMLTable "encoding" option (passed to htmlspecialchars()) Thanks digit_shine &lt;digit_shine at yahoo dot com dot cn&gt; - - Req #5838: + + ########################################################################## + # FEATURE REQUESTS # + ########################################################################## + + Req #4254 "New DataSource driver (DB_Table)" : + Completed integration of the DBTable datasource driver + + Req #4379 "New DataSource driver (DBQuery)" : + Completed integration of the DBQuery datasource driver + Thanks Mark Wiesemann &lt;wiesemann at php dot net&gt; + + Req #4709 "add &lt;thead&gt;, &lt;tfoot&gt;, &lt;tbody&gt; to HTMLTable renderer" : + Added support for grouping into &lt;thead&gt;, &lt;tfoot&gt; and &lt;tbody&gt; + (HTMLTable renderer) + Thanks Mark Wiesemann &lt;wiesemann at php dot net&gt; + + Req #5758 "Extra parameters for Structures_DataGrid_Column::formatter() callback" : + New parameters for Structures_DataGrid_Column::formatter() callback: + 'fieldName', 'columnName', 'orderBy', 'attribs' + + Req #5806 "XLS formatage des header automatique" : + Req #5808 "XLS rendering" : + Added support for custom Excel Writer and Format objects + Thanks Vincent Vermersch for these requests + + Req #6621 "get reference to column by name" : + New method getColumnByName() that returns a reference to a column object. + + Req #5838 "Reversion of: Bug #3601" : New HTMLTable "convertEntities" option Thanks &lt;abriening at comcast dot net&gt; - Req #5859: + Req #5859 "New renderer driver interface" : The rendering layer has gone through a long refactoring process and a new and flexible renderer driver interface has been implemented. - + + Req #4565 "Multiple field sort and record grouping" : + This request has not been implemented, but some improvements have been + made in order to support multiple field sorting in the future + + + ########################################################################## + # OTHER FIXES AND CHANGES # + ########################################################################## + Auto-alignment : The HTMLTable renderer now automatically aligns numeric values to the right. This is configurable with HTMLTable::setAutoAlign() @@ -131,6 +150,12 @@ "datasource container") which it fills with data. No data is output during this process. It is up to the user to decide what to do with the container once it's been filled up. + + Sortable and unsortable fields : + Better support for the $orderBy parameter of the Column constructor : + if it is null, then the corresponding column is considered unsortable, + which is taken into account by various renderer drivers (HTMLTable, XUL, + etc..) </notes> <deps> <dep type="pkg" rel="ge" version="1.2" optional="no">PEAR</dep> http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/Common.php?r1=1.17&r2=1.18&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/Common.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.17 pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.18 --- pear/Structures_DataGrid/DataGrid/Renderer/Common.php:1.17 Mon Feb 27 22:42:36 2006 +++ pear/Structures_DataGrid/DataGrid/Renderer/Common.php Wed Mar 1 15:16:08 2006 @@ -17,7 +17,7 @@ // | Olivier Guilyardi <olivier@samalyse.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.17 2006/02/27 22:42:36 olivierg Exp $ +// $Id: Common.php,v 1.18 2006/03/01 15:16:08 olivierg Exp $ /** * Structures_DataGrid_Renderer_Common Class @@ -56,7 +56,7 @@ * added * * - * @version $Revision: 1.17 $ + * @version $Revision: 1.18 $ * @author Olivier Guilyardi <olivier@samalyse.com> * @access public * @package Structures_DataGrid @@ -86,18 +86,19 @@ var $_container = null; /** - * Field which the data is currently sorted by - * @var string - * @access protected - */ - var $_currentSortField = null; - - /** - * Direction which the data is currently sorted in - * @var string + * Fields/directions the data is currently sorted by + * + * This is an array of the form : + * array ( + * 0 => array ('field' => 'field1', 'direction' => 'ASC'), + * 1 => array ('field' => 'field2', 'direction' => 'DESC'), + * etc... + * ); + * + * @var array * @access protected */ - var $_currentSortDirection = null; + var $_currentSort = array(); /** * Columns objects @@ -161,6 +162,14 @@ var $_isBuilt = false; /** + * Which fields the datagrid may be sorted by + * + * @var array Field names + * @access protected + */ + var $_sortableFields = array(); + + /** * Common and driver-specific options * * @var array @@ -259,14 +268,18 @@ /** * Specify how the datagrid is currently sorted * - * @param string $field Which field it is sorted by - * @param string $direction Direction (ASC|DESC) + * @param string $spec Which fields/directions it is sorted by + * This is an array of the form : + * array ( + * 0 => array ('field' => 'field1', 'direction' => 'ASC'), + * 1 => array ('field' => 'field2', 'direction' => 'DESC'), + * etc... + * ); * @access public */ - function setCurrentSorting($field, $direction) + function setCurrentSorting($spec) { - $this->_currentSortField = $field; - $this->_currentSortDirection = $direction; + $this->_currentSort = $spec; } /** @@ -403,10 +416,13 @@ $this->_columns = array(); foreach ($this->_columnObjects as $index => $column) { - if (isset($column->orderBy)) { + if (!is_null($column->orderBy)) { $field = $column->orderBy; - } else if (isset($column->field)) { - $field = $column->field; + if (!in_array($field,$this->_sortableFields)) { + $this->_sortableFields[] = $field; + } + } else if (!is_null($column->fieldName)) { + $field = $column->fieldName; } else { $field = $column->columnName; } http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php?r1=1.82&r2=1.83&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.82 pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.83 --- pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php:1.82 Tue Feb 28 10:48:08 2006 +++ pear/Structures_DataGrid/DataGrid/Renderer/HTMLTable.php Wed Mar 1 15:16:08 2006 @@ -18,7 +18,7 @@ // | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: HTMLTable.php,v 1.82 2006/02/28 10:48:08 wiesemann Exp $ +// $Id: HTMLTable.php,v 1.83 2006/03/01 15:16:08 olivierg Exp $ require_once 'Structures/DataGrid/Renderer/Common.php'; require_once 'HTML/Table.php'; @@ -54,7 +54,7 @@ * - encoding : the content encoding. Default: ISO-8859-1 * * - * @version $Revision: 1.82 $ + * @version $Revision: 1.83 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @author Olivier Guilyardi <olivier@samalyse.com> * @author Mark Wiesemann <wiesemann@php.net> @@ -308,6 +308,7 @@ function buildHeader() { $prefix = $this->_requestPrefix; + // Build the list of common get parameters $common = $this->_options['extraVars']; $ignore = $this->_options['excludeVars']; @@ -326,12 +327,20 @@ $label = $this->_columns[$col]['label']; // Define Content - if (!in_array($field, $this->_options['disableColumnSorting'])) { - // Determine Direction - if ($this->_currentSortField == $field && - $this->_currentSortDirection == 'ASC') { - $direction = 'DESC'; + if (in_array ($field, $this->_sortableFields) and + !in_array($field, $this->_options['disableColumnSorting'])) { + + // Determine next sort direction and current sort icon + if ($this->_currentSort and $this->_currentSort[0]['field'] == $field) { + if ($this->_currentSort[0]['direction'] == 'ASC') { + $icon = $this->_options['sortIconASC']; + $direction = 'DESC'; + } else { + $icon = $this->_options['sortIconDESC']; + $direction = 'ASC'; + } } else { + $icon = ''; $direction = 'ASC'; } @@ -349,15 +358,7 @@ $url .= http_build_query(array_merge($common, $get)); // Build HTML Link - $str = "<a href=\"$url\">$label"; - $iconVar = "sortIcon" . - (is_null($this->_currentSortDirection) ? 'ASC' : $this->_currentSortDirection); - if (($this->_options[$iconVar] != '') && - ($this->_currentSortField == $field)) { - $str .= ' ' . $this->_options[$iconVar]; - } - $str .= '</a>'; - + $str = "<a href=\"$url\">$label $icon</a>"; } else { $str = $label; } http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/Renderer/XUL.php?r1=1.16&r2=1.17&diff_format=u Index: pear/Structures_DataGrid/DataGrid/Renderer/XUL.php diff -u pear/Structures_DataGrid/DataGrid/Renderer/XUL.php:1.16 pear/Structures_DataGrid/DataGrid/Renderer/XUL.php:1.17 --- pear/Structures_DataGrid/DataGrid/Renderer/XUL.php:1.16 Mon Feb 27 22:47:21 2006 +++ pear/Structures_DataGrid/DataGrid/Renderer/XUL.php Wed Mar 1 15:16:08 2006 @@ -18,7 +18,7 @@ // | Mark Wiesemann <wiesemann@php.net> | // +----------------------------------------------------------------------+ // -// $Id: XUL.php,v 1.16 2006/02/27 22:47:21 olivierg Exp $ +// $Id: XUL.php,v 1.17 2006/03/01 15:16:08 olivierg Exp $ require_once 'Structures/DataGrid/Renderer/Common.php'; //require_once 'XML/XUL.php'; @@ -40,7 +40,7 @@ * - selfPath: (string) The complete path for sorting and paging links * (default: $_SERVER['PHP_SELF']) * - * @version $Revision: 1.16 $ + * @version $Revision: 1.17 $ * @author Andrew S. Nagy <asnagy@webitecture.org> * @author Olivier Guilyardi <olivier@samalyse.com> * @author Mark Wiesemann <wiesemann@php.net> @@ -150,34 +150,42 @@ $field = $this->_columns[$col]['field']; $label = $this->_columns[$col]['label']; - if ($this->_currentSortField == $field) { - if ($this->_currentSortDirection == 'ASC') { - // The data is currently sorted by $column, ascending. - // That means we want $dirArg set to 'DESC', for the next - // click to trigger a reverse order sort, and we need - // $dirCur set to 'ascending' so that a neat xul arrow - // shows the current "ASC" direction. - $dirArg = 'DESC'; - $dirCur = 'ascending'; + if (in_array($field, $this->_sortableFields)) { + if ($this->_currentSort and $this->_currentSort[0]['field'] == $field) { + if ($this->_currentSort[0]['direction'] == 'ASC') { + // The data is currently sorted by $column, ascending. + // That means we want $dirArg set to 'DESC', for the next + // click to trigger a reverse order sort, and we need + // $dirCur set to 'ascending' so that a neat xul arrow + // shows the current "ASC" direction. + $dirArg = 'DESC'; + $dirCur = 'ascending'; + } else { + // Next click will do ascending sort, and we show a reverse + // arrow because we're currently descending. + $dirArg = 'ASC'; + $dirCur = 'descending'; + } } else { - // Next click will do ascending sort, and we show a reverse - // arrow because we're currently descending. + // No current sort on this column. Next click will ascend. We + // show no arrow. $dirArg = 'ASC'; - $dirCur = 'descending'; + $dirCur = 'natural'; } + + $onCommand = + "oncommand=\"location.href='{$this->_options['selfPath']}". + "?{$this->_requestPrefix}orderBy=$field". + "&amp;{$this->_requestPrefix}direction=$dirArg';\""; + $sortDirection = "sortDirection=\"$dirCur\""; } else { - // No current sort on this column. Next click will ascend. We - // show no arrow. - $dirArg = 'ASC'; - $dirCur = 'natural'; + $onCommand = ''; + $sortDirection = ''; } - $onClick = "location.href='" . $this->_options['selfPath'] . - '?' . $this->_requestPrefix . 'orderBy=' . $field . - "&amp;" . $this->_requestPrefix . "direction=$dirArg';"; $label = XML_Util::replaceEntities($label); $this->_container .= ' <listheader label="' . $label . '" ' . - "sortDirection=\"$dirCur\" oncommand=\"$onClick\" />\n"; + "$sortDirection $onCommand />\n"; } $this->_container .= " </listhead>\n"; }
« previous php.pear.cvs (#38788) next »