From 823d71ced9b4947b1a5a5ade7245d521ed490061 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 7 Jun 2016 15:17:49 +0200 Subject: * renaming php directory --- app/php/dto/CalendarDTO.php | 31 -------------- app/php/dto/CalendarGridDTO.php | 84 ------------------------------------- app/php/dto/CalendarGridDayDTO.php | 28 ------------- app/php/dto/CalendarGroupDTO.php | 44 -------------------- app/php/dto/EventDTO.php | 85 -------------------------------------- app/php/dto/GridEventDTO.php | 28 ------------- app/php/dto/TimezoneDTO.php | 46 --------------------- app/php/dto/weekdays.json | 1 - 8 files changed, 347 deletions(-) delete mode 100644 app/php/dto/CalendarDTO.php delete mode 100644 app/php/dto/CalendarGridDTO.php delete mode 100644 app/php/dto/CalendarGridDayDTO.php delete mode 100644 app/php/dto/CalendarGroupDTO.php delete mode 100644 app/php/dto/EventDTO.php delete mode 100644 app/php/dto/GridEventDTO.php delete mode 100644 app/php/dto/TimezoneDTO.php delete mode 120000 app/php/dto/weekdays.json (limited to 'app/php/dto') diff --git a/app/php/dto/CalendarDTO.php b/app/php/dto/CalendarDTO.php deleted file mode 100644 index 4468941..0000000 --- a/app/php/dto/CalendarDTO.php +++ /dev/null @@ -1,31 +0,0 @@ -ID = $calendarRecord->UID; - $this->Name = $calendarRecord->CustomName ?: $calendarRecord->Name; - $this->Website = $calendarRecord->Website; - $this->Image = $calendarRecord->CustomImageUrl; - $this->Url = $calendarRecord->CustomUrl; - $this->LastUpdated = $calendarRecord->LastUpdated; - $this->GroupID = $calendarRecord->CategoryID; - } - - public static function __compare(CalendarDTO $cal1, CalendarDTO $cal2) { - return strcmp($cal1->Name, $cal2->Name); - } - -} - -?> diff --git a/app/php/dto/CalendarGridDTO.php b/app/php/dto/CalendarGridDTO.php deleted file mode 100644 index f5d91a5..0000000 --- a/app/php/dto/CalendarGridDTO.php +++ /dev/null @@ -1,84 +0,0 @@ -DateFrom = DateTimeImmutable::createFromMutable($dateFrom); - $this->DateTo = DateTimeImmutable::createFromMutable($dateTo); - $date = $this->DateFrom; - $days = []; - $previousDay = NULL; - while ($date <= $this->DateTo) { - $day = $this->_getGridDay($date, $events, $previousDay); - $days[] = $day; - $previousDay = $day; - $date = $date->modify('+1 day'); - } - $this->Weeks = array_chunk($days, 7); - } - - private function _getContinuedEventGridPositions( - CalendarGridDayDTO $day, - CalendarGridDayDTO $previousDay = NULL) { - $eventPositions = []; - if ($previousDay) { - foreach ($day->Events as $event) { - if (in_array($event, $previousDay->Events)) { - $eventPositions[] = $event->GridPosition; - } - } - } - return $eventPositions; - } - - private function _alignEvents(array $eventPositions, array $events) { - $previousCount = count($eventPositions); - foreach ($events as $event) { - if ($event->GridPosition === NULL) { - $event->GridPosition = min( - array_diff( - range(0, count($events) + $previousCount), - $eventPositions - ) - ); - $eventPositions[] = $event->GridPosition; - } - } - usort($events, ['GridEventDTO', '__compare']); - return $events; - } - - private function _fillEventGrid(array $events) { - $previousEvent = -1; - foreach ($events as $event) { - $eventStep = $event->GridPosition - $previousEvent; - if ($eventStep > 1) { - array_splice( - $events, $previousEvent + 1, 0, array_fill(0, $eventStep - 1, NULL) - ); - } - $previousEvent = $event->GridPosition; - } - return $events; - } - - private function _getGridDay(DateTimeImmutable $date, - array $events, - CalendarGridDayDTO $previousDay = NULL) { - $day = new CalendarGridDayDTO($date, $events); - $eventPositions = $this->_getContinuedEventGridPositions($day, $previousDay); - $day->Events = $this->_alignEvents($eventPositions, $day->Events); - $day->Events = $this->_fillEventGrid($day->Events); - return $day; - } - -} - -?> diff --git a/app/php/dto/CalendarGridDayDTO.php b/app/php/dto/CalendarGridDayDTO.php deleted file mode 100644 index ba65eb9..0000000 --- a/app/php/dto/CalendarGridDayDTO.php +++ /dev/null @@ -1,28 +0,0 @@ -Date = $date->format('Y-m-d'); - $this->Events = array_filter($events, [$this, '_checkEventDate']); - // initial sort (date and calendar name) - // events are going to be re-sorted after assigning grid priorities - usort($this->Events, ['EventDTO', '__compare']); - } - - private function _checkEventDate(GridEventDTO $event) { - if (!$this->Date) { - return FALSE; - } - return ($this->Date >= $event->DateFrom) && ($this->Date <= $event->DateTo); - } - -} - -?> diff --git a/app/php/dto/CalendarGroupDTO.php b/app/php/dto/CalendarGroupDTO.php deleted file mode 100644 index 7b64c6e..0000000 --- a/app/php/dto/CalendarGroupDTO.php +++ /dev/null @@ -1,44 +0,0 @@ -Name = $categoryRecord->Name; - $this->ID = $categoryRecord->ID; - $this->Priority = $categoryRecord->Priority; - $this->Calendars = array_map( - function($calendarRecord) { - $dto = new CalendarDTO(); - $dto->loadRecord($calendarRecord); - return $dto; - }, - array_filter( - $calendars, - function($calendarRecord) use($categoryRecord) { - return $categoryRecord->ID == $calendarRecord->CategoryID; - } - ) - ); - usort($this->Calendars, ['CalendarDTO', '__compare']); - } - - public static function __compare(CalendarGroupDTO $cat1, - CalendarGroupDTO $cat2) { - $cmp = ($cat1->Priority ?: PHP_MAX_INT) - ($cat2->Priority ?: PHP_MAX_INT); - if ($cmp !== 0) { - return $cmp; - } - return strcmp($cat1->Name, $cat2->Name); - } - -} - -?> diff --git a/app/php/dto/EventDTO.php b/app/php/dto/EventDTO.php deleted file mode 100644 index 8f5cdf5..0000000 --- a/app/php/dto/EventDTO.php +++ /dev/null @@ -1,85 +0,0 @@ -_utc = new DateTimeZone('UTC'); - $this->_targetTZ = new DateTimeZone( - $tz - ? $tz->Name - : UserFacade::getInstance()->getTimezonePreference( - Prado::getApplication()->getUser() - )->Name - ); - } - - private $_beginDate; - protected function getBeginDate(Entry $event) { - if (!$this->_beginDate) { - $this->_beginDate = new DateTime($event->BeginDate, $this->_utc); - } - return $this->_beginDate; - } - - private $_endDate; - protected function getEndDate(Entry $event) { - if (!$this->_endDate) { - $this->_endDate = new DateTime($event->EndDate, $this->_utc); - if ($event->AllDay) { - $this->_endDate = $this->_endDate->modify('-1 day'); - } - } - return $this->_endDate; - } - - public function loadRecord(Entry $event, array $calendars) { - $this->Name = $event->Name; - $this->Location = $event->Location; - - if ($event->AllDay) { - $this->DateString = $this->getBeginDate($event)->format('Y-m-d'); - if ($this->getBeginDate($event) != $this->getEndDate($event)) { - $this->DateString .= sprintf( - ' - %s', - $this->getEndDate($event)->format('Y-m-d') - ); - } - } else { - $beginDate = $this->getBeginDate($event)->setTimezone($this->_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 - ); - } - - public static function __compare(EventDTO $ev1, EventDTO $ev2) { - if ($ev1->DateString === $ev2->DateString) { - return strcmp($ev1->Calendar->Name, $ev2->Calendar->Name); - } - return strcmp($ev1->DateString, $ev2->DateString); - } - -} - -?> diff --git a/app/php/dto/GridEventDTO.php b/app/php/dto/GridEventDTO.php deleted file mode 100644 index 0d2bb37..0000000 --- a/app/php/dto/GridEventDTO.php +++ /dev/null @@ -1,28 +0,0 @@ -AllDay = TPropertyValue::ensureBoolean($event->AllDay); - $this->DateFrom = $this->getBeginDate($event)->format('Y-m-d'); - $this->DateTo = $this->getEndDate($event)->format('Y-m-d'); - } - - public static function __compare(EventDTO $ev1, EventDTO $ev2) { - if ($ev1->GridPosition === NULL || $ev2->GridPosition === NULL) { - return parent::__compare($ev1, $ev2); - } - return $ev1->GridPosition - $ev2->GridPosition; - } - -} - -?> diff --git a/app/php/dto/TimezoneDTO.php b/app/php/dto/TimezoneDTO.php deleted file mode 100644 index e4078e6..0000000 --- a/app/php/dto/TimezoneDTO.php +++ /dev/null @@ -1,46 +0,0 @@ -Name = $tz->getName(); - $this->Offset = $tz->getOffset(new DateTime()); - $this->OffsetHours = $this->Offset / 3600; - $this->OffsetMinutes = $this->Offset % 3600 / 60; - $this->Location = $tz->getLocation()['country_code']; - $this->FirstDayOfTheWeek = $this->_getFirstDayOfTheWeek(); - $this->Label = sprintf('UTC%+03d:%02d %s', $this->OffsetHours, $this->OffsetMinutes, $this->Name); - } - - private function _getFirstDayOfTheWeek() { - $dayMapping = json_decode( - file_get_contents( - Prado::getPathOfNamespace('Application.dto.weekdays', '.json') - ), - TRUE - ); - if ($this->Location && isset($dayMapping[$this->Location])) { - return ucfirst($dayMapping[$this->Location]); - } - return ucfirst($dayMapping['001']); - } - - - - public static function __compare(TimezoneDTO $tz1, TimezoneDTO $tz2) { - $diff = $tz1->Offset - $tz2->Offset; - return ($diff == 0) ? strcmp($tz1->Name, $tz2->Name) : $diff; - } - -} - -?> diff --git a/app/php/dto/weekdays.json b/app/php/dto/weekdays.json deleted file mode 120000 index 325c801..0000000 --- a/app/php/dto/weekdays.json +++ /dev/null @@ -1 +0,0 @@ -../../../config/weekdays.json \ No newline at end of file -- cgit v1.2.3