change time widget in question and questionnaire forms
This commit is contained in:
@ -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,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
@ -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']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -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];
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user