summaryrefslogtreecommitdiff
path: root/app/frontend/dto/GridEventGroupDTO.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/GridEventGroupDTO.php
parentece88ff6d4c59418dc043c735252aca012eee207 (diff)
* data objects for grouped calendar view
Diffstat (limited to 'app/frontend/dto/GridEventGroupDTO.php')
-rw-r--r--app/frontend/dto/GridEventGroupDTO.php73
1 files changed, 73 insertions, 0 deletions
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 @@
+<?php
+
+Prado::using('Application.dto.GridEventDTO');
+Prado::using('Application.controls.grid.IGridElementDTO');
+
+class GridEventGroupDTO implements IGridElementDTO {
+
+ public $Header;
+ public $Events;
+ public $Calendar;
+ public $GridPosition;
+
+ public function __construct(array $events) {
+ $this->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';
+ }
+
+}
+
+?>