adding forgotten files for last commit
This commit is contained in:
58
frontend/modules/api/controllers/AnswerController.php
Normal file
58
frontend/modules/api/controllers/AnswerController.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\Answer;
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
|
||||
class AnswerController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
|
||||
$behaviors['authenticator']['authMethods'] = [
|
||||
HttpBearerAuth::className(),
|
||||
];
|
||||
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
'get-answers' => ['get'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetAnswers(): array
|
||||
{
|
||||
$question_id = Yii::$app->request->get('question_id');
|
||||
|
||||
if(empty($question_id) or !is_numeric($question_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect questionnaire ID');
|
||||
}
|
||||
|
||||
$answers = Answer::getActiveAnswers($question_id);
|
||||
if(empty($answers)) {
|
||||
throw new NotFoundHttpException('Active questionnaire not found');
|
||||
}
|
||||
|
||||
array_walk( $answers, function(&$arr){
|
||||
unset(
|
||||
$arr['created_at'],
|
||||
$arr['updated_at'],
|
||||
$arr['answer_flag']
|
||||
);
|
||||
});
|
||||
|
||||
return $answers;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user