public function actionRespond() { $calendarEntry = $this->getCalendarEntry(Yii::$app->request->get('id')); if ($calendarEntry == null) { throw new HttpException('404', Yii::t('CalendarModule.base', "Event not found!")); } if ($calendarEntry->canRespond()) { $calendarEntryParticipant = CalendarEntryParticipant::findOne(['calendar_entry_id' => $calendarEntry->id, 'user_id' => Yii::$app->user->id]); if ($calendarEntryParticipant == null) { $calendarEntryParticipant = new CalendarEntryParticipant(); $calendarEntryParticipant->user_id = Yii::$app->user->id; $calendarEntryParticipant->calendar_entry_id = $calendarEntry->id; } $calendarEntryParticipant->participation_state = (int) Yii::$app->request->get('type'); $calendarEntryParticipant->save(); } return $this->redirect($this->contentContainer->createUrl('view', array('id' => $calendarEntry->id))); }
public function getParticipationState(User $user = null) { if ($user == null) { $user = Yii::$app->user->getIdentity(); } $participant = CalendarEntryParticipant::findOne(['user_id' => $user->id, 'calendar_entry_id' => $this->id]); if ($participant !== null) { return $participant->participation_state; } return 0; }