mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-22 14:04:01 +00:00
71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Questionnaires\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Questionnaires\Services\ListsQuestions;
|
|
use App\Classes\Modules\Questionnaires\Standards\Rules\CanListQuestions;
|
|
use App\Http\Resources\QuestionResource;
|
|
use App\Models\QAQuestionnaireSet;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ListQuestionsLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Retrieved Questions',
|
|
'message' => 'You have successfully retrieved a list of questions'
|
|
];
|
|
}
|
|
|
|
/** @var CanListQuestions */
|
|
private $canListQuestions;
|
|
|
|
/** @var ListsQuestions */
|
|
private $listsQuestions;
|
|
|
|
/**
|
|
* ListQuestionsLogic constructor.
|
|
* @param CanListQuestions $canListQuestions
|
|
* @param ListsQuestions $listsQuestions
|
|
*/
|
|
public function __construct(CanListQuestions $canListQuestions, ListsQuestions $listsQuestions)
|
|
{
|
|
$this->canListQuestions = $canListQuestions;
|
|
$this->listsQuestions = $listsQuestions;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
* @throws \App\Classes\Exceptions\RequestValidationException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
$this->canListQuestions->passes();
|
|
$setId = 0;
|
|
if ($request->route('set_id')) {
|
|
$setId = $request->route('set_id');
|
|
}
|
|
|
|
if($setId === 0){
|
|
$set = QAQuestionnaireSet::where('group', '1688,approve_po,fill_po')->latest('id')->first();
|
|
$setId = $set->id;
|
|
}
|
|
|
|
$query = $this->listsQuestions->execute(array_merge($this->listsQuestions->deserializeFilters($request->input('filters')), ['questionnaire_set_id' => $setId]));
|
|
|
|
return $this->collectionResponse(QuestionResource::collection($query));
|
|
}
|
|
|
|
}
|