summaryrefslogtreecommitdiff
path: root/app/php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-03-16 23:09:11 +0100
committeremkael <emkael@tlen.pl>2016-03-16 23:09:11 +0100
commit6839a125d4d0643642e6a9ed5342b29150eed13a (patch)
tree6b1f14c0ed337eb78e04058958b249b600265508 /app/php
parentab39bbffbea2fa9d2cd98e0f107e066e42b59458 (diff)
* event facade refactor
Diffstat (limited to 'app/php')
-rw-r--r--app/php/components/UpcomingEvents.php27
-rw-r--r--app/php/facades/EventFacade.php30
2 files changed, 35 insertions, 22 deletions
diff --git a/app/php/components/UpcomingEvents.php b/app/php/components/UpcomingEvents.php
index 301e740..08341d8 100644
--- a/app/php/components/UpcomingEvents.php
+++ b/app/php/components/UpcomingEvents.php
@@ -23,28 +23,11 @@ class UpcomingEvents extends TTemplateControl {
private function _getEventsForUser(DbUser $user) {
$utc = new DateTimeZone('UTC');
- $events = EventFacade::getInstance()->getEventList(
- (new DateTime('now', $utc))->format('Y-m-d H:i:s'),
- (new DateTime('+7 days', $utc))->format('Y-m-d H:i:s'),
- $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
+ $dateFrom = new DateTime('now', $utc);
+ $dateTo = new DateTime('+7 days', $utc);
+ return EventFacade::getInstance()->getTimeframeListForUser(
+ $user,
+ $dateFrom, $dateTo
);
}
diff --git a/app/php/facades/EventFacade.php b/app/php/facades/EventFacade.php
index e7b3abe..7897d05 100644
--- a/app/php/facades/EventFacade.php
+++ b/app/php/facades/EventFacade.php
@@ -30,6 +30,36 @@ class EventFacade extends Facade {
);
}
+ public function getTimeframeListForUser(DbUser $user,
+ DateTime $dateFrom,
+ DateTime $dateTo) {
+ $events = $this->getEventList(
+ $dateFrom->format('Y-m-d H:i:s'),
+ $dateTo->format('Y-m-d H:i:s'),
+ $user->getCalendarPreference()
+ );
+ $calendars = $this->_getCalendarsForEvents($events);
+ return array_map(
+ function($event) use($calendars) {
+ $dto = new EventDTO();
+ $dto->loadRecord($event, $calendars);
+ return $dto;
+ },
+ $events
+ );
+ }
+
+ private function _getCalendarsForEvents(array $events) {
+ return Calendar::finder()->findAllByPks(
+ array_map(
+ function($event) {
+ return $event->CalendarID;
+ },
+ $events
+ )
+ );
+ }
+
}
?>