From 6dcabb240f0ff0ee1654ac66f806bedb22495d23 Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 12 Mar 2016 12:36:05 +0100 Subject: * user calendar selection on profile page --- app/php/components/UserSelection.php | 67 ++++++++++++++++++++++++++++++++++++ app/php/components/UserSelection.tpl | 25 ++++++++++++++ app/php/pages/Profile.page | 4 +++ 3 files changed, 96 insertions(+) create mode 100644 app/php/components/UserSelection.php create mode 100644 app/php/components/UserSelection.tpl (limited to 'app') 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 @@ +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 []; + } + +} + +?> diff --git a/app/php/components/UserSelection.tpl b/app/php/components/UserSelection.tpl new file mode 100644 index 0000000..0532cef --- /dev/null +++ b/app/php/components/UserSelection.tpl @@ -0,0 +1,25 @@ +Selected calendars: +
+ + + <%# $this->DataItem->Name %>
+ + + + <%# $this->DataItem->ID %> + <%# !$this->SourceTemplateControl->UserToDisplay->IsGuest %> + + <%# $this->DataItem->Name %> + + <%# $this->DataItem->Website %> + +
+
+
+
+
+
diff --git a/app/php/pages/Profile.page b/app/php/pages/Profile.page index b66a50b..c5e06ca 100644 --- a/app/php/pages/Profile.page +++ b/app/php/pages/Profile.page @@ -2,4 +2,8 @@ <%= $this->User %> +
+ + <%= $this->User %> + -- cgit v1.2.3