summaryrefslogtreecommitdiff
path: root/app/frontend/dto/GroupedCalendarGridDayDTO.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-06-16 02:25:37 +0200
committeremkael <emkael@tlen.pl>2016-06-16 11:50:18 +0200
commit0fea2103dd4cc5a04a756d5a87e26d39ea347e49 (patch)
tree193c6af2ffe418c71348944528178e1b11e46fce /app/frontend/dto/GroupedCalendarGridDayDTO.php
parentece88ff6d4c59418dc043c735252aca012eee207 (diff)
* data objects for grouped calendar view
Diffstat (limited to 'app/frontend/dto/GroupedCalendarGridDayDTO.php')
-rw-r--r--app/frontend/dto/GroupedCalendarGridDayDTO.php33
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
+ );
+ }
+
+}
+
+?>