2021-10-28 10:51:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
2022-03-15 17:56:45 +03:00
|
|
|
use common\services\UserQuestionnaireService;
|
2022-10-19 15:28:09 +03:00
|
|
|
use yii\helpers\ArrayHelper;
|
2021-10-28 10:51:14 +03:00
|
|
|
use yii\web\NotFoundHttpException;
|
2022-03-15 17:56:45 +03:00
|
|
|
use yii\web\ServerErrorHttpException;
|
2021-10-28 10:51:14 +03:00
|
|
|
|
2022-03-03 17:24:45 +03:00
|
|
|
class UserQuestionnaireController extends ApiController
|
2021-10-28 10:51:14 +03:00
|
|
|
{
|
2022-10-19 15:28:09 +03:00
|
|
|
|
|
|
|
public function behaviors(): array
|
2021-10-28 10:51:14 +03:00
|
|
|
{
|
2022-10-19 15:28:09 +03:00
|
|
|
return ArrayHelper::merge(parent::behaviors(), [
|
|
|
|
|
|
|
|
'verbs' => [
|
|
|
|
'class' => \yii\filters\VerbFilter::class,
|
|
|
|
'actions' => [
|
|
|
|
'questionnaires-list' => ['get'],
|
|
|
|
'questionnaire-completed' => ['get'],
|
|
|
|
'get-points-number' => ['get'],
|
|
|
|
'get-question-number' => ['get'],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
]);
|
2021-10-28 10:51:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-10-10 15:06:01 +03:00
|
|
|
* @OA\Get(path="/user-questionnaire/questionnaires-list",
|
|
|
|
* summary="Список тестов",
|
|
|
|
* description="Получение списка тестов",
|
|
|
|
* security={
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
* },
|
|
|
|
* tags={"Tests"},
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="user_id",
|
|
|
|
* in="query",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="integer",
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
*
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Возвращает массив объектов тест",
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(ref="#/components/schemas/UserQuestionnaireArrExample"),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2021-10-28 10:51:14 +03:00
|
|
|
* @throws NotFoundHttpException
|
|
|
|
*/
|
2022-03-15 17:56:45 +03:00
|
|
|
public function actionQuestionnairesList($user_id): array
|
2021-10-28 10:51:14 +03:00
|
|
|
{
|
2022-03-15 17:56:45 +03:00
|
|
|
if (empty($user_id) or !is_numeric($user_id)) {
|
2021-10-28 10:51:14 +03:00
|
|
|
throw new NotFoundHttpException('Incorrect user ID');
|
|
|
|
}
|
2022-03-15 17:56:45 +03:00
|
|
|
$userQuestionnaireModels = UserQuestionnaireService::getQuestionnaireList($user_id);
|
2022-02-15 11:29:16 +03:00
|
|
|
if(empty($userQuestionnaireModels)) {
|
2021-10-28 10:51:14 +03:00
|
|
|
throw new NotFoundHttpException('Active questionnaire not found');
|
|
|
|
}
|
2022-03-15 17:56:45 +03:00
|
|
|
return $userQuestionnaireModels;
|
2021-10-28 10:51:14 +03:00
|
|
|
}
|
2022-03-14 17:47:01 +03:00
|
|
|
|
2022-03-15 17:56:45 +03:00
|
|
|
/**
|
2023-10-10 15:06:01 +03:00
|
|
|
* @OA\Get(path="/user-questionnaire/questionnaire-completed",
|
|
|
|
* summary="Проверка теста",
|
|
|
|
* description="Выполнения проверки теста",
|
|
|
|
* security={
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
* },
|
|
|
|
* tags={"Tests"},
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="user_questionnaire_uuid",
|
|
|
|
* in="query",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Возвращает объект Запроса",
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(ref="#/components/schemas/UserQuestionnaireExample"),
|
|
|
|
* ),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*
|
2022-03-15 17:56:45 +03:00
|
|
|
* @throws NotFoundHttpException
|
|
|
|
* @throws ServerErrorHttpException
|
|
|
|
*/
|
|
|
|
public function actionQuestionnaireCompleted($user_questionnaire_uuid)
|
2022-03-14 17:47:01 +03:00
|
|
|
{
|
2022-03-15 17:56:45 +03:00
|
|
|
$userQuestionnaireModel = UserQuestionnaireService::calculateScore($user_questionnaire_uuid);
|
|
|
|
if ($userQuestionnaireModel->errors) {
|
2022-10-19 15:28:09 +03:00
|
|
|
throw new ServerErrorHttpException($userQuestionnaireModel->errors);
|
2022-03-14 17:47:01 +03:00
|
|
|
}
|
|
|
|
return $userQuestionnaireModel;
|
|
|
|
}
|
2022-03-17 14:50:57 +03:00
|
|
|
|
|
|
|
/**
|
2023-10-10 15:06:01 +03:00
|
|
|
* @OA\Get(path="/user-questionnaire/get-points-number",
|
|
|
|
* summary="Количество балов в тесте",
|
|
|
|
* description="Возвращает максимальное количество балов за тест",
|
|
|
|
* security={
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
* },
|
|
|
|
* tags={"Tests"},
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="user_questionnaire_uuid",
|
|
|
|
* in="query",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Возвращает максимально возможное количество балов за тест",
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(
|
|
|
|
* @OA\Property(
|
|
|
|
* property="sum_point",
|
|
|
|
* type="integer",
|
|
|
|
* example="61",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* )
|
2022-03-17 14:50:57 +03:00
|
|
|
* @throws ServerErrorHttpException
|
|
|
|
*/
|
|
|
|
public function actionGetPointsNumber($user_questionnaire_uuid)
|
|
|
|
{
|
|
|
|
$questionPointsNumber = UserQuestionnaireService::getPointsNumber($user_questionnaire_uuid);
|
|
|
|
if (empty($questionPointsNumber)) {
|
2022-10-19 15:28:09 +03:00
|
|
|
throw new ServerErrorHttpException('Question points not found!');
|
2022-03-17 14:50:57 +03:00
|
|
|
}
|
|
|
|
return $questionPointsNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-10-10 15:06:01 +03:00
|
|
|
* @OA\Get(path="/user-questionnaire/get-question-number",
|
|
|
|
* summary="Число вопросов в тесте",
|
|
|
|
* description="Возвращает число вопросов в тесте",
|
|
|
|
* security={
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
* },
|
|
|
|
* tags={"Tests"},
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="user_questionnaire_uuid",
|
|
|
|
* in="query",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Возвращает число вопросов в тесте",
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(
|
|
|
|
* @OA\Property(
|
|
|
|
* property="question_number",
|
|
|
|
* type="integer",
|
|
|
|
* example="61",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
*
|
|
|
|
* ),
|
|
|
|
* )
|
2022-03-17 14:50:57 +03:00
|
|
|
* @throws ServerErrorHttpException
|
|
|
|
*/
|
|
|
|
public function actionGetQuestionNumber($user_questionnaire_uuid)
|
|
|
|
{
|
|
|
|
$questionNumber = UserQuestionnaireService::getQuestionNumber($user_questionnaire_uuid);
|
|
|
|
if (empty($questionNumber)) {
|
2022-10-19 15:28:09 +03:00
|
|
|
throw new ServerErrorHttpException('Question number not found!');
|
2022-03-17 14:50:57 +03:00
|
|
|
}
|
|
|
|
return $questionNumber;
|
|
|
|
}
|
2021-10-28 10:51:14 +03:00
|
|
|
}
|