public function getGroupedDateTimesByDay() { $all_times = $this->DateTimes(); $grouped = new GroupedList($all_times); $grouped->GroupedBy("getTokenEventStartEnd", "Times"); return $grouped; }
public function testGroupedBy() { $list = new GroupedList(new ArrayList(array(array('Name' => 'AAA'), array('Name' => 'AAA'), array('Name' => 'BBB'), array('Name' => 'BBB'), array('Name' => 'AAA'), array('Name' => 'BBB'), array('Name' => 'CCC'), array('Name' => 'CCC')))); $grouped = $list->GroupedBy('Name'); $first = $grouped->first(); $last = $grouped->last(); $this->assertEquals(3, count($first->Children)); $this->assertEquals('AAA', $first->Name); $this->assertEquals(2, count($last->Children)); $this->assertEquals('CCC', $last->Name); }
/** * @param string $index * @param string $childrenKey * @return ArrayList */ public function GroupedBy($index, $childrenKey = 'Children') { if (strpos($index, '.') === false) { return parent::GroupedBy($index, $childrenKey); } $grouped = $this->groupBy($index); $result = new ArrayList(); // Extract the key name from the relations $relations = explode('.', $index); $key = array_pop($relations); foreach ($grouped as $indexValue => $list) { $list = self::create($list); $data = new ArrayData(array($key => $indexValue, $childrenKey => $list)); $result->push($data); } return $result; }