diff options
Diffstat (limited to 'app/frontend/dto/GroupedCalendarGridDayDTO.php')
-rw-r--r-- | app/frontend/dto/GroupedCalendarGridDayDTO.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/frontend/dto/GroupedCalendarGridDayDTO.php b/app/frontend/dto/GroupedCalendarGridDayDTO.php new file mode 100644 index 0000000..7d2c041 --- /dev/null +++ b/app/frontend/dto/GroupedCalendarGridDayDTO.php @@ -0,0 +1,33 @@ +<?php + +Prado::using('Application.dto.CalendarGridDayDTO'); +Prado::using('Application.dto.GridEventGroupDTO'); + +class GroupedCalendarGridDayDTO extends CalendarGridDayDTO { + + public function __construct(DateTimeImmutable $date, array $events) { + parent::__construct($date, $events); + $this->Events = $this->_getEventGroups($this->Events); + // initial sort events are going to be re-sorted after assigning grid priorities + usort($this->Events, ['GridEventGroupDTO', '__compare']); + } + + private function _getEventGroups(array $events) { + $clusters = []; + foreach ($events as $event) { + if (!isset($clusters[$event->Calendar->ID])) { + $clusters[$event->Calendar->ID] = []; + } + $clusters[$event->Calendar->ID][] = $event; + } + return array_map( + function($cluster) { + return new GridEventGroupDTO($cluster); + }, + $clusters + ); + } + +} + +?> |