diff options
author | emkael <emkael@tlen.pl> | 2016-03-12 12:36:05 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-03-12 12:36:05 +0100 |
commit | 6dcabb240f0ff0ee1654ac66f806bedb22495d23 (patch) | |
tree | 3015dec4654dbdd49a75ee2acd6eadfbe769cc3a /app/php | |
parent | e4606f2d87be0073bcba02fc5878b768260f4a7f (diff) |
* user calendar selection on profile page
Diffstat (limited to 'app/php')
-rw-r--r-- | app/php/components/UserSelection.php | 67 | ||||
-rw-r--r-- | app/php/components/UserSelection.tpl | 25 | ||||
-rw-r--r-- | app/php/pages/Profile.page | 4 |
3 files changed, 96 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 []; + } + +} + +?> 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: +<br /> +<com:TRepeater ID="Categories" OnItemDataBound="categoryDataBind"> + <prop:ItemTemplate> + <%# $this->DataItem->Name %><br /> + <com:TRepeater ID="Calendars"> + <prop:ItemTemplate> + <com:TLinkButton + Text="[X]" + OnCommand="SourceTemplateControl.removeFromSelection"> + <prop:CommandParameter><%# $this->DataItem->ID %></prop:CommandParameter> + <prop:Visible><%# !$this->SourceTemplateControl->UserToDisplay->IsGuest %></prop:Visible> + </com:TLinkButton> + <%# $this->DataItem->Name %> + <com:THyperLink + Text="(www)" + Target="_blank"> + <prop:NavigateUrl><%# $this->DataItem->Website %></prop:NavigateUrl> + </com:THyperLink> + <br /> + </prop:ItemTemplate> + </com:TRepeater> + <br /> + </prop:ItemTemplate> +</com:TRepeater> 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 @@ <com:PasswordChange> <prop:UserToChange><%= $this->User %></prop:UserToChange> </com:PasswordChange> + <br /> + <com:UserSelection> + <prop:UserToDisplay><%= $this->User %></prop:UserToDisplay> + </com:UserSelection> </com:TContent> |