cvs: pear /Structures_DataGrid/DataGrid/DataSource DataObject.php

From: Date: Thu, 02 Mar 2006 00:52:36 +0000
Subject: cvs: pear /Structures_DataGrid/DataGrid/DataSource DataObject.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-38824@lists.php.net to get a copy of this message
olivierg Thu Mar 2 00:52:36 2006 UTC Modified files: /pear/Structures_DataGrid/DataGrid/DataSource DataObject.php Log: Added multiple field sorting support http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid/DataSource/DataObject.php?r1=1.24&r2=1.25&diff_format=u Index: pear/Structures_DataGrid/DataGrid/DataSource/DataObject.php diff -u pear/Structures_DataGrid/DataGrid/DataSource/DataObject.php:1.24 pear/Structures_DataGrid/DataGrid/DataSource/DataObject.php:1.25 --- pear/Structures_DataGrid/DataGrid/DataSource/DataObject.php:1.24 Wed Dec 21 11:10:13 2005 +++ pear/Structures_DataGrid/DataGrid/DataSource/DataObject.php Thu Mar 2 00:52:36 2006 @@ -17,7 +17,7 @@ // | Andrew Nagy <asnagy@webitecture.org> | // +----------------------------------------------------------------------+ // -// $Id: DataObject.php,v 1.24 2005/12/21 11:10:13 wiesemann Exp $ +// $Id: DataObject.php,v 1.25 2006/03/02 00:52:36 olivierg Exp $ require_once 'Structures/DataGrid/DataSource/Common.php'; @@ -38,7 +38,7 @@ * same kind of information as the "fields" options. If the "fields" * option is set, this one will not be used. Default : "fb_fieldsToRender". * - * @version $Revision: 1.24 $ + * @version $Revision: 1.25 $ * @author Olivier Guilyardi <olivier@samalyse.com> * @author Andrew Nagy <asnagy@webitecture.org> * @access public @@ -76,12 +76,15 @@ function Structures_DataGrid_DataSource_DataObject() { parent::Structures_DataGrid_DataSource_Common(); + $this->_addDefaultOptions(array( 'use_private_vars' => false, 'labels_property' => 'fb_fieldLabels', 'fields_property' => 'fb_fieldsToRender', 'sort_property' => 'fb_linkOrderFields', 'formbuilder_integration' => false)); + + $this->_addFeatures(array('multiSort' => true)); } /** @@ -160,12 +163,15 @@ * * @param integer $offset Limit offset (starting from 0) * @param integer $len Limit length - * @param string $sortField Field to sort by + * @param mixed $sortSpec A single field (string) to sort by, or a + * sort specification array of the form : + * array(field => direction, ...) * @param string $sortDir Sort direction : 'ASC' or 'DESC' + * This is ignored if $sortDesc is an array * @access public * @return array The 2D Array of the records */ - function &fetch($offset=0, $len=null, $sortField=null, $sortDir='ASC') + function &fetch($offset=0, $len=null, $sortSpec=null, $sortDir='ASC') { // Check to see if Query has already been submitted if ($this->_dataobject->_DB_resultid != '') { @@ -179,8 +185,8 @@ } // Sorting - if ($sortField) { - $this->sort($sortField, $sortDir); + if ($sortSpec) { + $this->sort($sortSpec, $sortDir); } elseif (($sortProperty = $this->_options['sort_property']) && isset($this->_dataobject->$sortProperty)) { foreach ($this->_dataobject->$sortProperty as $sort) { @@ -279,15 +285,24 @@ * Sorts the dataobject. This MUST be called before fetch. * * @access public - * @param string $sortField Field to sort by + * @param mixed $sortSpec A single field (string) to sort by, or a + * sort specification array of the form : + * array(field => direction, ...) * @param string $sortDir Sort direction : 'ASC' or 'DESC' + * This is ignored if $sortDesc is an array */ - function sort($sortField, $sortDir = null) + function sort($sortSpec, $sortDir = null) { - if (is_null ($sortDir)) { - $this->_dataobject->orderBy($sortField); + if (is_array($sortSpec)) { + foreach ($sortSpec as $item) { + $this->_dataobject->orderBy($item['field'].' '.$item['direction']); + } } else { - $this->_dataobject->orderBy($sortField . ' ' . $sortDir); + if (is_null ($sortDir)) { + $this->_dataobject->orderBy($sortSpec); + } else { + $this->_dataobject->orderBy($sortSpec . ' ' . $sortDir); + } } }

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