diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/php/components/UserSelection.php | 34 | ||||
-rw-r--r-- | app/php/facades/CalendarFacade.php | 52 |
2 files changed, 54 insertions, 32 deletions
diff --git a/app/php/components/UserSelection.php b/app/php/components/UserSelection.php index 7b10b40..6ae68e4 100644 --- a/app/php/components/UserSelection.php +++ b/app/php/components/UserSelection.php @@ -1,7 +1,6 @@ <?php -Prado::using('Application.dto.CalendarGroupDTO'); -Prado::using('Application.model.UserPreference'); +Prado::using('Application.facades.CalendarFacade'); class UserSelection extends TTemplateControl { @@ -28,40 +27,11 @@ class UserSelection extends TTemplateControl { public function removeFromSelection($sender, $param) { if (!$this->UserToDisplay->IsGuest) { - $preferenceRecord = UserPreference::finder()->find( - '_user = ? AND _calendar = ?', - $this->UserToDisplay->DbRecord->ID, - $param->CommandParameter - ); - $preferenceRecord->delete(); } } private function _getUserSelection(DbUser $user) { - $calendars = $user->getCalendarPreference(); - if ($calendars) { - $categories = Category::finder()->findAllByPks( - array_unique( - array_map( - function($calendar) { - return $calendar->CategoryID; - }, - $calendars - ) - ) - ); - $categories = array_map( - function($category) use($calendars) { - $dto = new CalendarGroupDTO(); - $dto->loadRecord($category, $calendars); - return $dto; - }, - $categories - ); - usort($categories, ['CalendarGroupDTO', '__compare']); - return $categories; - } - return []; + return CalendarFacade::getInstance()->getPreferenceList($user); } } 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(); + } + } + +} + +?> |