public static function createSavedCalendarSubscription($name, $color, $user) { $savedCalendars = SavedCalendar::getByName($name); $savedCalendarSubscription = new SavedCalendarSubscription(); $savedCalendarSubscription->user = $user; $savedCalendarSubscription->savedcalendar = $savedCalendars[0]; $savedCalendarSubscription->color = $color; assert($savedCalendarSubscription->save()); // Not Coding Standard return $savedCalendarSubscription; }
/** * Remove the subscription for the calendar. * @param int $id */ public function actionUnsubscribe($id) { $savedCalendarSubscription = SavedCalendarSubscription::getById(intval($id)); $savedCalendarSubscription->delete(); $dataProvider = CalendarUtil::getCalendarItemsDataProvider(Yii::app()->user->userModel); $savedCalendarSubscriptions = $dataProvider->getSavedCalendarSubscriptions(); $content = CalendarUtil::makeCalendarItemsList($savedCalendarSubscriptions->getSubscribedToSavedCalendarsAndSelected(), 'sharedcalendar[]', 'sharedcalendar', 'shared'); echo $content; }
/** * Process and save the color for the model. * @param SavedCalendar|SavedCalendarSubscription $calendar * @param array $usedColors */ public static function processAndSaveColor($calendar, $usedColors) { assert('$calendar instanceof SavedCalendar || $calendar instanceof SavedCalendarSubscription'); assert('is_array($usedColors)'); $availableColors = SavedCalendar::$colorsArray; $filteredColors = array_diff($availableColors, $usedColors); $color = array_shift($filteredColors); $calendar->color = $color; $calendar->save(); }