Events = $events; if ($this->Events) { $this->Calendar = $this->Events[0]->Calendar; } usort($this->Events, ['GridEventDTO', '__compare']); $this->Header = $this->_determineCommonHeader($this->Events); } public static function __compare(GridEventGroupDTO $ev1, GridEventGroupDTO $ev2) { if ($ev1->GridPosition === NULL || $ev2->GridPosition === NULL) { if (count($ev1->Events) && count($ev2->Events)) { return EventDTO::__compare($ev1->Events[0], $ev2->Events[0]); } } return $ev1->GridPosition - $ev2->GridPosition; } private function _determineCommonHeader(array $events) { if (!$events) { return NULL; } $names = array_map( function(EventDTO $event) { return $event->Name; }, $events ); $prefix = $names[0]; $passed = FALSE; while (!$passed && $prefix) { $passed = TRUE; $prefixLength = strlen($prefix); foreach ($names as $name) { if (substr($name, 0, $prefixLength) != $prefix) { $passed = FALSE; break; } } if ($passed) { foreach ($names as $name) { if (is_numeric(trim(substr($name, $prefixLength)))) { $passed = FALSE; break; } } } if (!$passed) { $prefix = substr($prefix, 0, strrpos($prefix, ' ')); } } return $prefix ?: $events[0]->Calendar->Name; } public function getRendererClass() { return 'Group'; } } ?>