guild/backend/modules/questionnaire/views/user-questionnaire/view.php

173 lines
5.9 KiB
PHP
Raw Normal View History

2021-10-22 17:02:28 +03:00
<?php
2021-11-08 12:41:39 +03:00
use common\helpers\ScoreCalculatorHelper;
use common\helpers\AnswerHelper;
use common\helpers\StatusHelper;
2021-10-22 17:02:28 +03:00
use yii\bootstrap\Modal;
use yii\grid\GridView;
2021-11-08 12:41:39 +03:00
use yii\helpers\ArrayHelper;
2021-10-22 17:02:28 +03:00
use yii\helpers\Html;
use yii\web\YiiAsset;
use yii\widgets\DetailView;
2021-10-29 17:06:09 +03:00
use yii\widgets\Pjax;
2021-10-22 17:02:28 +03:00
/* @var $this yii\web\View */
/* @var $model backend\modules\questionnaire\models\UserQuestionnaire */
/* @var $responseDataProvider yii\data\ActiveDataProvider */
$user = $model->getUserName();
$questionnaire_title = $model->getQuestionnaireTitle();
2021-10-22 17:02:28 +03:00
$this->title = $user . ": " . $questionnaire_title;
2021-10-22 17:02:28 +03:00
$this->params['breadcrumbs'][] = ['label' => 'User Questionnaires', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
YiiAsset::register($this);
?>
2021-10-29 17:06:09 +03:00
<?php
//$this->registerJs(
// '$("document").ready(function(){
// $("#new_note").on("pjax:end", function() {
// $.pjax.reload({container:"#user_responses"}); //Reload GridView
// });
// });'
//);
?>
2021-10-22 17:02:28 +03:00
<div class="user-questionnaire-view">
<!-- --><?php //var_dump($model->setPercentCorrectAnswers(4)); die();?>
2021-10-22 17:02:28 +03:00
<p>
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
[
'attribute' => 'questionnaires_id',
2021-11-08 12:41:39 +03:00
'value' => ArrayHelper::getValue($model, 'questionnaire.title'),
2021-10-22 17:02:28 +03:00
],
[
'attribute' => 'user_id',
2021-11-08 12:41:39 +03:00
'value' => ArrayHelper::getValue($model, 'user.username'),
2021-10-22 17:02:28 +03:00
],
'uuid',
'score',
[
'attribute' => 'percent_correct_answers',
'value' => function($model) {
$percent = $model->percent_correct_answers * 100;
return $percent . '%';
}
],
2021-10-22 17:02:28 +03:00
[
'attribute' => 'status',
'format' => 'raw',
2021-11-08 12:41:39 +03:00
'value' => StatusHelper::statusLabel($model->status),
2021-10-22 17:02:28 +03:00
],
'created_at',
'updated_at',
],
]) ?>
<p>
<?= Html::a('Проверить ответы', ['rate-responses', 'id' => $model->id], [
'class' => 'btn btn-primary',
'data' => [
'confirm' => 'Проверка ответов пользователя: ' . $user . ". Категория: " . $questionnaire_title,
2021-10-22 17:02:28 +03:00
],
]) ?>
<?php
Modal::begin([
'header' => '<h3>Подсчёт балов</h3>',
'toggleButton' => [
'label' => 'Посчитать баллы',
'tag' => 'button',
'class' => 'btn btn-success',
],
]);
2021-11-08 12:41:39 +03:00
if(ScoreCalculatorHelper::checkAnswerFlagsForNull($model))
2021-10-22 17:02:28 +03:00
{
echo 'Ответы проверены. Посчитать баллы?';
echo Html::a('Посчитать баллы', ['calculate-score', 'id' => $model->id], [
'class' => 'btn btn-primary'
]);
}
else
{
echo 'Не все ответы проверены.';
}
?>
<?php Modal::end(); ?>
</p>
<div>
<h2>
<?= 'Ответы пользователя' ?>
</h2>
</div>
2021-10-29 17:06:09 +03:00
<?php Pjax::begin(['id' => 'user_responses']); ?>
<?php
echo GridView::widget([
'dataProvider' => $responseDataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'response_body',
[
'attribute' => 'question_id',
2021-11-08 12:41:39 +03:00
'value' => 'question.question_body'
2021-10-29 17:06:09 +03:00
],
[
'attribute' => 'Тип вопроса',
'value' => 'questionType.question_type',
2021-10-29 17:06:09 +03:00
],
[
'attribute' => 'answer_flag',
'format' => 'raw',
'value' => function ($model) {
return AnswerHelper::answerStatusLabel($model->answer_flag);
2021-10-22 17:02:28 +03:00
},
2021-10-22 17:02:28 +03:00
],
2021-10-29 17:06:09 +03:00
[
'class' => 'yii\grid\ActionColumn',
2021-11-08 12:41:39 +03:00
'template' => '{view} {update} {delete}',
'controller' => 'user-response',
2021-10-29 17:06:09 +03:00
'buttons' => [
2021-11-08 12:41:39 +03:00
2021-10-29 17:06:09 +03:00
'update' => function ($url,$model) {
return Html::a(
'<span class="glyphicon glyphicon-pencil"></span>',
['user-response/update', 'id' => $model['id'], 'user_questionnaire_uuid' => $model['user_questionnaire_uuid']]);
},
'delete' => function ($url,$model) {
return Html::a(
'<span class="glyphicon glyphicon-trash"></span>',
['user-response/delete', 'id' => $model['id'], 'user_questionnaire_uuid' => $model['user_questionnaire_uuid']],
['data' => ['confirm' => 'Вы уверены, что хотите удалить этот вопрос?', 'method' => 'post']]
);
2021-10-29 17:06:09 +03:00
},
],
],
2021-10-22 17:02:28 +03:00
],
2021-10-29 17:06:09 +03:00
]);
?>
<?php Pjax::end(); ?>
2021-10-22 17:02:28 +03:00
</div>