feat: list and show submitted questionnaires to the office

This commit is contained in:
fromme committed 2026-10-27 17:02:51 +01:00
1 parent 890e04f8a6
commit a35f91ac63
15 files changed
+715 -46

No files matched your search

@@ -0,0 +1,43 @@
<?php
namespace App\Controller\Administrative\Questionnaire;
use App\Config\QuestionnaireCatalog;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\QuestionnaireResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
/**
* One submitted questionnaire: what the disposition knew when it was submitted, then the answers,
* rendered with the definition version they were given under.
*/
class DetailController extends AbstractController
{
use ReturnUrlTrait;
public function __construct(
private readonly QuestionnaireCatalog $catalog,
) {
}
#[Route('/administrative/questionnaire/{uuid}', name: 'app_administrative_questionnaire_detail')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(QuestionnaireResponse $response, Request $request): Response
{
// a draft is still the teamer's
if (false === $response->isSubmitted()) {
throw new NotFoundHttpException();
}
return $this->render('administrative/questionnaire/detail.html.twig', [
'definition' => $this->catalog->get($response->getQuestionnaire(), $response->getVersion()),
'response' => $response,
'returnUrl' => $this->getReturnUrl($request, 'app_administrative_questionnaire_index'),
]);
}
}
@@ -0,0 +1,51 @@
<?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 teamer questionnaires. Only administrative users read them: they rate the house
* manager among others, so house managers are deliberately not let in.
*/
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', name: 'app_administrative_questionnaire_index')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Request $request): Response
{
$filterDto = $this->filterHandler->getFilterSettings();
$pagination = $this->paginator->paginate(
$this->responseRepository->getListQuery(QuestionnaireCatalog::TEAMER_ESCORT, $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(QuestionnaireCatalog::TEAMER_ESCORT),
'pagination' => $pagination,
'filterDto' => $filterDto,
]);
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Controller\Common;
use App\Form\QuestionnaireResponseFilterType;
use App\Htmx\HxRedirectResponse;
use App\Service\Common\QuestionnaireResponseFilterHandler;
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;
class QuestionnaireResponseFilterController extends AbstractController
{
public function __construct(private readonly QuestionnaireResponseFilterHandler $filterHandler)
{
}
#[Route('/common/questionnaire-response/filter', name: 'app_common_questionnaire_response_filter')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Request $request): Response
{
$formData = $this->filterHandler->getFilterSettings();
$form = $this->createForm(QuestionnaireResponseFilterType::class, $formData);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->filterHandler->handleRequest($form);
return new HxRedirectResponse($this->generateUrl('app_administrative_questionnaire_index'));
}
return $this->render('common/modal_questionnaire_response_filter.html.twig', [
'filterForm' => $form->createView(),
'filterDto' => $form->getData(),
]);
}
#[Route('/common/questionnaire-response/filter/reset', name: 'app_common_questionnaire_response_filter_reset')]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function reset(): Response
{
$this->filterHandler->resetFilterSettings();
return $this->redirectToRoute('app_administrative_questionnaire_index');
}
}
@@ -0,0 +1,53 @@
<?php
namespace App\Form;
use App\Entity\Teamer;
use App\Model\QuestionnaireResponseFilterDto;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class QuestionnaireResponseFilterType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('teamer', AutocompleteEntityType::class, [
'label' => 'Teamer',
'required' => false,
'class' => Teamer::class,
'label_property' => 'name',
'label_function' => fn (Teamer $teamer) => (string) $teamer,
'endpoint_route' => 'app_admin_autocomplete_teamer',
])
->add('hotel', TextType::class, [
'label' => 'Haus',
'required' => false,
])
->add('dateFrom', DatepickerType::class, [
'label' => 'Einsatzende von',
'required' => false,
])
->add('dateTo', DatepickerType::class, [
'label' => 'Einsatzende bis',
'required' => false,
])
->add('apply', SubmitType::class, [
'label' => 'filtern',
])
->add('reset', SubmitType::class, [
'label' => 'reset',
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => QuestionnaireResponseFilterDto::class,
]);
}
}
+12
View File
@@ -109,6 +109,18 @@ class AdminMenuBuilder extends AbstractMenuBuilder
],
],
]);
$menu->addChild('Fragebögen', [
'route' => 'app_administrative_questionnaire_index',
'linkAttributes' => [
'title' => 'Fragebögen der Busbegleitungen',
],
'extras' => [
'icon' => 'bus',
'routes' => [
['pattern' => '/^app_administrative_questionnaire_/'],
],
],
]);
$menu->addChild('Teamübersicht', [
'route' => 'app_administrative_teamer_index',
+12
View File
@@ -118,6 +118,18 @@ class ManagerMenuBuilder extends AbstractMenuBuilder
],
],
]);
$menu->addChild('Fragebögen', [
'route' => 'app_administrative_questionnaire_index',
'linkAttributes' => [
'title' => 'Fragebögen der Busbegleitungen',
],
'extras' => [
'icon' => 'bus',
'routes' => [
['pattern' => '/^app_administrative_questionnaire_/'],
],
],
]);
$statisticsMenu = $menu->addChild('Statistiken', [
'extras' => [
'icon' => 'chart',
@@ -0,0 +1,61 @@
<?php
namespace App\Model;
use App\Entity\Teamer;
class QuestionnaireResponseFilterDto extends AbstractFilterDto
{
protected ?Teamer $teamer = null;
protected ?string $hotel = null;
protected ?\DateTimeImmutable $dateFrom = null;
protected ?\DateTimeImmutable $dateTo = null;
public function getTeamer(): ?Teamer
{
return $this->teamer;
}
public function setTeamer(?Teamer $teamer): static
{
$this->teamer = $teamer;
return $this;
}
public function getHotel(): ?string
{
return $this->hotel;
}
public function setHotel(?string $hotel): static
{
$this->hotel = $hotel;
return $this;
}
public function getDateFrom(): ?\DateTimeImmutable
{
return $this->dateFrom;
}
public function setDateFrom(?\DateTimeImmutable $dateFrom): static
{
$this->dateFrom = $dateFrom;
return $this;
}
public function getDateTo(): ?\DateTimeImmutable
{
return $this->dateTo;
}
public function setDateTo(?\DateTimeImmutable $dateTo): static
{
$this->dateTo = $dateTo;
return $this;
}
}
@@ -4,7 +4,11 @@ namespace App\Repository;
use App\Entity\Disposition;
use App\Entity\QuestionnaireResponse;
use App\Enum\QuestionnaireResponseStatus;
use App\Model\QuestionnaireResponseFilterDto;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;
/**
@@ -22,6 +26,60 @@ class QuestionnaireResponseRepository extends ServiceEntityRepository
parent::__construct($registry, QuestionnaireResponse::class);
}
/**
* Submitted responses to one questionnaire for the office's list. Drafts stay out: until the
* teamer submits, a response is theirs. Filtered and sorted on the live disposition rather
* than the snapshot in `context`, which JSON would make neither sortable nor indexable.
*/
public function getListQuery(string $questionnaire, QuestionnaireResponseFilterDto $filterDto): Query
{
$qb = $this->createQueryBuilder('response');
$qb
->select('response', 'disposition', 'teamer', 'assignment', 'destination')
->innerJoin('response.disposition', 'disposition')
->innerJoin('disposition.teamer', 'teamer')
->innerJoin('disposition.assignment', 'assignment')
->innerJoin('assignment.destination', 'destination')
->where($qb->expr()->andX(
$qb->expr()->eq('response.questionnaire', ':questionnaire'),
$qb->expr()->eq('response.status', ':submitted')
))
->setParameter('questionnaire', $questionnaire)
->setParameter('submitted', QuestionnaireResponseStatus::SUBMITTED)
;
if (null !== $teamer = $filterDto->getTeamer()) {
$qb
->andWhere($qb->expr()->eq('disposition.teamer', ':teamer'))
->setParameter('teamer', $teamer)
;
}
if (null !== $hotel = $filterDto->getHotel()) {
$qb
->andWhere($qb->expr()->like('destination.hotel', ':hotel'))
->setParameter('hotel', '%'.addcslashes($hotel, '%_').'%')
;
}
if (null !== $dateFrom = $filterDto->getDateFrom()) {
$qb
->andWhere($qb->expr()->gte('destination.dateTo', ':dateFrom'))
->setParameter('dateFrom', $dateFrom, Types::DATE_IMMUTABLE)
;
}
if (null !== $dateTo = $filterDto->getDateTo()) {
$qb
->andWhere($qb->expr()->lte('destination.dateTo', ':dateTo'))
->setParameter('dateTo', $dateTo, Types::DATE_IMMUTABLE)
;
}
return $qb->getQuery();
}
public function findOneByDisposition(string $questionnaire, Disposition $disposition): ?QuestionnaireResponse
{
return $this->findOneBy(['questionnaire' => $questionnaire, 'disposition' => $disposition]);
@@ -0,0 +1,48 @@
<?php
namespace App\Service\Common;
use App\Entity\Teamer;
use App\Model\AbstractFilterDto;
use App\Model\QuestionnaireResponseFilterDto;
class QuestionnaireResponseFilterHandler extends AbstractFilterHandler
{
protected string $namespace = 'filter:questionnaire_response';
protected string $modelClass = QuestionnaireResponseFilterDto::class;
public function getFilterSettings(): QuestionnaireResponseFilterDto
{
$filterDto = new $this->modelClass();
if (null === $data = $this->getSession()->get($this->namespace)) {
return $filterDto;
}
if (isset($data['teamer_id'])) {
$filterDto->setTeamer($this->entityManager->getRepository(Teamer::class)->find($data['teamer_id']));
}
if (isset($data['hotel'])) {
$filterDto->setHotel($data['hotel']);
}
if (isset($data['date_from'])) {
$filterDto->setDateFrom($data['date_from']);
}
if (isset($data['date_to'])) {
$filterDto->setDateTo($data['date_to']);
}
return $filterDto;
}
protected function saveFilterSettings(AbstractFilterDto $filterDto): void
{
/* @var QuestionnaireResponseFilterDto $filterDto */
$this->getSession()->set($this->namespace, [
'teamer_id' => $filterDto->getTeamer()?->getId(),
'hotel' => $filterDto->getHotel(),
'date_from' => $filterDto->getDateFrom(),
'date_to' => $filterDto->getDateTo(),
]);
}
}
@@ -0,0 +1,45 @@
{% extends 'administrative/layout.html.twig' %}
{% block title %}{{ definition.title }}{% endblock %}
{% block content %}
{% set context = response.context %}
<h1 class="text-2xl font-bold pb-4">
{{ definition.title }}
</h1>
<p class="pb-8 text-gray-700">
{{ context.teamerName|default('-') }}, abgeschickt am {{ response.submittedAt|date('d.m.Y, H:i') }} Uhr
</p>
<div class="grid lg:grid-cols-3 gap-8 items-start">
<div class="lg:col-span-2">
{% include 'questionnaire/_answers.html.twig' %}
</div>
<div>
{# the snapshot taken on submit, so it shows the placement as the teamer answered for it #}
<h2 class="text-lg font-bold pb-4">
Einsatz
</h2>
<dl class="divide-y divide-gray-100 text-sm leading-6">
{% for label, value in {
'Teamer:in': context.teamerName|default(null),
'Jobprofil': context.jobProfileName|default(null),
'Destination': context.destinationProduct|default(null),
'Haus': context.hotel|default(null) ? context.hotel ~ ' (' ~ context.hotelCode ~ ')' : null,
'Einsatztermin': context.dateFrom|default(null) ? context.dateFrom|date('d.m.Y') ~ ' - ' ~ context.dateTo|date('d.m.Y') : null,
'Busbegleitung ab': context.escortPickup|default(null) ? context.escortPickup.city ~ ', ' ~ context.escortPickup.street ~ (context.escortPickup.time ? ', ' ~ context.escortPickup.time ~ ' Uhr' : '') : null,
'Abfahrt Hinfahrt': context.escortPickupDate|default(null) ? context.escortPickupDate|date('d.m.Y') : null,
} %}
<div class="py-3 first:pt-0 grid grid-cols-3 gap-4">
<dt class="font-bold text-gray-900">{{ label }}</dt>
<dd class="col-span-2 text-gray-700">{{ (value ?? '-') }}</dd>
</div>
{% endfor %}
</dl>
<div class="pt-8">
<a href="{{ returnUrl }}" class="underline">
zurück
</a>
</div>
</div>
</div>
{% endblock %}
@@ -0,0 +1,96 @@
{% extends 'administrative/layout.html.twig' %}
{% block title %}Fragebögen{% endblock %}
{% block content %}
<div class="flex items-start justify-between pb-4">
<h1 class="text-2xl font-bold">
Fragebögen: {{ definition.title }}
</h1>
<div class="flex flex-col items-end space-y-2 md:flex-row md:items-center md:space-x-2 md:space-y-0">
<button type="button"
class="{{ html_classes('btn btn--small', { 'btn--secondary': filterDto.active }) }}"
title="Filter"
hx-get="{{ path('app_common_questionnaire_response_filter', { 'r': return_url() }) }}"
hx-target="body"
hx-swap="beforeend">
{{ icon('filter', 'w-4 h-4 shrink-0') }}
{% if filterDto.active %}
<span class="whitespace-nowrap">{{ filterDto.activeFiltersCount }} Filter aktiv</span>
{% else %}
<span>Filter</span>
{% endif %}
</button>
{% if filterDto.active %}
<a href="{{ path('app_common_questionnaire_response_filter_reset', { 'r': return_url() }) }}" class="btn btn--small btn--secondary">
Reset
</a>
{% endif %}
</div>
</div>
<div class="data-table-wrapper">
<div class="data-table-wrapper__inner">
<table class="data-table">
<thead>
<tr>
<th>
{{ knp_pagination_sortable(pagination, 'Name', 'teamer.lastName') }}
</th>
<th>
{{ knp_pagination_sortable(pagination, 'Vorname', 'teamer.firstName') }}
</th>
<th>
{{ knp_pagination_sortable(pagination, 'Einsatzzeitraum', 'destination.dateFrom') }}
</th>
<th>
{{ knp_pagination_sortable(pagination, 'Haus', 'destination.hotel') }}
</th>
<th>
{{ knp_pagination_sortable(pagination, 'Abgeschickt', 'response.submittedAt') }}
</th>
<th></th>
</tr>
</thead>
<tbody>
{% for response in pagination %}
{% set disposition = response.disposition %}
{% set destination = disposition.assignment.destination %}
<tr>
<td>
{{ disposition.teamer.lastName }}
</td>
<td>
{{ disposition.teamer.firstName }}
{% include '_partials/_teamer_deleted_badge.html.twig' with { 'teamer': disposition.teamer } %}
</td>
<td>
{{ destination.dateFrom|date('d.m.Y') }}-
<br>
{{ destination.dateTo|date('d.m.Y') }}
</td>
<td>
{{ destination.hotel }}
</td>
<td>
{{ response.submittedAt|date('d.m.Y') }}
</td>
<td>
<a href="{{ path('app_administrative_questionnaire_detail', { 'uuid': response.uuid, 'r': return_url() }) }}" title="Fragebogen anzeigen">
{{ icon('info', 'w-4 h-4') }}
</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="6">
Keine Daten...
</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ knp_pagination_render(pagination) }}
</div>
</div>
{% endblock %}
@@ -0,0 +1,19 @@
{% extends 'htmx_modal.html.twig' %}
{% block title %}Fragebögen filtern{% endblock %}
{% block content %}
{{ form_start(filterForm, { 'attr': { 'hx-post': app.request.uri, 'hx-target': '#htmx-modal', 'hx-swap': 'outerHTML' } }) }}
<div class="flex flex-col space-y-2 pb-4">
{{ form_row(filterForm.teamer) }}
{{ form_row(filterForm.hotel) }}
{{ form_row(filterForm.dateFrom) }}
{{ form_row(filterForm.dateTo) }}
</div>
<div class="flex items-center space-x-2">
{{ form_widget(filterForm.apply, { 'attr': { 'class': 'btn' } }) }}
{{ form_widget(filterForm.reset, { 'attr': { 'class': 'btn btn--secondary' } }) }}
</div>
{{ form_rest(filterForm) }}
{{ form_end(filterForm) }}
{% endblock %}
@@ -4,14 +4,9 @@ declare(strict_types=1);
namespace App\Tests\Repository;
use App\Config\QuestionnaireCatalog;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Destination;
use App\Entity\Disposition;
use App\Entity\QuestionnaireResponse;
use App\Entity\Teamer;
use App\Model\Questionnaire\Definition;
use App\Repository\DispositionRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
@@ -27,6 +22,8 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
*/
class DispositionRepositoryQuestionnaireTest extends KernelTestCase
{
use QuestionnaireFixturesTrait;
private const string GO_LIVE = '2026-01-01';
private EntityManagerInterface $entityManager;
@@ -138,45 +135,4 @@ class DispositionRepositoryQuestionnaireTest extends KernelTestCase
return $this->repository->findPendingQuestionnaireByTeamer($this->teamer, new \DateTimeImmutable(self::GO_LIVE));
}
private function escort(string $dateTo = 'yesterday', ?Teamer $teamer = null): Disposition
{
$destination = (new Destination())
->setProduct('Davos Klosters - Schwendi')
->setHotel('Schwendi')
->setHotelCode('DKI')
->setHotelBusProId(1)
->setDateFrom(new \DateTimeImmutable($dateTo.' -7 days'))
->setDateTo(new \DateTimeImmutable($dateTo))
->setPickups([['busProId' => 4711, 'city' => 'Stuttgart', 'street' => 'Busbahnhof', 'time' => '21:30']])
;
$assignment = (new Assignment())
->setDestination($destination)
->setPickup(4711)
->setStatus(Assignment::STATUS_STAFFED)
;
$disposition = (new Disposition(new Application($assignment, $teamer ?? $this->teamer)))
->setStatus(Disposition::STATUS_ENDED)
;
$this->entityManager->persist($destination);
$this->entityManager->persist($assignment);
$this->entityManager->persist($disposition);
return $disposition;
}
private function respond(Disposition $disposition, bool $submit, string $questionnaire = QuestionnaireCatalog::TEAMER_ESCORT): void
{
$definition = new Definition($questionnaire, 1, 'Beispiel', null, []);
$response = QuestionnaireResponse::forDisposition($definition, $disposition);
if ($submit) {
$response->submit($definition, [], [], new \DateTimeImmutable());
} else {
$response->saveDraft([], []);
}
$this->entityManager->persist($response);
}
}
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace App\Tests\Repository;
use App\Config\QuestionnaireCatalog;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Destination;
use App\Entity\Disposition;
use App\Entity\QuestionnaireResponse;
use App\Entity\Teamer;
use App\Model\Questionnaire\Definition;
use Doctrine\ORM\EntityManagerInterface;
/**
* Escort placements and questionnaire responses for running the questionnaire queries against
* db_test. The using test owns $entityManager and $teamer, and rolls its transaction back.
*
* @property EntityManagerInterface $entityManager
* @property Teamer $teamer
*/
trait QuestionnaireFixturesTrait
{
private function escort(string $dateTo = 'yesterday', ?Teamer $teamer = null, string $hotel = 'Schwendi'): Disposition
{
$destination = (new Destination())
->setProduct('Davos Klosters - Schwendi')
->setHotel($hotel)
->setHotelCode('DKI')
->setHotelBusProId(1)
->setDateFrom(new \DateTimeImmutable($dateTo.' -7 days'))
->setDateTo(new \DateTimeImmutable($dateTo))
->setPickups([['busProId' => 4711, 'city' => 'Stuttgart', 'street' => 'Busbahnhof', 'time' => '21:30']])
;
$assignment = (new Assignment())
->setDestination($destination)
->setPickup(4711)
->setStatus(Assignment::STATUS_STAFFED)
;
$disposition = (new Disposition(new Application($assignment, $teamer ?? $this->teamer)))
->setStatus(Disposition::STATUS_ENDED)
;
$this->entityManager->persist($destination);
$this->entityManager->persist($assignment);
$this->entityManager->persist($disposition);
return $disposition;
}
private function respond(Disposition $disposition, bool $submit, string $questionnaire = QuestionnaireCatalog::TEAMER_ESCORT): QuestionnaireResponse
{
$definition = new Definition($questionnaire, 1, 'Beispiel', null, []);
$response = QuestionnaireResponse::forDisposition($definition, $disposition);
if ($submit) {
$response->submit($definition, [], [], new \DateTimeImmutable());
} else {
$response->saveDraft([], []);
}
$this->entityManager->persist($response);
return $response;
}
}
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace App\Tests\Repository;
use App\Config\QuestionnaireCatalog;
use App\Entity\QuestionnaireResponse;
use App\Entity\Teamer;
use App\Model\QuestionnaireResponseFilterDto;
use App\Repository\QuestionnaireResponseRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* The office's list of submitted questionnaires, run against db_test inside a rolled-back
* transaction. A draft is still the teamer's and must never show up there.
*/
class QuestionnaireResponseRepositoryTest extends KernelTestCase
{
use QuestionnaireFixturesTrait;
private EntityManagerInterface $entityManager;
private QuestionnaireResponseRepository $repository;
private Teamer $teamer;
protected function setUp(): void
{
self::bootKernel();
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
$this->repository = $this->entityManager->getRepository(QuestionnaireResponse::class);
$this->entityManager->getConnection()->beginTransaction();
$this->teamer = (new Teamer())->setFirstName('Kim')->setLastName('Muster')->setGender('d');
$this->entityManager->persist($this->teamer);
}
protected function tearDown(): void
{
$this->entityManager->getConnection()->rollBack();
parent::tearDown();
}
public function testOnlySubmittedResponsesToThisQuestionnaireAreListed(): void
{
$submitted = $this->respond($this->escort(), submit: true);
$this->respond($this->escort(), submit: false);
$this->respond($this->escort(), submit: true, questionnaire: 'other');
$this->assertSame([$submitted], $this->list(new QuestionnaireResponseFilterDto()));
}
public function testFilterByTeamer(): void
{
$other = (new Teamer())->setFirstName('Alex')->setLastName('Beispiel')->setGender('d');
$this->entityManager->persist($other);
$this->respond($this->escort(teamer: $other), submit: true);
$mine = $this->respond($this->escort(), submit: true);
$this->assertSame([$mine], $this->list((new QuestionnaireResponseFilterDto())->setTeamer($this->teamer)));
}
/**
* Matched as a substring, and a % typed into the filter is a literal, not a wildcard.
*/
public function testFilterByHotel(): void
{
$ranalt = $this->respond($this->escort(hotel: 'Gasthof Ranalt'), submit: true);
$this->respond($this->escort(hotel: 'Schwendi'), submit: true);
$this->assertSame([$ranalt], $this->list((new QuestionnaireResponseFilterDto())->setHotel('ranalt')));
$this->assertSame([], $this->list((new QuestionnaireResponseFilterDto())->setHotel('%')));
}
public function testFilterByEndOfAssignment(): void
{
$recent = $this->respond($this->escort(dateTo: '2026-03-14'), submit: true);
$this->respond($this->escort(dateTo: '2026-01-10'), submit: true);
$filter = (new QuestionnaireResponseFilterDto())
->setDateFrom(new \DateTimeImmutable('2026-03-01'))
->setDateTo(new \DateTimeImmutable('2026-03-14'))
;
$this->assertSame([$recent], $this->list($filter));
}
/**
* @return list<QuestionnaireResponse>
*/
private function list(QuestionnaireResponseFilterDto $filter): array
{
$this->entityManager->flush();
return $this->repository->getListQuery(QuestionnaireCatalog::TEAMER_ESCORT, $filter)->getResult();
}
}