Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX Added Fixing deprecated usage of array_multisort for php 5.3

It worked by accident in php 5.2, see https://bugs.php.net/bug.php?id=49241
  • Loading branch information...
commit bf73265252f7cef6091fad482bbb4c1ef02bd989 1 parent 2101d3c
Stig Lindqvist authored
Showing with 21 additions and 20 deletions.
  1. +21 −20 model/ArrayList.php
View
41 model/ArrayList.php
@@ -70,6 +70,7 @@ public function remove($item) {
*
* @param array|object $item
* @param array|object $with
+ * @return void;
*/
public function replace($item, $with) {
foreach ($this->items as $key => $candidate) {
@@ -100,7 +101,7 @@ public function removeDuplicates($field = 'ID') {
$seen = array();
foreach ($this->items as $key => $item) {
- $value = $this->extract($item, $field);
+ $value = $this->extractValue($item, $field);
if (array_key_exists($value, $seen)) {
unset($this->items[$key]);
@@ -157,21 +158,21 @@ public function last() {
public function map($keyfield, $titlefield) {
$map = array();
foreach ($this->items as $item) {
- $map[$this->extract($item, $keyfield)] = $this->extract($item, $titlefield);
+ $map[$this->extractValue($item, $keyfield)] = $this->extractValue($item, $titlefield);
}
return $map;
}
public function find($key, $value) {
foreach ($this->items as $item) {
- if ($this->extract($item, $key) == $value) return $item;
+ if ($this->extractValue($item, $key) == $value) return $item;
}
}
public function column($field = 'ID') {
$result = array();
foreach ($this->items as $item) {
- $result[] = $this->extract($item, $field);
+ $result[] = $this->extractValue($item, $field);
}
return $result;
}
@@ -185,28 +186,28 @@ public function canSortBy($by) {
* field name and direction, or a map of field names to sort directions.
*
* @param string|array $by
- * @param string $dir
- * @see SS_List::sort()
+ * @param string $sortDirection
+ * @see SS_List::sort()
+ * @link http://php.net/manual/en/function.array-multisort.php
+ * @example $list->sort('Name', 'ASC');
+ * @example $list->sort(array('Name'=>'ASC,'Age'=>'DESC');
*/
- public function sort($by, $dir = 'ASC') {
+ public function sort($by, $sortDirection = 'ASC') {
$sorts = array();
- if (!is_array($by)) {
- $by = array($by => $dir);
+ if(!is_array($by)) {
+ $by = array($by => $sortDirection);
}
- foreach ($by as $field => $dir) {
- $dir = strtoupper($dir) == 'DESC' ? SORT_DESC : SORT_ASC;
- $vals = array();
-
- foreach ($this->items as $item) {
- $vals[] = $this->extract($item, $field);
+ foreach ($by as $field => $sortDirection) {
+ $sortDirection = strtoupper($sortDirection) == 'DESC' ? SORT_DESC : SORT_ASC;
+ $values = array();
+ foreach($this->items as $item) {
+ $values[] = $this->extractValue($item, $field);
}
-
- $sorts[] = $vals;
- $sorts[] = $dir;
+ $sorts[] = &$values;
+ $sorts[] = &$sortDirection;
}
-
$sorts[] = &$this->items;
call_user_func_array('array_multisort', $sorts);
}
@@ -235,7 +236,7 @@ public function offsetUnset($offset) {
* @param string $key
* @return mixed
*/
- protected function extract($item, $key) {
+ protected function extractValue($item, $key) {
if (is_object($item)) {
return $item->$key;
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.