fix answerFlagLabel method in AnswerHelper

This commit is contained in:
iironside 2022-03-15 19:30:53 +03:00
parent 18d2b4327d
commit 97e79f6c94
3 changed files with 13 additions and 13 deletions

View File

@ -20,13 +20,6 @@ $this->params['breadcrumbs'][] = $this->title;
<?= Html::a('Новый ответ пользователя', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php
//echo $this->render('_search_by_questionnaire', [
// 'model' => $searchModel,
// ])
?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,

View File

@ -10,12 +10,14 @@ 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 => 'Не проверен',
];
}
@ -24,15 +26,15 @@ class AnswerHelper
*/
public static function answerFlagLabel($status): string
{
switch ($status) {
case self::FLAG_FALSE:
switch (true) {
case ($status === self::FLAG_FALSE):
$class = 'label label-danger';
break;
case self::FLAG_TRUE:
case ($status === self::FLAG_TRUE):
$class = 'label label-success';
break;
default:
$class = 'label label-default';
$class = 'label label-warning';
}
return Html::tag('span', ArrayHelper::getValue(self::answerFlagsList(), $status), [

View File

@ -5,6 +5,7 @@ namespace common\services;
use backend\modules\questionnaire\models\Answer;
use common\models\UserQuestionnaire;
use common\models\UserResponse;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
class ScoreCalculatorService
@ -44,6 +45,9 @@ class ScoreCalculatorService
return true;
}
/**
* @throws InvalidConfigException
*/
public static function calculateScore(UserQuestionnaire $userQuestionnaire)
{
$responses_questions = $userQuestionnaire->hasMany(UserResponse::className(), ['user_questionnaire_uuid' => 'uuid'])
@ -71,11 +75,9 @@ class ScoreCalculatorService
}
}
// if($score !== null) {
self::setPercentCorrectAnswers($user_correct_answers_num, $userQuestionnaire);
$userQuestionnaire->score = round($score);
$userQuestionnaire->save();
// }
}
protected static function isCorrect($answer_flag): bool
@ -91,6 +93,9 @@ class ScoreCalculatorService
return Answer::numCorrectAnswers($question_id);
}
/**
* @throws InvalidConfigException
*/
protected static function setPercentCorrectAnswers($user_correct_answers_num, UserQuestionnaire $userQuestionnaire)
{
if($user_correct_answers_num !== null) {