public function getOptionsStatisticsByQuestionId($id) { return Checkbutton::find()->where(['Question_id' => $id])->select(['content', 'count'])->orderBy(['count' => SORT_DESC])->asArray()->all(); }
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.')); } } }
} else { $field = '[' . $index . ']temp_input'; } if ($row->temp_type == 0) { ?> <?php echo $form->field($row, $field)->textInput(['maxlength' => true])->label($row->content); ?> <?php } ?> <?php if ($row->temp_type == 1) { ?> <?php echo $form->field($row, $field)->checkboxList(\app\models\Checkbutton::getAllOptionsByQuestionId($row->id))->label($row->content); ?> <?php } ?> <?php if ($row->temp_type == 2) { ?> <?php echo $form->field($row, $field)->radioList(\app\models\Radiobutton::getAllOptionsByQuestionId($row->id))->label($row->content); ?> <?php } ?> <?php }