67 lines
2.6 KiB
PHP
67 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Administrative\Questionnaire;
|
|
|
|
use App\Config\QuestionnaireCatalog;
|
|
use App\Repository\QuestionnaireResponseRepository;
|
|
use App\Service\Common\QuestionnaireResponseFilterHandler;
|
|
use Knp\Component\Pager\PaginatorInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
/**
|
|
* The submitted responses to one questionnaire: teamer, bus or house manager feedback. Only
|
|
* administrative users read them here: the teamer ones rate the house manager among others, so
|
|
* house managers are deliberately not let in. A house manager reads their own travel's
|
|
* questionnaire in the HouseManager area.
|
|
*/
|
|
class IndexController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly QuestionnaireResponseFilterHandler $filterHandler,
|
|
private readonly QuestionnaireResponseRepository $responseRepository,
|
|
private readonly QuestionnaireCatalog $catalog,
|
|
private readonly PaginatorInterface $paginator,
|
|
) {
|
|
}
|
|
|
|
#[Route(
|
|
'/administrative/questionnaire/list/{questionnaire}',
|
|
name: 'app_administrative_questionnaire_index',
|
|
requirements: ['questionnaire' => '[a-z0-9_]+'],
|
|
defaults: ['questionnaire' => QuestionnaireCatalog::TEAMER_FEEDBACK],
|
|
)]
|
|
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
|
public function index(string $questionnaire, Request $request): Response
|
|
{
|
|
$keys = $this->catalog->keys();
|
|
|
|
if (!in_array($questionnaire, $keys, true)) {
|
|
throw $this->createNotFoundException(sprintf('No questionnaire "%s"', $questionnaire));
|
|
}
|
|
|
|
$filterDto = $this->filterHandler->getFilterSettings();
|
|
|
|
$pagination = $this->paginator->paginate(
|
|
$this->responseRepository->getListQuery($questionnaire, $filterDto),
|
|
$request->query->getInt('page', 1),
|
|
$request->query->getInt('limit', 50),
|
|
[
|
|
'defaultSortFieldName' => 'response.submittedAt',
|
|
'defaultSortDirection' => 'desc',
|
|
]
|
|
);
|
|
|
|
return $this->render('administrative/questionnaire/index.html.twig', [
|
|
'definition' => $this->catalog->get($questionnaire),
|
|
// for switching between the questionnaires
|
|
'definitions' => array_map($this->catalog->get(...), $keys),
|
|
'pagination' => $pagination,
|
|
'filterDto' => $filterDto,
|
|
]);
|
|
}
|
|
}
|