cvs: pear /Structures_DataGrid DataGrid.php
| From: | Olivier Guilyardi | Date: | Thu, 02 Mar 2006 01:28:30 +0000 |
| Subject: | cvs: pear /Structures_DataGrid DataGrid.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-38825@lists.php.net to get a copy of this message | ||
olivierg Thu Mar 2 01:28:30 2006 UTC
Modified files:
/pear/Structures_DataGrid DataGrid.php
Log:
Simplified the array structure
http://cvs.php.net/viewcvs.cgi/pear/Structures_DataGrid/DataGrid.php?r1=1.42&r2=1.43&diff_format=u
Index: pear/Structures_DataGrid/DataGrid.php
diff -u pear/Structures_DataGrid/DataGrid.php:1.42 pear/Structures_DataGrid/DataGrid.php:1.43
--- pear/Structures_DataGrid/DataGrid.php:1.42 Wed Mar 1 15:16:08 2006
+++ pear/Structures_DataGrid/DataGrid.php Thu Mar 2 01:28:30 2006
@@ -18,7 +18,7 @@
// | Mark Wiesemann <wiesemann@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: DataGrid.php,v 1.42 2006/03/01 15:16:08 olivierg Exp $
+// $Id: DataGrid.php,v 1.43 2006/03/02 01:28:30 olivierg Exp $
require_once 'PEAR.php';
@@ -72,7 +72,7 @@
* ?>
* </code>
*
- * @version $Revision: 1.42 $
+ * @version $Revision: 1.43 $
* @author Andrew S. Nagy <asnagy@webitecture.org>
* @author Olivier Guilyardi <olivier@samalyse.com>
* @author Mark Wiesemann <wiesemann@php.net>
@@ -113,14 +113,7 @@
/**
* 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
+ * @var array Form: array (fieldName => direction, ....)
* @access private
*/
var $sortSpec = array();
@@ -717,12 +710,13 @@
$page = $this->page ? $this->page - 1 : 0;
// Fetch the Data
- if ($this->sortSpec) {
+ reset($this->sortSpec);
+ if (list($field,$direction) = each($this->sortSpec)) {
$recordSet = $this->_dataSource->fetch(
($page * $this->rowLimit),
- $this->rowLimit,
- $this->sortSpec[0]['field'],
- $this->sortSpec[0]['direction']);
+ $this->rowLimit,
+ $field,
+ $direction);
} else {
$recordSet = $this->_dataSource->fetch(
($page * $this->rowLimit),
@@ -786,10 +780,12 @@
*/
function sortRecordSet($sortBy, $direction = 'ASC')
{
- $this->sortSpec = array(array('field' => $sortBy, 'direction'
=> $direction));
+ $this->sortSpec = array($sortBy => $direction);
if ($this->_dataSource) {
$this->_dataSource->sort($sortBy, $direction);
} else {
+ $this->_sortCallbackField = $sortBy;
+ $this->_sortCallbackDirection = $direction;
usort($this->recordSet, array($this, '_sort'));
}
}
@@ -804,9 +800,9 @@
*/
function _sort($a, $b)
{
- $bool = strnatcasecmp($a[$this->sortSpec[0]['field']],
$b[$this->sortSpec[0]['field']]);
+ $bool = strnatcasecmp($a[$this->_sortCallbackField], $b[$this->_sortCallbackField]);
- if ($this->sortSpec[0]['direction'] == 'DESC') {
+ if ($this->_sortCallbackDirection == 'DESC') {
$bool = $bool * -1;
}
@@ -844,27 +840,33 @@
}
}
+ $orderBy = '';
if (isset($_REQUEST[$prefix . 'orderBy'])) {
// Use POST, GET, or COOKIE value in respective order
if (isset($_POST[$prefix . 'orderBy'])) {
- $this->sortSpec[0]['field'] = $_POST[$prefix . 'orderBy'];
+ $orderBy = $_POST[$prefix . 'orderBy'];
} elseif (isset($_GET[$prefix . 'orderBy'])) {
- $this->sortSpec[0]['field'] = $_GET[$prefix . 'orderBy'];
+ $orderBy = $_GET[$prefix . 'orderBy'];
} elseif (isset($_COOKIE[$prefix . 'orderBy'])) {
- $this->sortSpec[0]['field'] = $_COOKIE[$prefix . 'orderBy'];
+ $orderBy = $_COOKIE[$prefix . 'orderBy'];
}
}
+ $direction = 'ASC';
if (isset($_REQUEST[$prefix . 'direction'])) {
// Use POST, GET, or COOKIE value in respective order
if (isset($_POST[$prefix . 'direction'])) {
- $this->sortSpec[0]['direction'] = $_POST[$prefix .
'direction'];
+ $direction = $_POST[$prefix . 'direction'];
} elseif (isset($_GET[$prefix . 'direction'])) {
- $this->sortSpec[0]['direction'] = $_GET[$prefix .
'direction'];
+ $direction = $_GET[$prefix . 'direction'];
} elseif (isset($_COOKIE[$prefix . 'direction'])) {
- $this->sortSpec[0]['direction'] = $_COOKIE[$prefix .
'direction'];
+ $direction = $_COOKIE[$prefix . 'direction'];
}
}
+
+ if ($orderBy) {
+ $this->sortSpec[$orderBy] = $direction;
+ }
}
/**