public function checkIsTextBoxByQuestionId($id) { if (TextBox::find()->where(['id' => $id])->exists() == 1) { return true; } return false; }
/** * Finds the TextBox model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TextBox the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TextBox::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionResult($id) { if (Yii::$app->user->can('surveyResult')) { $model = $this->findModel($id); $dataProvider = []; $questions = Question::getAllQuestionBySurveyId($id); foreach ($questions as $row) { $result['id'] = $row['id']; $result['question'] = Question::getQuestionContentByQuestionId($row['id']); if (TextBox::checkIsTextBoxByQuestionId($row['id'])) { $result['type'] = 0; $result['results'] = TextResponse::getResponsesByQuestionId($row['id']); array_push($dataProvider, $result); continue; } if (Checkbutton::checkIsCheckBoxByQuestionId($row['id'])) { $result['type'] = 1; $result['results'] = Checkbutton::getOptionsStatisticsByQuestionId($row['id']); array_push($dataProvider, $result); continue; } if (Radiobutton::checkIsRadioButtonByQuestionId($row['id'])) { $result['type'] = 2; $result['results'] = Radiobutton::getOptionsStatisticsByQuestionId($row['id']); array_push($dataProvider, $result); continue; } } return $this->render('result', ['model' => $model, 'dataProvider' => $dataProvider, 'doneCount' => SurveyHasParticipant::getDoneCountBySurveyId($id)]); } else { if (Yii::$app->user->isGuest) { Yii::$app->user->loginRequired(); } else { throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); } } }
/** * @return \yii\db\ActiveQuery */ public function getTextBox() { return $this->hasOne(TextBox::className(), ['id' => 'id']); }