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 ) ) ); $categories = array_map( function($category) use($calendars) { $dto = new CalendarGroupDTO(); $dto->loadRecord($category, $calendars); return $dto; }, $categories ); usort( $categories, function ($cat1, $cat2) { return strcmp($cat1->Name, $cat2->Name); } ); return $categories; } return []; } } ?>