add filters, refactoring
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
<?php
|
||||
|
||||
use backend\components\timepicker\src\TimePicker;
|
||||
use backend\modules\questionnaire\models\Questionnaire;
|
||||
use backend\modules\questionnaire\models\QuestionType;
|
||||
use common\helpers\StatusHelper;
|
||||
use kartik\select2\Select2;
|
||||
use kartik\time\TimePicker;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
@ -16,7 +19,7 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?= $form->field($model, 'question_type_id')->widget(Select2::class,
|
||||
[
|
||||
'data' => \yii\helpers\ArrayHelper::map(\common\models\QuestionType::find()->all(),'id', 'question_type'),
|
||||
'data' => QuestionType::find()->select(['question_type', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
@ -26,7 +29,7 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?= $form->field($model, 'questionnaire_id')->widget(Select2::class,
|
||||
[
|
||||
'data' => \yii\helpers\ArrayHelper::map(\common\models\Questionnaire::find()->all(),'id', 'title'),
|
||||
'data' => Questionnaire::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
@ -41,13 +44,13 @@ use yii\widgets\ActiveForm;
|
||||
<?= $form->field($model, 'next_question')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'status')->dropDownList(
|
||||
\common\helpers\StatusHelper::statusList(),
|
||||
StatusHelper::statusList(),
|
||||
[
|
||||
'prompt' => 'Выберите'
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'time_limit')->widget(\backend\components\timepicker\src\TimePicker::class,
|
||||
<?= $form->field($model, 'time_limit')->widget(TimePicker::class,
|
||||
[
|
||||
'name' => 'time_limit_picker',
|
||||
'pluginOptions' => [
|
||||
@ -60,8 +63,6 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?= $form->field($model, 'score')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\questionnaire\models\Questionnaire;
|
||||
use backend\modules\questionnaire\models\QuestionType;
|
||||
use common\helpers\StatusHelper;
|
||||
use common\helpers\TimeHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
@ -24,33 +28,29 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'question_body',
|
||||
[
|
||||
'attribute' => 'question_type_id',
|
||||
'filter' => \yii\helpers\ArrayHelper::map(\backend\modules\questionnaire\models\QuestionType::find()->all(), 'id', 'question_type'),
|
||||
'value' => function($model){
|
||||
return $model->getQuestionTitle();
|
||||
}
|
||||
'filter' => QuestionType::find()->select(['question_type', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'questionType.question_type'
|
||||
],
|
||||
[
|
||||
'attribute' => 'questionnaire_id',
|
||||
'filter' => \yii\helpers\ArrayHelper::map(\backend\modules\questionnaire\models\Questionnaire::find()->all(), 'id', 'title'),
|
||||
'value' => function($model){
|
||||
return $model->getQuestionnaireTitle();
|
||||
}
|
||||
'filter' => Questionnaire::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'questionnaire.title',
|
||||
],
|
||||
'question_priority',
|
||||
'next_question',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'format' => 'raw',
|
||||
'filter' => \common\helpers\StatusHelper::statusList(),
|
||||
'filter' => StatusHelper::statusList(),
|
||||
'value' => function ($model) {
|
||||
return \common\helpers\StatusHelper::statusLabel($model->status);
|
||||
return StatusHelper::statusLabel($model->status);
|
||||
},
|
||||
],
|
||||
[
|
||||
'attribute' => 'time_limit',
|
||||
'format' => 'raw',
|
||||
'value' => function($model){
|
||||
return \common\helpers\TimeHelper::limitTime($model->time_limit);
|
||||
return TimeHelper::limitTime($model->time_limit);
|
||||
}
|
||||
],
|
||||
'score',
|
||||
|
@ -1,10 +1,17 @@
|
||||
<?php
|
||||
|
||||
use common\helpers\AnswerHelper;
|
||||
use common\helpers\StatusHelper;
|
||||
use common\helpers\TimeHelper;
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\questionnaire\models\Question */
|
||||
/* @var $answerSearchModel backend\modules\questionnaire\models\Question */
|
||||
/* @var $answerDataProvider backend\modules\questionnaire\models\Question */
|
||||
|
||||
$this->title = $model->question_body;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Questions', 'url' => ['index']];
|
||||
@ -31,15 +38,11 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'id',
|
||||
[
|
||||
'attribute' => 'question_type_id',
|
||||
'value' => function($model){
|
||||
return $model->getQuestionTitle();
|
||||
}
|
||||
'value' => ArrayHelper::getValue($model, 'questionType.question_type'),
|
||||
],
|
||||
[
|
||||
'attribute' => 'questionnaire_id',
|
||||
'value' => function($model){
|
||||
return $model->getQuestionnaireTitle();
|
||||
}
|
||||
'value' => ArrayHelper::getValue($model,'questionnaire.title'),
|
||||
],
|
||||
'question_body',
|
||||
'question_priority',
|
||||
@ -47,22 +50,81 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'format' => 'raw',
|
||||
'filter' => \common\helpers\StatusHelper::statusList(),
|
||||
'value' => function ($model) {
|
||||
return \common\helpers\StatusHelper::statusLabel($model->status);
|
||||
},
|
||||
'filter' => StatusHelper::statusList(),
|
||||
'value' => StatusHelper::statusLabel($model->status),
|
||||
],
|
||||
'created_at',
|
||||
'updated_at',
|
||||
[
|
||||
'attribute' => 'time_limit',
|
||||
'format' => 'raw',
|
||||
'value' => function($model){
|
||||
return \common\helpers\TimeHelper::limitTime($model->time_limit);
|
||||
}
|
||||
'value' => TimeHelper::limitTime($model->time_limit),
|
||||
],
|
||||
'score'
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<div>
|
||||
<h2>
|
||||
<?= 'Ответы: '?>
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $answerDataProvider,
|
||||
'filterModel' => $answerSearchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
'answer_body',
|
||||
[
|
||||
'attribute' => 'answer_flag',
|
||||
'format' => 'raw',
|
||||
'filter' => AnswerHelper::answerFlagsList(),
|
||||
'value' => function ($model) {
|
||||
return AnswerHelper::answerStatusLabel($model->answer_flag);
|
||||
},
|
||||
],
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'format' => 'raw',
|
||||
'filter' => StatusHelper::statusList(),
|
||||
'value' => function($model){
|
||||
return StatusHelper::statusLabel($model->status);
|
||||
}
|
||||
],
|
||||
[
|
||||
'class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view} {update} {delete}',
|
||||
'controller' => 'answer',
|
||||
'buttons' => [
|
||||
|
||||
'update' => function ($url,$model) {
|
||||
return Html::a(
|
||||
'<span class="glyphicon glyphicon-pencil"></span>',
|
||||
['answer/update', 'id' => $model['id'], 'question_id' => $model['question_id']]);
|
||||
},
|
||||
'delete' => function ($url,$model) {
|
||||
return Html::a(
|
||||
'<span class="glyphicon glyphicon-trash"></span>',
|
||||
[
|
||||
'answer/delete', 'id' => $model['id'], 'question_id' => $model['question_id']
|
||||
],
|
||||
[
|
||||
'data' => ['confirm' => 'Вы уверены, что хотите удалить этот вопрос?', 'method' => 'post']
|
||||
]
|
||||
);
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a(
|
||||
'Добавить новый ответ',
|
||||
['answer/create', 'question_id' => $model->id],
|
||||
['class' => 'btn btn-primary']
|
||||
) ?>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user