2021-10-28 10:51:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
|
|
|
use common\models\UserQuestionnaire;
|
|
|
|
use Yii;
|
|
|
|
use yii\filters\auth\HttpBearerAuth;
|
|
|
|
use yii\rest\Controller;
|
|
|
|
use yii\web\NotFoundHttpException;
|
|
|
|
|
2022-03-03 17:24:45 +03:00
|
|
|
class UserQuestionnaireController extends ApiController
|
2021-10-28 10:51:14 +03:00
|
|
|
{
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
$behaviors = parent::behaviors();
|
|
|
|
|
|
|
|
$behaviors['authenticator']['authMethods'] = [
|
|
|
|
HttpBearerAuth::className(),
|
|
|
|
];
|
|
|
|
|
|
|
|
return $behaviors;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function verbs()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'questionnaires-list' => ['get'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws NotFoundHttpException
|
|
|
|
*/
|
|
|
|
public function actionQuestionnairesList(): array
|
|
|
|
{
|
|
|
|
$user_id = Yii::$app->request->get('user_id');
|
|
|
|
|
|
|
|
if(empty($user_id) or !is_numeric($user_id))
|
|
|
|
{
|
|
|
|
throw new NotFoundHttpException('Incorrect user ID');
|
|
|
|
}
|
|
|
|
|
|
|
|
$userQuestionnaireModel = UserQuestionnaire::findActiveUserQuestionnaires($user_id);
|
|
|
|
if(empty($userQuestionnaireModel)) {
|
|
|
|
throw new NotFoundHttpException('Active questionnaire not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
array_walk( $userQuestionnaireModel, function(&$arr){
|
|
|
|
unset(
|
2021-11-12 14:30:01 +03:00
|
|
|
$arr['questionnaire_id'],
|
2021-10-28 10:51:14 +03:00
|
|
|
$arr['created_at'],
|
|
|
|
$arr['updated_at'],
|
2021-11-12 14:30:01 +03:00
|
|
|
$arr['id'],
|
2021-10-28 10:51:14 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return $userQuestionnaireModel;
|
|
|
|
}
|
|
|
|
}
|