From a798696dea21ccf90c18c5a5fb47bd845e5a885b Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 13 May 2016 13:41:48 +0200 Subject: * refactor of compiling events from specific timeframe to DTOs --- app/php/facades/EventFacade.php | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/php/facades/EventFacade.php b/app/php/facades/EventFacade.php index 6c51716..32dab88 100644 --- a/app/php/facades/EventFacade.php +++ b/app/php/facades/EventFacade.php @@ -2,8 +2,7 @@ Prado::using('Application.facades.Facade'); Prado::using('Application.dto.EventDTO'); -Prado::using('Application.dto.GridEventDTO'); -Prado::using('Application.dto.CalendarGridDTO'); +Prado::using('Application.dto.TimezoneDTO'); Prado::using('Application.model.Calendar'); Prado::using('Application.facades.CalendarFacade'); Prado::using('Application.user.DbUser'); @@ -38,9 +37,23 @@ class EventFacade extends Facade { ); } - public function getTimeframeListForUser(DbUser $user, - DateTime $dateFrom, - DateTime $dateTo) { + 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( @@ -49,14 +62,10 @@ class EventFacade extends Facade { $calendars ); $calendars = $this->_getCalendarsForEvents($events); - return array_map( - function($event) use($calendars) { - $dto = new EventDTO(); - $dto->loadRecord($event, $calendars); - return $dto; - }, - $events - ); + return $this->_compileEventObjects( + $events, $calendars, + UserFacade::getInstance()->getTimezonePreference($user), + $returnClass); } return []; } -- cgit v1.2.3