mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
GroupedList: Enable grouping by a function result.
This commit is contained in:
parent
588118ade5
commit
c563caec05
@ -16,7 +16,9 @@ class GroupedList extends SS_ListDecorator {
|
|||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
foreach ($this->list as $item) {
|
foreach ($this->list as $item) {
|
||||||
$key = is_object($item) ? $item->$index : $item[$index];
|
/* if $item is an Object, $index can be a method or a value,
|
||||||
|
* if $item is an array, $index is used as the index */
|
||||||
|
$key = is_object($item) ? ($item->hasMethod($index) ? $item->$index() : $item->$index) : $item[$index];
|
||||||
|
|
||||||
if (array_key_exists($key, $result)) {
|
if (array_key_exists($key, $result)) {
|
||||||
$result[$key]->push($item);
|
$result[$key]->push($item);
|
||||||
|
Loading…
Reference in New Issue
Block a user