cvs: pear /Structures_DataGrid package2-ds-dbquery.xml /Structures_DataGrid/DataGrid/DataSource DBQuery.php
| From: | Olivier Guilyardi | Date: | Fri, 23 Jun 2006 20:55:57 +0000 |
| Subject: | cvs: pear /Structures_DataGrid package2-ds-dbquery.xml /Structures_DataGrid/DataGrid/DataSource DBQuery.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-40880@lists.php.net to get a copy of this message | ||
olivierg Fri Jun 23 20:55:57 2006 UTC
Modified files:
/pear/Structures_DataGrid package2-ds-dbquery.xml
/pear/Structures_DataGrid/DataGrid/DataSource DBQuery.php
Log:
added multiSort
http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/package2-ds-dbquery.xml?r1=1.6&r2=1.7&diff_format=u
Index: pear/Structures_DataGrid/package2-ds-dbquery.xml
diff -u pear/Structures_DataGrid/package2-ds-dbquery.xml:1.6
pear/Structures_DataGrid/package2-ds-dbquery.xml:1.7
--- pear/Structures_DataGrid/package2-ds-dbquery.xml:1.6 Thu Jun 22 17:27:41 2006
+++ pear/Structures_DataGrid/package2-ds-dbquery.xml Fri Jun 23 20:55:56 2006
@@ -30,8 +30,8 @@
<date>2006-06-22</date>
<time>19:23:00</time>
<version>
- <release>0.1.1</release>
- <api>0.1.0</api>
+ <release>0.1.2</release>
+ <api>0.1.1</api>
</version>
<stability>
<release>beta</release>
@@ -39,8 +39,7 @@
</stability>
<license uri="http://www.php.net/license">PHP
License</license>
<notes>
-- Fixed request #7965 'Please reintroduce sorting in DBQuery or MDB2'
- Thanks Benny Labach (bennythebee at gmail dot com)
+ - added multiple fields sorting support (multiSort)
</notes>
<contents>
http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/DataGrid/DataSource/DBQuery.php?r1=1.10&r2=1.11&diff_format=u
Index: pear/Structures_DataGrid/DataGrid/DataSource/DBQuery.php
diff -u pear/Structures_DataGrid/DataGrid/DataSource/DBQuery.php:1.10
pear/Structures_DataGrid/DataGrid/DataSource/DBQuery.php:1.11
--- pear/Structures_DataGrid/DataGrid/DataSource/DBQuery.php:1.10 Thu Jun 22 17:00:01 2006
+++ pear/Structures_DataGrid/DataGrid/DataSource/DBQuery.php Fri Jun 23 20:55:57 2006
@@ -17,7 +17,7 @@
// | Mark Wiesemann <wiesemann@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: DBQuery.php,v 1.10 2006/06/22 17:00:01 olivierg Exp $
+// $Id: DBQuery.php,v 1.11 2006/06/23 20:55:57 olivierg Exp $
require_once 'DB.php';
require_once 'Structures/DataGrid/DataSource.php';
@@ -28,7 +28,7 @@
*
* This class is a data source driver for the PEAR::DB object
*
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
* @author Andrew S. Nagy <asnagy@php.net>
* @author Mark Wiesemann <wiesemann@php.net>
* @access public
@@ -55,22 +55,14 @@
var $_query;
/**
- * The field to sort by
+ * Fields/directions to sort the data by
*
- * @var string
+ * @var array Structure: array(fieldName => direction, ....)
* @access private
*/
- var $_sortField;
+ var $_sortSpec = array();
/**
- * The direction to sort by
- *
- * @var string
- * @access private
- */
- var $_sortDir;
-
- /**
* Constructor
*
* @access public
@@ -78,6 +70,11 @@
function Structures_DataGrid_DataSource_DBQuery()
{
parent::Structures_DataGrid_DataSource();
+
+ // FIXME: For clarity, supported options should be declared with
+ // _addDefaultOptions()
+
+ $this->_setFeatures(array('multiSort' => true));
}
/**
@@ -132,9 +129,11 @@
*/
function &fetch($offset=0, $limit=null)
{
- if (!is_null($this->_sortField) && !is_null($this->_sortDir)) {
- $sortString = ' ORDER BY '. $this->_sortField .
- ' ' . $this->_sortDir;
+ if (!empty($this->_sortSpec)) {
+ foreach ($this->_sortSpec as $field => $direction) {
+ $sortArray[] = "$field $direction";
+ }
+ $sortString = ' ORDER BY '. join(', ', $sortArray);
} else {
$sortString = '';
}
@@ -223,10 +222,13 @@
* @param string $sortField Field to sort by
* @param string $sortDir Sort direction: 'ASC' or 'DESC'
*/
- function sort($sortField, $sortDir)
+ function sort($sortSpec, $sortDir = 'ASC')
{
- $this->_sortField = $sortField;
- $this->_sortDir = $sortDir;
+ if (is_array($sortSpec)) {
+ $this->_sortSpec = $sortSpec;
+ } else {
+ $this->_sortSpec[$sortSpec] = $sortDir;
+ }
}