summaryrefslogtreecommitdiff
path: root/app/php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-03-15 23:59:54 +0100
committeremkael <emkael@tlen.pl>2016-03-15 23:59:54 +0100
commit4847856dd8adcbc0004f6653c627cb7cf7773a95 (patch)
treed325618787d1ef3cb162c046c2566706ff52f75b /app/php
parente509fc24d904831759071134361bef1503d4ff87 (diff)
* event DTO
Diffstat (limited to 'app/php')
-rw-r--r--app/php/dto/EventDTO.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/app/php/dto/EventDTO.php b/app/php/dto/EventDTO.php
new file mode 100644
index 0000000..4a16505
--- /dev/null
+++ b/app/php/dto/EventDTO.php
@@ -0,0 +1,47 @@
+<?php
+
+Prado::using('Application.model.Entry');
+Prado::using('Application.dto.CalendarDTO');
+
+class EventDTO {
+
+ public $DateString;
+ public $Name;
+ public $Location;
+ public $Calendar;
+
+ public function loadRecord(Entry $event, array $calendars) {
+ $this->Name = $event->Name;
+ $this->Location = $event->Location;
+
+ $utc = new DateTimeZone('UTC');
+ $targetTz = new DateTimeZone(date_default_timezone_get());
+ $beginDate = new DateTime($event->BeginDate, $utc);
+ $endDate = new DateTime($event->EndDate, $utc);
+ if ($event->AllDay) {
+ $endDate = $endDate->modify('-1 day');
+ $this->DateString = $beginDate->format('Y-m-d');
+ if ($beginDate != $endDate) {
+ $this->DateString .= sprintf(
+ ' - %s',
+ $endDate->format('Y-m-d')
+ );
+ }
+ } else {
+ $beginDate = $beginDate->setTimezone($targetTz);
+ $this->DateString = $beginDate->format('Y-m-d H:i');
+ }
+
+ $calendars = array_filter(
+ $calendars,
+ function ($calendar) use($event) {
+ return $calendar->UID == $event->CalendarID;
+ }
+ );
+ $this->Calendar = new CalendarDTO();
+ $this->Calendar->loadRecord($calendars ? array_values($calendars)[0] : $event->Calendar);
+ }
+
+}
+
+?>