change time widget in question and questionnaire forms

This commit is contained in:
iIronside 2021-11-02 17:29:15 +03:00
parent 7b8847e1e1
commit f8bacb7b58
23 changed files with 5795 additions and 117 deletions

View File

@ -81,7 +81,7 @@ return [
'components' => [ 'components' => [
'request' => [ 'request' => [
'csrfParam' => '_csrf-backend', 'csrfParam' => '_csrf-backend',
'baseUrl' => '', // /secure 'baseUrl' => '/secure', // /secure
'parsers' => [ 'parsers' => [
'application/json' => 'yii\web\JsonParser', 'application/json' => 'yii\web\JsonParser',
'text/xml' => 'yii/web/XmlParser', 'text/xml' => 'yii/web/XmlParser',

View File

@ -17,8 +17,8 @@ class QuestionSearch extends Question
public function rules() public function rules()
{ {
return [ return [
[['id', 'question_type_id', 'questionnaire_id', 'question_priority', 'next_question', 'status', 'score', 'time_limit'], 'integer'], [['id', 'question_type_id', 'questionnaire_id', 'question_priority', 'next_question', 'status', 'score'], 'integer'],
[['question_body', 'created_at', 'updated_at'], 'safe'], [['question_body', 'created_at', 'updated_at', 'time_limit'], 'safe'],
]; ];
} }

View File

@ -36,7 +36,7 @@ $this->params['breadcrumbs'][] = $this->title;
'format' => 'raw', 'format' => 'raw',
'filter' => \common\helpers\AnswerHelper::answerFlagsList(), 'filter' => \common\helpers\AnswerHelper::answerFlagsList(),
'value' => function ($model) { 'value' => function ($model) {
return \common\helpers\AnswerHelper::statusLabel($model->answer_flag); return \common\helpers\AnswerHelper::answerStatusLabel($model->answer_flag);
}, },
], ],
[ [

View File

@ -48,7 +48,7 @@ function cut_title($str)
'format' => 'raw', 'format' => 'raw',
'filter' => \common\helpers\AnswerHelper::answerFlagsList(), 'filter' => \common\helpers\AnswerHelper::answerFlagsList(),
'value' => function ($model) { 'value' => function ($model) {
return \common\helpers\AnswerHelper::statusLabel($model->status); return \common\helpers\AnswerHelper::answerStatusLabel($model->status);
}, },
], ],
[ [

View File

@ -1,6 +1,7 @@
<?php <?php
use kartik\select2\Select2; use kartik\select2\Select2;
use kartik\time\TimePicker;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -46,18 +47,16 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'time_limit')->dropDownList( <?= $form->field($model, 'time_limit')->widget(TimePicker::class,
[ [
'' => 'Не ограничено', 'name' => 'time_limit_picker',
'30' => '30 секунд', 'pluginOptions' => [
'60' => '1 минута', 'showSeconds' => false,
'90' => '1:30 секунд', 'showMeridian' => false,
'120' => '2 минуты', 'minuteStep' => 1,
'180' => '3 минуты', 'defaultTime' => ''
'300' => '5 минут',
'600' => '10 минут',
] ]
) ?> ]) ?>
<?= $form->field($model, 'score')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'score')->textInput(['maxlength' => true]) ?>

View File

@ -24,12 +24,14 @@ $this->params['breadcrumbs'][] = $this->title;
'question_body', 'question_body',
[ [
'attribute' => 'question_type_id', 'attribute' => 'question_type_id',
'filter' => \yii\helpers\ArrayHelper::map(\backend\modules\questionnaire\models\QuestionType::find()->all(), 'id', 'question_type'),
'value' => function($model){ 'value' => function($model){
return $model->getQuestionTitle(); return $model->getQuestionTitle();
} }
], ],
[ [
'attribute' => 'questionnaire_id', 'attribute' => 'questionnaire_id',
'filter' => \yii\helpers\ArrayHelper::map(\backend\modules\questionnaire\models\Questionnaire::find()->all(), 'id', 'title'),
'value' => function($model){ 'value' => function($model){
return $model->getQuestionnaireTitle(); return $model->getQuestionnaireTitle();
} }
@ -46,6 +48,7 @@ $this->params['breadcrumbs'][] = $this->title;
], ],
[ [
'attribute' => 'time_limit', 'attribute' => 'time_limit',
'format' => 'raw',
'value' => function($model){ 'value' => function($model){
return \common\helpers\TimeHelper::limitTime($model->time_limit); return \common\helpers\TimeHelper::limitTime($model->time_limit);
} }

View File

@ -56,6 +56,7 @@ $this->params['breadcrumbs'][] = $this->title;
'updated_at', 'updated_at',
[ [
'attribute' => 'time_limit', 'attribute' => 'time_limit',
'format' => 'raw',
'value' => function($model){ 'value' => function($model){
return \common\helpers\TimeHelper::limitTime($model->time_limit); return \common\helpers\TimeHelper::limitTime($model->time_limit);
} }

View File

@ -1,6 +1,7 @@
<?php <?php
use kartik\select2\Select2; use kartik\select2\Select2;
use kartik\time\TimePicker;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -32,21 +33,19 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'time_limit')->dropDownList( <?= $form->field($model, 'time_limit')->widget(TimePicker::class,
[ [
'' => 'Не ограничено', 'name' => 'time_limit_picker',
'600' => '10 минут', 'pluginOptions' => [
'900' => '15 минут', 'showSeconds' => false,
'1200' => '20 минут', 'showMeridian' => false,
'1800' => '30 минут', 'minuteStep' => 1,
'2700' => '45 минут', 'defaultTime' => ''
'3600' => '1 час',
] ]
) ]) ?>
?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?> <?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

View File

@ -34,12 +34,14 @@ $this->params['breadcrumbs'][] = $this->title;
], ],
[ [
'attribute' => 'category_id', 'attribute' => 'category_id',
'filter' => \yii\helpers\ArrayHelper::map(common\models\QuestionnaireCategory::find()->all(), 'id', 'title'),
'value' => function($model){ 'value' => function($model){
return $model->getCategoryTitle(); return $model->getCategoryTitle();
} }
], ],
[ [
'attribute' => 'time_limit', 'attribute' => 'time_limit',
'format' => 'raw',
'value' => function($model){ 'value' => function($model){
return \common\helpers\TimeHelper::limitTime($model->time_limit); return \common\helpers\TimeHelper::limitTime($model->time_limit);
} }

View File

@ -50,10 +50,11 @@ $this->params['breadcrumbs'][] = $this->title;
'updated_at', 'updated_at',
[ [
'attribute' => 'time_limit', 'attribute' => 'time_limit',
'format' => 'raw',
'value' => function($model){ 'value' => function($model){
return \common\helpers\TimeHelper::limitTime($model->time_limit); return \common\helpers\TimeHelper::limitTime($model->time_limit);
} }
] ],
], ],
]) ?> ]) ?>
@ -70,7 +71,13 @@ $this->params['breadcrumbs'][] = $this->title;
'filterModel' => $questionSearchModel, 'filterModel' => $questionSearchModel,
'columns' => [ 'columns' => [
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
'question_type_id', [
'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();
}
],
'question_body', 'question_body',
[ [
'attribute' => 'status', 'attribute' => 'status',

View File

@ -23,12 +23,14 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
[ [
'attribute' => 'questionnaire_id', 'attribute' => 'questionnaire_id',
'filter' => \yii\helpers\ArrayHelper::map(backend\modules\questionnaire\models\Questionnaire::find()->all(), 'id', 'title'),
'value' => function($model){ 'value' => function($model){
return $model->getQuestionnaireTitle(); return $model->getQuestionnaireTitle();
} }
], ],
[ [
'attribute' => 'user_id', 'attribute' => 'user_id',
'filter' => \yii\helpers\ArrayHelper::map(\common\models\User::find()->all(), 'id', 'username'),
'value' => function($model){ 'value' => function($model){
return $model->getUserName(); return $model->getUserName();
} }

View File

@ -70,13 +70,7 @@ YiiAsset::register($this);
'attribute' => 'status', 'attribute' => 'status',
'format' => 'raw', 'format' => 'raw',
'value' => function($model) { 'value' => function($model) {
return Html::tag( return common\helpers\StatusHelper::statusLabel($model->status);
'span',
$model->status ? 'Active' : 'Not Active',
[
'class' => 'label label-' . ($model->status ? 'success' : 'danger'),
]
);
}, },
], ],
'created_at', 'created_at',
@ -149,30 +143,9 @@ YiiAsset::register($this);
'attribute' => 'answer_flag', 'attribute' => 'answer_flag',
'format' => 'raw', 'format' => 'raw',
'value' => function ($model) { 'value' => function ($model) {
$answerFlag = $model->answer_flag; return \common\helpers\AnswerHelper::answerFlagLable($model->answer_flag);
$class = 'label label-warning';
$content = 'Not verified';
if ($answerFlag > 0)
{
$class = 'label label-success';
$answerFlag < 1 ? $content = $answerFlag *100 . '%' : $content = 'True';
}
else if ($answerFlag === 0.0)
{
$class = 'label label-danger';
$content = 'Wrong';
}
return Html::tag(
'span',
$content,
[
'class' => $class,
]
);
}, },
], ],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',

View File

@ -88,29 +88,7 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'answer_flag', 'attribute' => 'answer_flag',
'format' => 'raw', 'format' => 'raw',
'value' => function ($model) { 'value' => function ($model) {
$answerFlag = $model->answer_flag; return \common\helpers\AnswerHelper::answerFlagLable($model->answer_flag);
$class = 'label label-warning';
$content = 'Not verified';
if ($answerFlag > 0)
{
$class = 'label label-success';
$answerFlag < 1 ? $content = $answerFlag *100 . '%' : $content = 'True';
}
else if ($answerFlag === 0.0)
{
$class = 'label label-danger';
$content = 'Wrong';
}
return Html::tag(
'span',
$content,
[
'class' => $class,
]
);
}, },
], ],

View File

@ -54,7 +54,13 @@ function cut_title($str)
'response_body', 'response_body',
'created_at', 'created_at',
'updated_at', 'updated_at',
'answer_flag', [
'attribute' => 'answer_flag',
'format' => 'raw',
'value' => function ($model) {
return \common\helpers\AnswerHelper::answerFlagLable($model->answer_flag);
},
],
'user_questionnaires_uuid', 'user_questionnaires_uuid',
], ],
]) ?> ]) ?>

View File

@ -22,7 +22,7 @@ class AnswerHelper
/** /**
* @throws Exception * @throws Exception
*/ */
public static function statusLabel($status): string public static function answerStatusLabel($status): string
{ {
switch ($status) { switch ($status) {
case self::FLAG_FALSE: case self::FLAG_FALSE:
@ -39,4 +39,27 @@ class AnswerHelper
'class' => $class, 'class' => $class,
]); ]);
} }
public static function answerFlagLable($answer_flag)
{
$class = 'label label-warning';
$content = 'Не проверен';
if ($answer_flag > 0)
{
$class = 'label label-success';
$answer_flag < 1 ? $content = $answer_flag *100 . '%' : $content = 'Верен';
}
else if ($answer_flag === 0.0)
{
$class = 'label label-danger';
$content = 'Не верен';
}
return Html::tag('span', $content,
[
'class' => $class,
]
);
}
} }

View File

@ -2,6 +2,7 @@
namespace common\helpers; namespace common\helpers;
use Yii;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
@ -11,13 +12,13 @@ class TimeHelper
{ {
if ($time_limit === null) if ($time_limit === null)
{ {
return 'Не ограниченоTEST'; return 'Не ограничено';
} }
return date("H:i:s", mktime(null, null, $time_limit)) . ' (HH:mm:ss)'; return Html::tag(
'span',
// $date Yii::$app->formatter->asDuration(strtotime($time_limit, '0')),
// return Html::tag('span', $date, ['class' => 'label label-primary']); ['class' => 'label label-primary']
);
} }
} }

View File

@ -17,7 +17,7 @@ use yii\db\Expression;
* @property int $next_question * @property int $next_question
* @property int $status * @property int $status
* @property int $score * @property int $score
* @property int $time_limit * @property string $time_limit
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
* *
@ -59,14 +59,27 @@ class Question extends \yii\db\ActiveRecord
{ {
return [ return [
[['status', 'question_type_id', 'questionnaire_id', 'question_body', 'score'], 'required'], [['status', 'question_type_id', 'questionnaire_id', 'question_body', 'score'], 'required'],
[['question_type_id', 'questionnaire_id', 'question_priority', 'next_question', 'status', 'score', 'time_limit'], 'integer'], [['question_type_id', 'questionnaire_id', 'question_priority', 'next_question', 'status', 'score'], 'integer'],
[['created_at', 'updated_at'], 'safe'], [['created_at', 'updated_at', 'time_limit'], 'safe'],
[['question_body'], 'string', 'max' => 255], [['question_body'], 'string', 'max' => 255],
[['questionnaire_id'], 'exist', 'skipOnError' => true, 'targetClass' => Questionnaire::className(), 'targetAttribute' => ['questionnaire_id' => 'id']], [['questionnaire_id'], 'exist', 'skipOnError' => true, 'targetClass' => Questionnaire::className(), 'targetAttribute' => ['questionnaire_id' => 'id']],
[['question_type_id'], 'exist', 'skipOnError' => true, 'targetClass' => QuestionType::className(), 'targetAttribute' => ['question_type_id' => 'id']], [['question_type_id'], 'exist', 'skipOnError' => true, 'targetClass' => QuestionType::className(), 'targetAttribute' => ['question_type_id' => 'id']],
]; ];
} }
public function beforeSave($insert): bool
{
if (parent::beforeSave($insert)) {
if (strtotime($this->time_limit, '0') === 0)
{
$this->time_limit = null;
}
return true;
} else {
return false;
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -120,14 +133,6 @@ class Question extends \yii\db\ActiveRecord
return $this->hasMany(UserResponse::className(), ['question_id' => 'id']); return $this->hasMany(UserResponse::className(), ['question_id' => 'id']);
} }
public function getStatuses()
{
return [
self::STATUS_ACTIVE => 'Активен',
self::STATUS_PASSIVE => 'Не используется'
];
}
public function getStatusText() public function getStatusText()
{ {
return $this->statuses[$this->status]; return $this->statuses[$this->status];

View File

@ -15,7 +15,7 @@ use yii\helpers\ArrayHelper;
* @property int $status * @property int $status
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
* @property int $time_limit * @property string $time_limit
* *
* @property Question[] $questions * @property Question[] $questions
* @property QuestionnaireCategory $category * @property QuestionnaireCategory $category
@ -52,8 +52,9 @@ class Questionnaire extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['category_id', 'status', 'time_limit'], 'integer'], [['category_id', 'status', 'title'], 'required'],
[['created_at', 'updated_at'], 'safe'], [['category_id', 'status'], 'integer'],
[['created_at', 'updated_at', 'time_limit'], 'safe'],
['title', 'unique'], ['title', 'unique'],
[['title'], 'string', 'max' => 255], [['title'], 'string', 'max' => 255],
['status', 'default', 'value' => self::STATUS_ACTIVE], ['status', 'default', 'value' => self::STATUS_ACTIVE],
@ -73,10 +74,23 @@ class Questionnaire extends \yii\db\ActiveRecord
'status' => 'Статус', 'status' => 'Статус',
'created_at' => 'Created At', 'created_at' => 'Created At',
'updated_at' => 'Updated At', 'updated_at' => 'Updated At',
'time_limit' => 'Время на выполнение', 'time_limit' => 'Время на выполнение (HH:mm)',
]; ];
} }
public function beforeSave($insert): bool
{
if (parent::beforeSave($insert)) {
if (strtotime($this->time_limit, '0') === 0)
{
$this->time_limit = null;
}
return true;
} else {
return false;
}
}
/** /**
* @return \yii\db\ActiveQuery * @return \yii\db\ActiveQuery
*/ */

View File

@ -37,7 +37,8 @@
"ramsey/uuid": "^4.2", "ramsey/uuid": "^4.2",
"kartik-v/yii2-widget-depdrop": "dev-master", "kartik-v/yii2-widget-depdrop": "dev-master",
"2amigos/yii2-transliterator-helper": "*", "2amigos/yii2-transliterator-helper": "*",
"ext-json": "*" "ext-json": "*",
"kartik-v/yii2-widget-timepicker": "dev-master"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.0.0", "yiisoft/yii2-debug": "~2.0.0",

79
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "1f09d47b3a935abd3aae2c9a33ff84e5", "content-hash": "b61e162658b6b66bebc3ba305d476c8c",
"packages": [ "packages": [
{ {
"name": "2amigos/yii2-file-upload-widget", "name": "2amigos/yii2-file-upload-widget",
@ -1530,12 +1530,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/kartik-v/yii2-widget-datetimepicker.git", "url": "https://github.com/kartik-v/yii2-widget-datetimepicker.git",
"reference": "f64114bff520ea67f48e2a4e6372915968eb2c69" "reference": "881985a5e482a4e37d1901c7857912ba5af3f298"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/kartik-v/yii2-widget-datetimepicker/zipball/f64114bff520ea67f48e2a4e6372915968eb2c69", "url": "https://api.github.com/repos/kartik-v/yii2-widget-datetimepicker/zipball/881985a5e482a4e37d1901c7857912ba5af3f298",
"reference": "f64114bff520ea67f48e2a4e6372915968eb2c69", "reference": "881985a5e482a4e37d1901c7857912ba5af3f298",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1545,7 +1545,7 @@
"type": "yii2-extension", "type": "yii2-extension",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.4.x-dev" "dev-master": "1.5.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -1579,9 +1579,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/kartik-v/yii2-widget-datetimepicker/issues", "issues": "https://github.com/kartik-v/yii2-widget-datetimepicker/issues",
"source": "https://github.com/kartik-v/yii2-widget-datetimepicker/tree/master" "source": "https://github.com/kartik-v/yii2-widget-datetimepicker/tree/v1.5.0"
}, },
"time": "2020-09-11T13:24:42+00:00" "time": "2021-10-28T03:39:38+00:00"
}, },
{ {
"name": "kartik-v/yii2-widget-depdrop", "name": "kartik-v/yii2-widget-depdrop",
@ -1772,6 +1772,65 @@
], ],
"time": "2021-10-06T11:17:54+00:00" "time": "2021-10-06T11:17:54+00:00"
}, },
{
"name": "kartik-v/yii2-widget-timepicker",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/kartik-v/yii2-widget-timepicker.git",
"reference": "680aec2d79846e926c072da455cf6f33e1c3bb12"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kartik-v/yii2-widget-timepicker/zipball/680aec2d79846e926c072da455cf6f33e1c3bb12",
"reference": "680aec2d79846e926c072da455cf6f33e1c3bb12",
"shasum": ""
},
"require": {
"kartik-v/yii2-krajee-base": ">=2.0.0"
},
"default-branch": true,
"type": "yii2-extension",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"kartik\\time\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Kartik Visweswaran",
"email": "kartikv2@gmail.com",
"homepage": "http://www.krajee.com/"
}
],
"description": "Enhanced Yii2 wrapper for the bootstrap timepicker plugin (sub repo split from yii2-widgets)",
"homepage": "https://github.com/kartik-v/yii2-widget-timepicker",
"keywords": [
"bootstrap",
"extension",
"form",
"jquery",
"picker",
"plugin",
"time",
"widget",
"yii2"
],
"support": {
"issues": "https://github.com/kartik-v/yii2-widget-timepicker/issues",
"source": "https://github.com/kartik-v/yii2-widget-timepicker/tree/v1.0.5"
},
"time": "2021-10-28T03:49:56+00:00"
},
{ {
"name": "kavalar/hhapi", "name": "kavalar/hhapi",
"version": "dev-master", "version": "dev-master",
@ -7022,12 +7081,14 @@
"kartik-v/yii2-widget-datepicker": 20, "kartik-v/yii2-widget-datepicker": 20,
"kartik-v/yii2-grid": 20, "kartik-v/yii2-grid": 20,
"kartik-v/yii2-widget-datetimepicker": 20, "kartik-v/yii2-widget-datetimepicker": 20,
"kartik-v/yii2-widget-depdrop": 20 "kartik-v/yii2-widget-depdrop": 20,
"kartik-v/yii2-widget-timepicker": 20
}, },
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": ">=7.1.0" "php": ">=7.1.0",
"ext-json": "*"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.1.0" "plugin-api-version": "2.1.0"

View File

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Class m211102_130441_change_time_limit_type_in_questionnaire_table
*/
class m211102_130441_change_time_limit_type_in_questionnaire_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->alterColumn('questionnaire','time_limit', 'time' );
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->alterColumn('questionnaire','time_limit', 'integer' );
}
}

View File

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Class m211102_130931_change_time_limit_type_in_question_table
*/
class m211102_130931_change_time_limit_type_in_question_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->alterColumn('question','time_limit', 'time' );
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->alterColumn('question','time_limit', 'integer' );
}
}

File diff suppressed because it is too large Load Diff