summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-05-06 16:06:05 +0200
committeremkael <emkael@tlen.pl>2016-05-06 16:06:05 +0200
commit93a8bca97a8d5453a206c402efce5fdd0e9dae72 (patch)
tree58fbbc8216c9ef14fe7bd3677841bac7c6853263
parent306af7af3aaa315701f41924d786c09832fbb15a (diff)
* refactoring default calendar preference fetch
-rw-r--r--app/php/facades/CalendarFacade.php22
1 files changed, 17 insertions, 5 deletions
diff --git a/app/php/facades/CalendarFacade.php b/app/php/facades/CalendarFacade.php
index c342cd2..5eed764 100644
--- a/app/php/facades/CalendarFacade.php
+++ b/app/php/facades/CalendarFacade.php
@@ -22,9 +22,17 @@ class CalendarFacade extends Facade {
);
}
+ private $_defaultPreference = NULL;
+ public function getDefaultPreference() {
+ if ($this->_defaultPreference === NULL) {
+ $this->_defaultPreference = Calendar::finder()->findAllByIsVisible(1);
+ }
+ return $this->_defaultPreference;
+ }
+
public function getCalendarPreference(DbUser $user) {
if ($user->IsGuest) {
- return Calendar::finder()->findAllByIsVisible(1);
+ return $this->getDefaultPreference();
} else {
return $user->DbRecord->Calendars;
}
@@ -63,10 +71,7 @@ class CalendarFacade extends Facade {
if (!$user->IsGuest) {
$calendar = Calendar::finder()->findByPk($calendarID);
if ($calendar) {
- $preference = new UserPreference();
- $preference->CalendarID = $calendar->UID;
- $preference->UserID = $user->DbRecord->ID;
- $preference->save();
+ $this->setPreferredCalendar($user->DbRecord, $calendar);
}
}
}
@@ -84,6 +89,13 @@ class CalendarFacade extends Facade {
}
}
+ public function setPreferredCalendar(User $user, Calendar $calendar) {
+ $preference = new UserPreference();
+ $preference->CalendarID = $calendar->UID;
+ $preference->UserID = $user->ID;
+ $preference->save();
+ }
+
public function getEventsForTimeframe(CalendarDTO $calendar,
DateTime $dateFrom,
DateTime $dateTo,