2021-10-29 17:06:09 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace common\helpers;
|
|
|
|
|
|
|
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
use Exception;
|
|
|
|
|
use yii\helpers\Html;
|
|
|
|
|
|
|
|
|
|
class AnswerHelper
|
|
|
|
|
{
|
|
|
|
|
const FLAG_TRUE = 1;
|
|
|
|
|
const FLAG_FALSE = 0;
|
2022-03-15 19:30:53 +03:00
|
|
|
|
const FLAG_NOT_VERIFIED = null;
|
2021-10-29 17:06:09 +03:00
|
|
|
|
|
|
|
|
|
public static function answerFlagsList(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
self::FLAG_TRUE => 'Верен',
|
|
|
|
|
self::FLAG_FALSE => 'Ошибочный',
|
2022-03-15 19:30:53 +03:00
|
|
|
|
self::FLAG_NOT_VERIFIED => 'Не проверен',
|
2021-10-29 17:06:09 +03:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-11-09 17:41:44 +03:00
|
|
|
|
public static function answerFlagLabel($status): string
|
2021-10-29 17:06:09 +03:00
|
|
|
|
{
|
2022-03-15 19:30:53 +03:00
|
|
|
|
switch (true) {
|
|
|
|
|
case ($status === self::FLAG_FALSE):
|
2021-10-29 17:06:09 +03:00
|
|
|
|
$class = 'label label-danger';
|
|
|
|
|
break;
|
2022-03-15 19:30:53 +03:00
|
|
|
|
case ($status === self::FLAG_TRUE):
|
2021-10-29 17:06:09 +03:00
|
|
|
|
$class = 'label label-success';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2022-03-15 19:30:53 +03:00
|
|
|
|
$class = 'label label-warning';
|
2021-10-29 17:06:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Html::tag('span', ArrayHelper::getValue(self::answerFlagsList(), $status), [
|
|
|
|
|
'class' => $class,
|
|
|
|
|
]);
|
|
|
|
|
}
|
2021-11-02 17:29:15 +03:00
|
|
|
|
|
2021-11-09 17:41:44 +03:00
|
|
|
|
public static function answerStatusLabel($answer_flag): string
|
2021-11-02 17:29:15 +03:00
|
|
|
|
{
|
|
|
|
|
$class = 'label label-warning';
|
|
|
|
|
$content = 'Не проверен';
|
|
|
|
|
|
2021-11-12 14:30:01 +03:00
|
|
|
|
if ($answer_flag > 0) {
|
2021-11-02 17:29:15 +03:00
|
|
|
|
$class = 'label label-success';
|
|
|
|
|
$answer_flag < 1 ? $content = $answer_flag *100 . '%' : $content = 'Верен';
|
|
|
|
|
}
|
2021-11-12 14:30:01 +03:00
|
|
|
|
else if ($answer_flag === 0.0) {
|
2021-11-02 17:29:15 +03:00
|
|
|
|
$class = 'label label-danger';
|
|
|
|
|
$content = 'Не верен';
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-12 14:30:01 +03:00
|
|
|
|
return Html::tag('span', $content, ['class' => $class,]);
|
2021-11-02 17:29:15 +03:00
|
|
|
|
}
|
2021-10-29 17:06:09 +03:00
|
|
|
|
}
|