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/frontend/facades/EventFacade.php | 115 +++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 app/frontend/facades/EventFacade.php (limited to 'app/frontend/facades/EventFacade.php') diff --git a/app/frontend/facades/EventFacade.php b/app/frontend/facades/EventFacade.php new file mode 100644 index 0000000..14f809d --- /dev/null +++ b/app/frontend/facades/EventFacade.php @@ -0,0 +1,115 @@ +quoteString($calendar->UID); + }, + $calendars + ) + ) + ); + } + return $this->fetchList( + 'getEvents', + [ + 'date_from' => $dateFrom ?: '0000-00-00 00:00:00', + 'date_to' => $dateTo ?: '9999-99-99', + 'calendar_clause' => $calendarClause, + 'order_clause' => $order + ] + ); + } + + private function _compileEventObjects(array $events, array $calendars, + TimezoneDTO $tz, + string $class = 'Application.dto.EventDTO') { + return array_map( + function($event) use($calendars, $class, $tz) { + $dto = Prado::createComponent($class, $tz); + $dto->loadRecord($event, $calendars); + return $dto; + }, + $events + ); + } + + public function getTimeframeListForUser( + DbUser $user, + DateTime $dateFrom, DateTime $dateTo, + string $returnClass = 'Application.dto.EventDTO') { + $calendars = CalendarFacade::getInstance()->getCalendarPreference($user); + if ($calendars) { + $events = $this->getEventList( + $dateFrom->format('Y-m-d H:i:s'), + $dateTo->format('Y-m-d H:i:s'), + $calendars + ); + $calendars = $this->_getCalendarsForEvents($events); + return $this->_compileEventObjects( + $events, $calendars, + UserFacade::getInstance()->getTimezonePreference($user), + $returnClass); + } + return []; + } + + public function getCalendarListForUser(DbUser $user, + $month, $year) { + if (!$year) { + $year = intval(date('Y')); + } + if (!$month) { + $month = intval(date('m')); + } + $timezone = $user + ? UserFacade::getInstance()->getTimezonePreference($user) + : new TimezoneDTO(date_default_timezone_get()); + $timeframe = CalendarFacade::getInstance()->getCalendarBoundaries( + $year, $month, $timezone + ); + return new CalendarGridDTO( + $this->getTimeframeListForUser( + $user, + $timeframe[0], $timeframe[1], + 'Application.dto.GridEventDTO' + ), + ...$timeframe + ); + } + + private function _getCalendarsForEvents(array $events) { + if ($events) { + return Calendar::finder()->findAllByPks( + array_map( + function($event) { + return $event->CalendarID; + }, + $events + ) + ); + } + return []; + } + +} + +?> -- cgit v1.2.3