/** * @return bool */ public function addParticipant() { if ($this->validate()) { $participant = new Participant(); $participant->setAttributes($this->getAttributes()); if ($participant->save()) { return $participant->id; } } return $this->getErrors(); }
public function addUser() { if (!$this->validate()) { return false; } if (Shift::findOne($this->shift_id === null) || User::findOne($this->user_id == null)) { throw new NotFoundHttpException('The requested page does not exist.'); } $participant = new Participant(); $participant->shift_id = $this->shift_id; $participant->user_id = $this->user_id; return $participant->save(); }
public function addParticipant($user_id) { if ($this->hasParticipant($user_id) == true) { Yii::$app->session->addFlash("error", "You are already signed up for this shift."); return false; } if (!$this->canBeFilled()) { Yii::$app->session->addFlash("error", "This shift is full."); return false; } if (!$this->meetsRequirement($user_id)) { Yii::$app->session->addFlash("error", $this->requirement->errorMessageString); return false; } $participant = new Participant(); $participant->shift_id = $this->id; $participant->user_id = $user_id; if ($participant->save()) { Yii::$app->session->addFlash("success", sprintf("You are now signed up for the %s '%s' shift on %s", $this->team->name, $this->title, date('M j \\a\\t g:i a', $this->start_time))); return true; } Yii::$app->session->addFlash("error", "There was an error saving: " . print_r($participant->errors, true)); return false; }