summaryrefslogtreecommitdiff
path: root/app/php/components/UserSelection.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-03-12 12:36:05 +0100
committeremkael <emkael@tlen.pl>2016-03-12 12:36:05 +0100
commit6dcabb240f0ff0ee1654ac66f806bedb22495d23 (patch)
tree3015dec4654dbdd49a75ee2acd6eadfbe769cc3a /app/php/components/UserSelection.php
parente4606f2d87be0073bcba02fc5878b768260f4a7f (diff)
* user calendar selection on profile page
Diffstat (limited to 'app/php/components/UserSelection.php')
-rw-r--r--app/php/components/UserSelection.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/app/php/components/UserSelection.php b/app/php/components/UserSelection.php
new file mode 100644
index 0000000..99dd2ab
--- /dev/null
+++ b/app/php/components/UserSelection.php
@@ -0,0 +1,67 @@
+<?php
+
+Prado::using('Application.dto.CalendarGroupDTO');
+Prado::using('Application.model.UserPreference');
+
+class UserSelection extends TTemplateControl {
+
+ public function getUserToDisplay() {
+ return $this->getControlState('user');
+ }
+
+ public function setUserToDisplay($user) {
+ $this->setControlState('user', $user);
+ }
+
+ public function onPreRender($param) {
+ parent::onPreRender($param);
+ $this->Categories->setDataSource(
+ $this->_getUserSelection($this->UserToDisplay)
+ );
+ $this->Categories->dataBind();
+ }
+
+ public function categoryDataBind($sender, $param) {
+ $param->Item->Calendars->setDataSource($param->Item->Data->Calendars);
+ $param->Item->Calendars->dataBind();
+ }
+
+ 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
+ )
+ )
+ );
+ return array_map(
+ function($category) use($calendars) {
+ $dto = new CalendarGroupDTO();
+ $dto->loadRecord($category, $calendars);
+ return $dto;
+ },
+ $categories
+ );
+ }
+ return [];
+ }
+
+}
+
+?>