summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-03-16 23:20:41 +0100
committeremkael <emkael@tlen.pl>2016-03-16 23:20:41 +0100
commit519ae86377ce9462099c3d025ed4d2fda90774c5 (patch)
treed753efc5d65dd38029e6e46de0dae6e593ce688b /app
parentc4c6d266817907c7587753ee9115a77e17f4cf4d (diff)
* user selection operations factored out to a facade
Diffstat (limited to 'app')
-rw-r--r--app/php/components/UserSelection.php34
-rw-r--r--app/php/facades/CalendarFacade.php52
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();
+ }
+ }
+
+}
+
+?>