guild/common/helpers/AnswerHelper.php
2022-03-15 19:30:53 +03:00

61 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace common\helpers;
use yii\helpers\ArrayHelper;
use Exception;
use yii\helpers\Html;
class AnswerHelper
{
const FLAG_TRUE = 1;
const FLAG_FALSE = 0;
const FLAG_NOT_VERIFIED = null;
public static function answerFlagsList(): array
{
return [
self::FLAG_TRUE => 'Верен',
self::FLAG_FALSE => 'Ошибочный',
self::FLAG_NOT_VERIFIED => 'Не проверен',
];
}
/**
* @throws Exception
*/
public static function answerFlagLabel($status): string
{
switch (true) {
case ($status === self::FLAG_FALSE):
$class = 'label label-danger';
break;
case ($status === self::FLAG_TRUE):
$class = 'label label-success';
break;
default:
$class = 'label label-warning';
}
return Html::tag('span', ArrayHelper::getValue(self::answerFlagsList(), $status), [
'class' => $class,
]);
}
public static function answerStatusLabel($answer_flag): string
{
$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,]);
}
}