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' => [
'request' => [
'csrfParam' => '_csrf-backend',
'baseUrl' => '', // /secure
'baseUrl' => '/secure', // /secure
'parsers' => [
'application/json' => 'yii\web\JsonParser',
'text/xml' => 'yii/web/XmlParser',

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -70,13 +70,7 @@ YiiAsset::register($this);
'attribute' => 'status',
'format' => 'raw',
'value' => function($model) {
return Html::tag(
'span',
$model->status ? 'Active' : 'Not Active',
[
'class' => 'label label-' . ($model->status ? 'success' : 'danger'),
]
);
return common\helpers\StatusHelper::statusLabel($model->status);
},
],
'created_at',
@ -149,30 +143,9 @@ YiiAsset::register($this);
'attribute' => 'answer_flag',
'format' => 'raw',
'value' => function ($model) {
$answerFlag = $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,
]
);
return \common\helpers\AnswerHelper::answerFlagLable($model->answer_flag);
},
],
[
'class' => 'yii\grid\ActionColumn',

View File

@ -88,29 +88,7 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'answer_flag',
'format' => 'raw',
'value' => function ($model) {
$answerFlag = $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,
]
);
return \common\helpers\AnswerHelper::answerFlagLable($model->answer_flag);
},
],

View File

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

View File

@ -22,7 +22,7 @@ class AnswerHelper
/**
* @throws Exception
*/
public static function statusLabel($status): string
public static function answerStatusLabel($status): string
{
switch ($status) {
case self::FLAG_FALSE:
@ -39,4 +39,27 @@ class AnswerHelper
'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;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
@ -11,13 +12,13 @@ class TimeHelper
{
if ($time_limit === null)
{
return 'Не ограниченоTEST';
return 'Не ограничено';
}
return date("H:i:s", mktime(null, null, $time_limit)) . ' (HH:mm:ss)';
// $date
// return Html::tag('span', $date, ['class' => 'label label-primary']);
return Html::tag(
'span',
Yii::$app->formatter->asDuration(strtotime($time_limit, '0')),
['class' => 'label label-primary']
);
}
}

View File

@ -17,7 +17,7 @@ use yii\db\Expression;
* @property int $next_question
* @property int $status
* @property int $score
* @property int $time_limit
* @property string $time_limit
* @property string $created_at
* @property string $updated_at
*
@ -59,14 +59,27 @@ class Question extends \yii\db\ActiveRecord
{
return [
[['status', 'question_type_id', 'questionnaire_id', 'question_body', 'score'], 'required'],
[['question_type_id', 'questionnaire_id', 'question_priority', 'next_question', 'status', 'score', 'time_limit'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['question_type_id', 'questionnaire_id', 'question_priority', 'next_question', 'status', 'score'], 'integer'],
[['created_at', 'updated_at', 'time_limit'], 'safe'],
[['question_body'], 'string', 'max' => 255],
[['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']],
];
}
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}
*/
@ -120,14 +133,6 @@ class Question extends \yii\db\ActiveRecord
return $this->hasMany(UserResponse::className(), ['question_id' => 'id']);
}
public function getStatuses()
{
return [
self::STATUS_ACTIVE => 'Активен',
self::STATUS_PASSIVE => 'Не используется'
];
}
public function getStatusText()
{
return $this->statuses[$this->status];

View File

@ -15,7 +15,7 @@ use yii\helpers\ArrayHelper;
* @property int $status
* @property string $created_at
* @property string $updated_at
* @property int $time_limit
* @property string $time_limit
*
* @property Question[] $questions
* @property QuestionnaireCategory $category
@ -52,8 +52,9 @@ class Questionnaire extends \yii\db\ActiveRecord
public function rules()
{
return [
[['category_id', 'status', 'time_limit'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['category_id', 'status', 'title'], 'required'],
[['category_id', 'status'], 'integer'],
[['created_at', 'updated_at', 'time_limit'], 'safe'],
['title', 'unique'],
[['title'], 'string', 'max' => 255],
['status', 'default', 'value' => self::STATUS_ACTIVE],
@ -73,10 +74,23 @@ class Questionnaire extends \yii\db\ActiveRecord
'status' => 'Статус',
'created_at' => 'Created 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
*/

View File

@ -37,7 +37,8 @@
"ramsey/uuid": "^4.2",
"kartik-v/yii2-widget-depdrop": "dev-master",
"2amigos/yii2-transliterator-helper": "*",
"ext-json": "*"
"ext-json": "*",
"kartik-v/yii2-widget-timepicker": "dev-master"
},
"require-dev": {
"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",
"This file is @generated automatically"
],
"content-hash": "1f09d47b3a935abd3aae2c9a33ff84e5",
"content-hash": "b61e162658b6b66bebc3ba305d476c8c",
"packages": [
{
"name": "2amigos/yii2-file-upload-widget",
@ -1530,12 +1530,12 @@
"source": {
"type": "git",
"url": "https://github.com/kartik-v/yii2-widget-datetimepicker.git",
"reference": "f64114bff520ea67f48e2a4e6372915968eb2c69"
"reference": "881985a5e482a4e37d1901c7857912ba5af3f298"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kartik-v/yii2-widget-datetimepicker/zipball/f64114bff520ea67f48e2a4e6372915968eb2c69",
"reference": "f64114bff520ea67f48e2a4e6372915968eb2c69",
"url": "https://api.github.com/repos/kartik-v/yii2-widget-datetimepicker/zipball/881985a5e482a4e37d1901c7857912ba5af3f298",
"reference": "881985a5e482a4e37d1901c7857912ba5af3f298",
"shasum": ""
},
"require": {
@ -1545,7 +1545,7 @@
"type": "yii2-extension",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
"dev-master": "1.5.x-dev"
}
},
"autoload": {
@ -1579,9 +1579,9 @@
],
"support": {
"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",
@ -1772,6 +1772,65 @@
],
"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",
"version": "dev-master",
@ -7022,12 +7081,14 @@
"kartik-v/yii2-widget-datepicker": 20,
"kartik-v/yii2-grid": 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-lowest": false,
"platform": {
"php": ">=7.1.0"
"php": ">=7.1.0",
"ext-json": "*"
},
"platform-dev": [],
"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