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 ); if ($preferenceRecord) { $preferenceRecord->delete(); } } } public function getAll() { return Calendar::finder()->withCategory()->findAll('ORDER BY name ASC'); } public function getCategories() { return Category::finder()->findAll('ORDER BY name ASC'); } public function get($uid) { return Calendar::finder()->withCategory()->findAllByPks($uid); } } ?>