From 0fea2103dd4cc5a04a756d5a87e26d39ea347e49 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 16 Jun 2016 02:25:37 +0200 Subject: * data objects for grouped calendar view --- app/frontend/dto/GridEventGroupDTO.php | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 app/frontend/dto/GridEventGroupDTO.php (limited to 'app/frontend/dto/GridEventGroupDTO.php') diff --git a/app/frontend/dto/GridEventGroupDTO.php b/app/frontend/dto/GridEventGroupDTO.php new file mode 100644 index 0000000..5845076 --- /dev/null +++ b/app/frontend/dto/GridEventGroupDTO.php @@ -0,0 +1,73 @@ +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'; + } + +} + +?> -- cgit v1.2.3