protected function afterSave($wasNew) { if (!$wasNew && $this->updateRelatedParticipants && $this->isModified('status')) { $stmt = $this->getRelatedParticipants(); foreach ($stmt as $participant) { $participant->updateRelatedParticipants = false; //prevent endless loop. Because it will also process this aftersave $participant->event->touch(); // Touch the event to update its mtime. $participant->status = $this->status; $participant->save(); } //$this->event->touch(); // Touch the event to update the modification date. } if ($wasNew && $this->event->is_organizer) { //add this participant to each existing event. if (!$this->dontCreateEvent && $this->user_id > 0 && !$this->is_organizer) { // if ($this->user_id > 0 && !$this->is_organizer) { $newEvent = $this->event->createCopyForParticipant($this); } $stmt = $this->event->getRelatedParticipantEvents(); foreach ($stmt as $event) { if (empty($newEvent) || $event->id != $newEvent->id) { $p = Participant::model()->findSingleByAttributes(array('event_id' => $event->id, 'email' => $this->email)); if (!$p) { $p = new Participant(); $p->setAttributes($this->getAttributes('raw'), false); $p->event_id = $event->id; $p->id = null; $p->save(); } } } if (!$this->is_organizer && $this->contact) { $this->contact->link($this->event); } } return parent::afterSave($wasNew); }