cvs: pear /Structures_DataGrid package2-ds-array.xml /Structures_DataGrid/DataGrid/DataSource Array.php

From: Date: Wed, 12 Sep 2007 21:05:10 +0000
Subject: cvs: pear /Structures_DataGrid package2-ds-array.xml /Structures_DataGrid/DataGrid/DataSource Array.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-48595@lists.php.net to get a copy of this message
wiesemann Wed Sep 12 21:05:10 2007 UTC Modified files: /pear/Structures_DataGrid package2-ds-array.xml /pear/Structures_DataGrid/DataGrid/DataSource Array.php Log: - Request #12018: new option 'natsort' allows natural sorting of data; e.g. 'example1, Example2, test1, Test2' vs. 'Example2, Test2, example1, test1' (default sorting, capital letters will come first) - Bug #12020: arrays with non-continuous keys are now - add some documentation for the Array driver - update changelog http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/package2-ds-array.xml?r1=1.9&r2=1.10&diff_format=u Index: pear/Structures_DataGrid/package2-ds-array.xml diff -u pear/Structures_DataGrid/package2-ds-array.xml:1.9 pear/Structures_DataGrid/package2-ds-array.xml:1.10 --- pear/Structures_DataGrid/package2-ds-array.xml:1.9 Wed Jan 24 19:55:53 2007 +++ pear/Structures_DataGrid/package2-ds-array.xml Wed Sep 12 21:05:09 2007 @@ -27,11 +27,11 @@ <email>wiesemann@php.net</email> <active>yes</active> </lead> - <date>2007-01-24</date> - <time>20:55:00</time> + <date>?</date> + <time>?</time> <version> - <release>0.1.2</release> - <api>0.1.0</api> + <release>0.1.3</release> + <api>0.1.1</api> </version> <stability> <release>beta</release> @@ -39,8 +39,13 @@ </stability> <license uri="http://opensource.org/licenses/bsd-license.php">New BSD</license> <notes> -- Bug #9914: removed the (wrong) assumption that always an array index 0 exists - (thanks to Rob, rjbarbour at gmail dot com) +- Request #12018: new option 'natsort' allows natural sorting of data; e.g. + 'example1, Example2, test1, Test2' vs. 'Example2, Test2, example1, test1' + (default sorting, capital letters will come first) +- Bug #12020: arrays with non-continuous keys are now + +The new option and the bug fix also affect the following DataSource drivers: +CSV, DB (not DBQuery!), Excel, RSS, XML </notes> <contents> <dir name="/"> http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/DataGrid/DataSource/Array.php?r1=1.30&r2=1.31&diff_format=u Index: pear/Structures_DataGrid/DataGrid/DataSource/Array.php diff -u pear/Structures_DataGrid/DataGrid/DataSource/Array.php:1.30 pear/Structures_DataGrid/DataGrid/DataSource/Array.php:1.31 --- pear/Structures_DataGrid/DataGrid/DataSource/Array.php:1.30 Wed Jan 24 19:55:53 2007 +++ pear/Structures_DataGrid/DataGrid/DataSource/Array.php Wed Sep 12 21:05:09 2007 @@ -35,9 +35,9 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * CSV file id: $Id: Array.php,v 1.30 2007/01/24 19:55:53 wiesemann Exp $ + * CSV file id: $Id: Array.php,v 1.31 2007/09/12 21:05:09 wiesemann Exp $ * - * @version $Revision: 1.30 $ + * @version $Revision: 1.31 $ * @package Structures_DataGrid_DataSource_Array * @category Structures * @license http://opensource.org/licenses/bsd-license.php New BSD License @@ -48,9 +48,32 @@ /** * Array Data Source Driver * - * This class is a data source driver for a 2D Array + * This class is a data source driver for a 2D array * - * @version $Revision: 1.30 $ + * SUPPORTED OPTIONS: + * + * - natsort: (boolean) Whether the array should be sorted naturally (e.g. + * example1, Example2, test1, Test2) or not (e.g. + * Example2, Test2, example1, test1; i.e. capital + * letters will come first). + * + * GENERAL NOTES: + * + * This driver expects an array of the following form: + * <code> + * $data = array(0 => array('col0' => 'val00', 'col1' => 'val01', ...), + * 1 => array('col0' => 'val10', 'col1' => 'val11', ...), + * ... + * ); + * </code> + * + * The first level of this array contains one entry for each row. For every + * row entry an array with the data for this row is expected. Such an array + * contains the field names as the keys. For example, 'val01' is the value + * of the column with the field name 'col1' in the first row. Row numbers + * start with 0, not with 1. + * + * @version $Revision: 1.31 $ * @author Olivier Guilyardi <olivier@samalyse.com> * @author Andrew Nagy <asnagy@webitecture.org> * @author Mark Wiesemann <wiesemann@php.net> @@ -72,6 +95,7 @@ function Structures_DataGrid_DataSource_Array() { parent::Structures_DataGrid_DataSource(); + $this->_addDefaultOptions(array('natsort' => false)); } /** @@ -88,7 +112,14 @@ } if (is_array($ar)) { - $this->_ar = $ar; + // if the array keys are non-continuous, reset the array keys to + // ensure correct sorting + $keys = array_keys($ar); + if (count($ar) != max($keys) + 1) { + $this->_ar = array_values($ar); + } else { + $this->_ar = $ar; + } return true; } else { return PEAR::raiseError('The provided source must be an array'); @@ -168,6 +199,9 @@ $sortDir = (is_null($sortDir) or strtoupper($sortDir) == 'ASC') ? SORT_ASC : SORT_DESC; + if ($this->_options['natsort']) { + $sortAr = array_map('strtolower', $sortAr); + } array_multisort($sortAr, $sortDir, $this->_ar); } }

« previous php.pear.cvs (#48595) next »