public function save() { if (!$this->validate()) { return false; } $model = new Quiz(); if ($desiredModel = Quiz::findOne($this->id)) { $model = $desiredModel; } $model->setAttributes(['name' => $this->name, 'dateStart' => strtotime($this->dateStart), 'dateEnd' => strtotime($this->dateEnd), 'deleted' => $this->deleted, 'published' => $this->published]); if ($model->save(false)) { $this->id = $model->id; foreach ($this->answers as $answer) { $answer->quizID = $model->id; $answer->save(); } } return !empty($this->id); }