diff options
author | emkael <emkael@tlen.pl> | 2016-05-13 13:41:48 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-13 13:50:11 +0200 |
commit | a798696dea21ccf90c18c5a5fb47bd845e5a885b (patch) | |
tree | 7a58eff1aa635af500c8fef771fbe6031e03f2a5 /app | |
parent | 0df58521beb5d7154a09bc8bb3abe83b948996c8 (diff) |
* refactor of compiling events from specific timeframe to DTOs
Diffstat (limited to 'app')
-rw-r--r-- | app/php/facades/EventFacade.php | 35 |
1 files changed, 22 insertions, 13 deletions
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 []; } |