guild/common/services/UserQuestionnaireService.php

37 lines
1.1 KiB
PHP
Raw Normal View History

2022-03-15 16:54:34 +03:00
<?php
namespace common\services;
2022-03-15 17:56:45 +03:00
use common\models\UserQuestionnaire;
use yii\web\NotFoundHttpException;
2022-03-15 16:54:34 +03:00
class UserQuestionnaireService
{
2022-03-15 17:56:45 +03:00
public static function getQuestionnaireList($user_id): array
{
$userQuestionnaireModels = UserQuestionnaire::findActiveUserQuestionnaires($user_id);
array_walk($userQuestionnaireModels, function (&$arr) {
unset(
$arr['questionnaire_id'],
$arr['created_at'],
$arr['updated_at'],
$arr['id'],
);
});
return $userQuestionnaireModels;
}
2022-03-15 16:54:34 +03:00
2022-03-15 17:56:45 +03:00
/**
* @throws NotFoundHttpException
*/
public static function calculateScore($user_questionnaire_uuid)
{
$userQuestionnaireModel = UserQuestionnaire::findOne(['uuid' => $user_questionnaire_uuid]);
if(empty($userQuestionnaireModel)) {
throw new NotFoundHttpException('The questionnaire with this uuid does not exist');
}
ScoreCalculatorService::rateResponses($userQuestionnaireModel);
ScoreCalculatorService::calculateScore($userQuestionnaireModel);
return $userQuestionnaireModel;
}
2022-03-15 16:54:34 +03:00
}