add filters, refactoring
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\questionnaire\models\Question;
|
||||
use backend\modules\questionnaire\models\UserQuestionnaire;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
@ -29,7 +31,7 @@ use yii\widgets\ActiveForm;
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->widget(Select2::class, [
|
||||
'data' => \yii\helpers\ArrayHelper::map(\common\models\User::find()->all(),'id', 'username'),
|
||||
'data' => \common\models\User::find()->select(['username','id'] )->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
@ -38,16 +40,15 @@ use yii\widgets\ActiveForm;
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'question_id')->widget(Select2::class,[
|
||||
'data' => \yii\helpers\ArrayHelper::map(\common\models\Question::find()
|
||||
// ->where('question_type_id != :question_type_id', ['question_type_id' => 1])
|
||||
->all(), 'id', 'question_body'),
|
||||
|
||||
'data' => Question::find()->select(['question_body', 'id'])->indexBy('id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true // 'id != :id', ['id'=>1]
|
||||
],
|
||||
])?>
|
||||
|
||||
<?= $form->field($model, 'user_questionnaire_id')->widget(Select2::class,[
|
||||
'data' => \yii\helpers\ArrayHelper::map(\common\models\UserQuestionnaire::find()->all(), 'id', 'id'),
|
||||
'data' => UserQuestionnaire::find()->select(['id', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
|
@ -1,7 +1,11 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\questionnaire\models\Questionnaire;
|
||||
use backend\modules\questionnaire\models\UserQuestionnaire;
|
||||
use common\helpers\AnswerHelper;
|
||||
use common\models\User;
|
||||
use kartik\depdrop\DepDrop;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\Url;
|
||||
@ -18,63 +22,31 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="user-responses-index">
|
||||
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Создать новый ответ пользователя', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<!-- --><?php //$form = ActiveForm::begin(); ?>
|
||||
|
||||
<!-- <?//= $form->field($model, 'user_id')->dropDownList(\yii\helpers\ArrayHelper::map(
|
||||
// \common\models\User::find()->all(), 'id', 'username'),
|
||||
// [
|
||||
// 'id'=>'user-id',
|
||||
// 'prompt' => 'Выберите пользователя'
|
||||
// ]
|
||||
// ) ?>
|
||||
-->
|
||||
|
||||
<!-- <?//= $form->field($questionnaire, 'title')->widget(DepDrop::classname(), [
|
||||
// 'options'=>['id'=>'questionnaire-id'],
|
||||
// 'pluginOptions'=>[
|
||||
// 'depends'=>['user-id'],
|
||||
// 'placeholder'=>'Выберите...',
|
||||
// 'url' => Url::to(['/questionnaire/user-response/questionnaire'])
|
||||
// ]
|
||||
// ]);?>
|
||||
-->
|
||||
|
||||
<!-- --><?php //ActiveForm::end(); ?>
|
||||
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
// 'id',
|
||||
// 'user_id',
|
||||
[
|
||||
'attribute' => 'user_questionnaire_id',
|
||||
'filter' => Questionnaire::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'value' => function($model){
|
||||
return $model->getQuestionnaireTitle();
|
||||
}
|
||||
],
|
||||
// 'user_questionnaire_id',
|
||||
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'value' => function($model){
|
||||
return $model->getUserName();
|
||||
}
|
||||
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'user.username',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'question_id',
|
||||
'value' => function($model){
|
||||
return $model->getQuestionBody();
|
||||
}
|
||||
'value' => 'question.question_body',
|
||||
],
|
||||
|
||||
'response_body',
|
||||
@ -86,15 +58,12 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
],
|
||||
[
|
||||
'attribute' => 'answer_flag',
|
||||
'filter' => AnswerHelper::answerFlagsList(),
|
||||
'format' => 'raw',
|
||||
'value' => function ($model) {
|
||||
return \common\helpers\AnswerHelper::answerFlagLable($model->answer_flag);
|
||||
return AnswerHelper::answerFlagLable($model->answer_flag);
|
||||
},
|
||||
],
|
||||
|
||||
// 'created_at',
|
||||
// 'updated_at',
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]); ?>
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
use common\helpers\AnswerHelper;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\web\YiiAsset;
|
||||
use yii\widgets\DetailView;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\questionnaire\models\UserResponse */
|
||||
@ -11,7 +13,7 @@ use yii\grid\GridView;
|
||||
$this->title =cut_title($model->response_body);
|
||||
$this->params['breadcrumbs'][] = ['label' => 'User Responses', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
YiiAsset::register($this);
|
||||
|
||||
function cut_title($str)
|
||||
{
|
||||
@ -41,15 +43,11 @@ function cut_title($str)
|
||||
'id',
|
||||
[
|
||||
'attribute' => 'Пользователь',
|
||||
'value' => function($model){
|
||||
return $model->getUserName();
|
||||
}
|
||||
'value' => ArrayHelper::getValue($model,'user.username'),
|
||||
],
|
||||
[
|
||||
'attribute' => 'Вопрос',
|
||||
'value' => function($model){
|
||||
return $model->getQuestionBody();
|
||||
}
|
||||
'value' => ArrayHelper::getValue($model,'question.question_body'),
|
||||
],
|
||||
'response_body',
|
||||
'created_at',
|
||||
@ -57,9 +55,7 @@ function cut_title($str)
|
||||
[
|
||||
'attribute' => 'answer_flag',
|
||||
'format' => 'raw',
|
||||
'value' => function ($model) {
|
||||
return \common\helpers\AnswerHelper::answerFlagLable($model->answer_flag);
|
||||
},
|
||||
'value' => AnswerHelper::answerFlagLable($model->answer_flag),
|
||||
],
|
||||
'user_questionnaires_uuid',
|
||||
],
|
||||
|
Reference in New Issue
Block a user