summaryrefslogtreecommitdiff
path: root/app/frontend/dto/GridEventGroupDTO.php
diff options
context:
space:
mode:
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';
+ }
+
+}
+
+?>