private function _initScreeningForm($subject_model) { $questions = \yii::$app->screeningquestion->getQuestions($this->getScreeningSession('screening_form_id')); $resource_model = Resource::findOne(['id' => $this->getScreeningSession('resource_id')]); $screening_form_model = ScreeningForm::findOne(['id' => $this->getScreeningSession('screening_form_id')]); $screening_entry_model = new \common\models\ScreeningEntry(); $screening_entry_model->screening_form_id = $this->getScreeningSession('screening_form_id'); $screening_entry_model->project_id = $this->getScreeningSession('project_id'); $screening_entry_model->subject_id = $subject_model->id; $screening_entry_model->researcher_id = \Yii::$app->user->identity->id; $screening_entry_model->screening_form_title = $screening_form_model->title; $screening_entry_model->resource_id = $this->getScreeningSession('resource_id'); $screening_entry_model->resource_title = $resource_model->title; if ($screening_entry_model->save() == false) { throw new \yii\web\HttpException(500, yii::t('app', 'An error occured.')); } $this->setScreeningSession('screening_hash', $screening_entry_model->hash); foreach ($questions as $q) { $model = new \common\models\ScreeningResponse(); $model->screening_question_id = $q['screening_question_id']; $model->screening_entry_id = $screening_entry_model->id; $model->subject_id = $subject_model->id; $model->save(); } return true; }
/** * Finds the Resource model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Resource the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Resource::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('您访问的页面不存在'); } }