diff options
Diffstat (limited to 'app/php/components/UpcomingEvents.php')
| -rw-r--r-- | app/php/components/UpcomingEvents.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/app/php/components/UpcomingEvents.php b/app/php/components/UpcomingEvents.php new file mode 100644 index 0000000..e18f2f4 --- /dev/null +++ b/app/php/components/UpcomingEvents.php @@ -0,0 +1,52 @@ +<?php + +Prado::using('Application.facades.EventFacade'); +Prado::using('Application.dto.EventDTO'); + +class UpcomingEvents extends TTemplateControl { + + public function getUserToDisplay() { + return $this->getControlState('user'); + } + + public function setUserToDisplay($user) { + $this->setControlState('user', $user); + } + + public function onPreRender($param) { + parent::onPreRender($param); + $this->Events->setDataSource( + $this->_getEventsForUser($this->UserToDisplay) + ); + $this->Events->dataBind(); + } + + private function _getEventsForUser(DbUser $user) { + $events = EventFacade::getInstance()->getEventList( + date('Y-m-d'), + date('Y-m-d', strtotime('+7 days')), + $user->getCalendarPreference() + ); + $calendars = Calendar::finder()->findAllByPks( + array_unique( + array_map( + function($event) { + return $event->CalendarID; + }, + $events + ) + ) + ); + return array_map( + function($event) use($calendars) { + $dto = new EventDTO(); + $dto->loadRecord($event, $calendars); + return $dto; + }, + $events + ); + } + +} + +?> |
