diff options
author | emkael <emkael@tlen.pl> | 2016-03-16 23:20:41 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-03-16 23:20:41 +0100 |
commit | 519ae86377ce9462099c3d025ed4d2fda90774c5 (patch) | |
tree | d753efc5d65dd38029e6e46de0dae6e593ce688b /app/php/facades/CalendarFacade.php | |
parent | c4c6d266817907c7587753ee9115a77e17f4cf4d (diff) |
* user selection operations factored out to a facade
Diffstat (limited to 'app/php/facades/CalendarFacade.php')
-rw-r--r-- | app/php/facades/CalendarFacade.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/app/php/facades/CalendarFacade.php b/app/php/facades/CalendarFacade.php new file mode 100644 index 0000000..7c4e84d --- /dev/null +++ b/app/php/facades/CalendarFacade.php @@ -0,0 +1,52 @@ +<?php + +Prado::using('Application.facades.Facade'); +Prado::using('Application.dto.CalendarGroupDTO'); +Prado::using('Application.model.Category'); +Prado::using('Application.model.UserPreference'); +Prado::using('Application.user.DbUser'); + +class CalendarFacade extends Facade { + + private function _getCategoriesForCalendars(array $calendars) { + return Category::finder()->findAllByPks( + array_map( + function($calendar) { + return $calendar->CategoryID; + }, + $calendars + ) + ); + } + + public function getPreferenceList(DbUser $user) { + $calendars = $user->getCalendarPreference(); + if ($calendars) { + $categories = array_map( + function($category) use($calendars) { + $dto = new CalendarGroupDTO(); + $dto->loadRecord($category, $calendars); + return $dto; + }, + $this->_getCategoriesForCalendars($calendars) + ); + usort($categories, ['CalendarGroupDTO', '__compare']); + return $categories; + } + return []; + } + + public function removeFromPreference(DbUser $user, $calendarID) { + if (!$user->IsGuest) { + $preferenceRecord = UserPreference::finder()->find( + '_user = ? AND _calendar = ?', + $user->DbRecord->ID, + $calendarID + ); + $preferenceRecord->delete(); + } + } + +} + +?> |