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 afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         // Creator automatically attends to this event
         $participant = new CalendarEntryParticipant();
         $participant->user_id = Yii::$app->user->id;
         $participant->calendar_entry_id = $this->id;
         $participant->participation_state = CalendarEntryParticipant::PARTICIPATION_STATE_ACCEPTED;
         $participant->save();
     }
     return;
 }