feat: add the house manager questionnaire per travel and compact the questionnaire layout
This commit is contained in:
1 parent
d760ed3cdf
commit
bfef08b519
50 files changed
+2763
-180
No files matched your search
@@ -35,6 +35,12 @@ class QuestionnaireCatalog
|
||||
*/
|
||||
public const string BUS_FEEDBACK = 'bus_feedback';
|
||||
|
||||
/**
|
||||
* The one a house manager fills in about a travel; see DestinationVoter::QUESTIONNAIRE. Its
|
||||
* subject is a Destination rather than a Disposition.
|
||||
*/
|
||||
public const string HOUSE_MANAGER_FEEDBACK = 'house_manager_feedback';
|
||||
|
||||
private const array ROOT_FIELDS = ['key', 'version', 'title', 'description', 'per_bus_leg', 'sections'];
|
||||
private const array SECTION_FIELDS = ['key', 'title', 'questions'];
|
||||
private const array QUESTION_FIELDS = ['key', 'label', 'type', 'required', 'help', 'widget', 'options', 'show_if'];
|
||||
@@ -57,14 +63,15 @@ class QuestionnaireCatalog
|
||||
}
|
||||
|
||||
/**
|
||||
* The services.yaml parameter questionnaire_go_live as a date: the teamer questionnaire is
|
||||
* offered for placements ending on or after it, and stays pending until submitted. Without
|
||||
* it, every past placement would be pending and reminded of at once.
|
||||
* A services.yaml go-live parameter as a date: questionnaire_go_live for the teamer
|
||||
* questionnaire (placements ending on or after it), house_manager_questionnaire_go_live for the
|
||||
* house manager's (travels ending on or after it). Either stays pending until submitted.
|
||||
* Without it, every past placement or travel would be pending and reminded of at once.
|
||||
*/
|
||||
public static function parseGoLive(string $goLive): \DateTimeImmutable
|
||||
{
|
||||
return \DateTimeImmutable::createFromFormat('!Y-m-d', $goLive)
|
||||
?: throw new \InvalidArgumentException(sprintf('questionnaire_go_live "%s" is not a Y-m-d date', $goLive));
|
||||
?: throw new \InvalidArgumentException(sprintf('Questionnaire go-live "%s" is not a Y-m-d date', $goLive));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,8 +16,8 @@ use Symfony\Component\Routing\Requirement\Requirement;
|
||||
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.
|
||||
* One submitted questionnaire: what the disposition or travel knew when it was submitted, then the
|
||||
* answers, rendered with the definition version they were given under.
|
||||
*/
|
||||
class DetailController extends AbstractController
|
||||
{
|
||||
@@ -43,8 +43,8 @@ class DetailController extends AbstractController
|
||||
}
|
||||
|
||||
// the other responses of the same placement, e.g. the bus feedback beside the teamer feedback,
|
||||
// or the other leg's
|
||||
$siblings = array_filter(
|
||||
// or the other leg's; a travel's questionnaire has none
|
||||
$siblings = null === $response->getDisposition() ? [] : array_filter(
|
||||
array_merge(...array_values($this->responseRepository->findByDisposition($response->getDisposition()))),
|
||||
static fn (QuestionnaireResponse $sibling): bool => $sibling !== $response && $sibling->isSubmitted(),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\Questionnaire;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Entity\Assignment;
|
||||
use App\Form\QuestionnaireType;
|
||||
use App\Repository\DispositionRepository;
|
||||
use App\Service\Questionnaire\DestinationContext;
|
||||
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
||||
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 house manager's questionnaire as a house manager gets it for the travel of this assignment,
|
||||
* with the travel's teamers - before or after the trip. Opened from an assignment, since that is
|
||||
* where the office tries out the teamer questionnaires too. Nothing is saved: "Absenden" shows
|
||||
* the answers as they would be stored, "Entwurf speichern" just keeps them in the form.
|
||||
*/
|
||||
class HouseManagerTestController extends AbstractController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly QuestionnaireCatalog $catalog,
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/questionnaire/test-house-manager/{uuid}', name: 'app_administrative_questionnaire_test_house_manager')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(
|
||||
#[MapEntity(mapping: ['uuid' => 'uuid'])]
|
||||
Assignment $assignment,
|
||||
Request $request,
|
||||
): Response {
|
||||
$destination = $assignment->getDestination();
|
||||
$definition = $this->catalog->get(QuestionnaireCatalog::HOUSE_MANAGER_FEEDBACK);
|
||||
$dispositions = $this->dispositionRepository->findForHouseManagerQuestionnaire($destination);
|
||||
|
||||
$form = $this->createForm(QuestionnaireType::class, [
|
||||
$definition->key => DestinationContext::initialAnswers($destination),
|
||||
], [
|
||||
'definitions' => [$definition],
|
||||
'travel' => DestinationContext::travel($destination, $dispositions),
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$submitted = null;
|
||||
$draft = false;
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (QuestionnaireType::isFinal($form)) {
|
||||
$submitted = $definition->withoutHiddenAnswers($form->getData()[$definition->key]);
|
||||
} else {
|
||||
$draft = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('administrative/questionnaire/test_house_manager.html.twig', [
|
||||
'assignment' => $assignment,
|
||||
'destination' => $destination,
|
||||
'dispositions' => $dispositions,
|
||||
'definition' => $definition,
|
||||
'context' => DestinationContext::build($destination, $dispositions),
|
||||
'form' => $form,
|
||||
'submitted' => $submitted,
|
||||
'draft' => $draft,
|
||||
'returnUrl' => $this->getReturnUrl($request, 'app_administrative_assignment_index'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,10 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* The submitted responses to one questionnaire, teamer or bus feedback. Only administrative users
|
||||
* read them: they rate the house manager among others, so house managers are deliberately not
|
||||
* let in.
|
||||
* 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
|
||||
{
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Controller\HouseManager\Feedback;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\User;
|
||||
use App\Repository\DestinationRepository;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -11,12 +14,21 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* The house manager's ended travels with something still to do, one row per travel: the
|
||||
* questionnaire about it (from the go-live on), and the ratings of its teamers, each linked.
|
||||
*/
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
private readonly \DateTimeImmutable $goLive;
|
||||
|
||||
public function __construct(
|
||||
private readonly DestinationRepository $destinationRepository,
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
private readonly PaginatorInterface $paginator,
|
||||
string $houseManagerQuestionnaireGoLive,
|
||||
) {
|
||||
$this->goLive = QuestionnaireCatalog::parseGoLive($houseManagerQuestionnaireGoLive);
|
||||
}
|
||||
|
||||
#[Route('/house-manager/pending-feedback', name: 'app_house_manager_feedback_index')]
|
||||
@@ -26,23 +38,22 @@ class IndexController extends AbstractController
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
$query = $this
|
||||
->dispositionRepository
|
||||
->getDispositionsWithPendingFeedbackQuery($user->getHotelCodes())
|
||||
;
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$query,
|
||||
$this->destinationRepository->getPendingForHouseManagerQuery($user->getHotelCodes(), $this->goLive, new \DateTimeImmutable('today'), $user->getTeamer()),
|
||||
$request->query->getInt('page', 1),
|
||||
$request->query->getInt('limit', 50),
|
||||
[
|
||||
'defaultSortFieldName' => 'destination.dateFrom',
|
||||
'defaultSortFieldName' => 'destination.dateTo',
|
||||
'defaultSortDirection' => 'asc',
|
||||
]
|
||||
);
|
||||
|
||||
$destinations = array_map(static fn (array $row): Destination => $row[0], iterator_to_array($pagination));
|
||||
|
||||
return $this->render('house_manager/feedback/index.html.twig', [
|
||||
'pagination' => $pagination,
|
||||
'placements' => $this->dispositionRepository->findForHouseManagerByDestinations($destinations),
|
||||
'goLive' => $this->goLive,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Controller\HouseManager;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\User;
|
||||
use App\Repository\DestinationRepository;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -11,8 +13,14 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly DispositionRepository $dispositionRepository)
|
||||
{
|
||||
private readonly \DateTimeImmutable $goLive;
|
||||
|
||||
public function __construct(
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
private readonly DestinationRepository $destinationRepository,
|
||||
string $houseManagerQuestionnaireGoLive,
|
||||
) {
|
||||
$this->goLive = QuestionnaireCatalog::parseGoLive($houseManagerQuestionnaireGoLive);
|
||||
}
|
||||
|
||||
#[Route('/house-manager', name: 'app_house_manager_index')]
|
||||
@@ -27,14 +35,16 @@ class IndexController extends AbstractController
|
||||
->findNewDispositionsByHotelCodes($user->getHotelCodes())
|
||||
;
|
||||
|
||||
$pendingFeedbacks = $this
|
||||
->dispositionRepository
|
||||
->findDispositionsWithPendingFeedbackByHotelCodes($user->getHotelCodes())
|
||||
$pendingTravels = $this
|
||||
->destinationRepository
|
||||
->getPendingForHouseManagerQuery($user->getHotelCodes(), $this->goLive, new \DateTimeImmutable('today'), $user->getTeamer())
|
||||
->getResult()
|
||||
;
|
||||
|
||||
return $this->render('house_manager/index.html.twig', [
|
||||
'newDispositions' => $newDispositions,
|
||||
'pendingFeedbacks' => $pendingFeedbacks,
|
||||
'pendingTravels' => $pendingTravels,
|
||||
'goLive' => $this->goLive,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\HouseManager\Questionnaire;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\User;
|
||||
use App\Repository\DispositionRepository;
|
||||
use App\Repository\QuestionnaireResponseRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Routing\Requirement\Requirement;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* The submitted questionnaire about a travel, read-only, for the house's managers; below it the
|
||||
* travel's teamers and their ratings, as on the form. Until it is submitted, the form is shown.
|
||||
*/
|
||||
class DetailController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly QuestionnaireCatalog $catalog,
|
||||
private readonly QuestionnaireResponseRepository $responseRepository,
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/house-manager/questionnaire/{id}/answers', name: 'app_house_manager_questionnaire_detail', requirements: ['id' => Requirement::DIGITS])]
|
||||
#[IsGranted('QUESTIONNAIRE', subject: 'destination')]
|
||||
public function index(Destination $destination): Response
|
||||
{
|
||||
$response = $this->responseRepository->findForDestination($destination);
|
||||
|
||||
if (true !== $response?->isSubmitted()) {
|
||||
return $this->redirectToRoute('app_house_manager_questionnaire_edit', ['id' => $destination->getId()]);
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
return $this->render('house_manager/questionnaire/detail.html.twig', [
|
||||
'destination' => $destination,
|
||||
'dispositions' => $this->dispositionRepository->findForHouseManagerQuestionnaire($destination, $user->getTeamer()),
|
||||
'definition' => $this->catalog->get($response->getQuestionnaire(), $response->getVersion()),
|
||||
'response' => $response,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\HouseManager\Questionnaire;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\User;
|
||||
use App\Form\QuestionnaireType;
|
||||
use App\Repository\DispositionRepository;
|
||||
use App\Repository\QuestionnaireResponseRepository;
|
||||
use App\Service\Questionnaire\DestinationContext;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
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\Routing\Requirement\Requirement;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* The house manager's questionnaire about a travel, one per travel whoever of the house's managers
|
||||
* fills it in. Saved as a draft until submitted; submitted answers are final and only shown
|
||||
* read-only (DetailController). Below the form, the travel's teamers link to the existing rating
|
||||
* form ("Bewerte dein Wochenteam"), independent of the questionnaire.
|
||||
*/
|
||||
class EditController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly QuestionnaireCatalog $catalog,
|
||||
private readonly QuestionnaireResponseRepository $responseRepository,
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/house-manager/questionnaire/{id}', name: 'app_house_manager_questionnaire_edit', requirements: ['id' => Requirement::DIGITS])]
|
||||
#[IsGranted('QUESTIONNAIRE', subject: 'destination')]
|
||||
public function index(Destination $destination, Request $request): Response
|
||||
{
|
||||
$response = $this->responseRepository->findForDestination($destination);
|
||||
|
||||
if (true === $response?->isSubmitted()) {
|
||||
return $this->redirectToRoute('app_house_manager_questionnaire_detail', ['id' => $destination->getId()]);
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$definition = $this->catalog->get(QuestionnaireCatalog::HOUSE_MANAGER_FEEDBACK);
|
||||
$dispositions = $this->dispositionRepository->findForHouseManagerQuestionnaire($destination, $user->getTeamer());
|
||||
|
||||
$form = $this->createForm(QuestionnaireType::class, [
|
||||
$definition->key => $response?->getAnswers() ?? DestinationContext::initialAnswers($destination),
|
||||
], [
|
||||
'definitions' => [$definition],
|
||||
'travel' => DestinationContext::travel($destination, $dispositions),
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$answers = $form->getData()[$definition->key];
|
||||
$context = DestinationContext::build($destination, $dispositions);
|
||||
$final = QuestionnaireType::isFinal($form);
|
||||
|
||||
if (null === $response) {
|
||||
$response = QuestionnaireResponse::forDestination($definition, $destination);
|
||||
$this->entityManager->persist($response);
|
||||
}
|
||||
|
||||
if (true === $final) {
|
||||
$response->submit($definition, $answers, $context, new \DateTimeImmutable());
|
||||
} else {
|
||||
$response->saveDraft($answers, $context);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->logger->info($final ? 'Submit house manager questionnaire' : 'Save house manager questionnaire draft', [
|
||||
'questionnaire' => $response->getQuestionnaire(),
|
||||
'questionnaire_response_id' => $response->getId(),
|
||||
'destination_id' => $destination->getId(),
|
||||
]);
|
||||
|
||||
if (true === $final) {
|
||||
$this->addFlash('success', 'Danke! Dein Fragebogen wurde abgeschickt.');
|
||||
|
||||
return $this->redirectToRoute('app_house_manager_questionnaire_detail', ['id' => $destination->getId()]);
|
||||
}
|
||||
|
||||
$this->addFlash('success', 'Dein Entwurf wurde gespeichert.');
|
||||
|
||||
return $this->redirectToRoute('app_house_manager_questionnaire_edit', ['id' => $destination->getId()]);
|
||||
}
|
||||
|
||||
return $this->render('house_manager/questionnaire/edit.html.twig', [
|
||||
'destination' => $destination,
|
||||
'dispositions' => $dispositions,
|
||||
'form' => $form,
|
||||
'lastSaved' => null === $response ? null : $response->getUpdatedAt() ?? $response->getCreatedAt(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -23,14 +23,17 @@ use Symfony\Component\Uid\Uuid;
|
||||
* A per-bus-leg questionnaire (Definition::$perBusLeg) has one response per escorted leg, the
|
||||
* others one per disposition.
|
||||
*
|
||||
* Its subject is a Disposition today. A questionnaire about something else gets a nullable foreign
|
||||
* key of its own beside $disposition, not a generic subject column.
|
||||
* Its subject is a Disposition (the teamer's questionnaires) or a Destination (the house manager's,
|
||||
* one per travel), each a nullable foreign key of its own rather than a generic subject column.
|
||||
* Exactly one is set. Each unique key leaves out the rows of the other subject: MariaDB lets the
|
||||
* NULLs repeat.
|
||||
*
|
||||
* Not soft-deletable: nothing in the UI deletes a response, and it goes with its disposition.
|
||||
* Not soft-deletable: nothing in the UI deletes a response, and it goes with its subject.
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: QuestionnaireResponseRepository::class)]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
#[ORM\UniqueConstraint(name: 'questionnaire_disposition_leg', columns: ['questionnaire', 'disposition_id', 'leg'])]
|
||||
#[ORM\UniqueConstraint(name: 'questionnaire_destination', columns: ['questionnaire', 'destination_id'])]
|
||||
class QuestionnaireResponse implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
{
|
||||
use BlameableEntity;
|
||||
@@ -72,6 +75,10 @@ class QuestionnaireResponse implements BlameableEntityInterface, TimestampableEn
|
||||
#[ORM\JoinColumn(onDelete: 'CASCADE')]
|
||||
private ?Disposition $disposition = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(onDelete: 'CASCADE')]
|
||||
private ?Destination $destination = null;
|
||||
|
||||
/**
|
||||
* A BusLeg value, or '' for a questionnaire without legs rather than null: part of the unique
|
||||
* key, and MariaDB lets NULLs repeat in one.
|
||||
@@ -102,6 +109,18 @@ class QuestionnaireResponse implements BlameableEntityInterface, TimestampableEn
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public static function forDestination(Definition $definition, Destination $destination): static
|
||||
{
|
||||
if ($definition->perBusLeg) {
|
||||
throw new \LogicException(sprintf('Questionnaire "%s" needs a bus leg, a travel has none', $definition->key));
|
||||
}
|
||||
|
||||
$instance = new static($definition);
|
||||
$instance->destination = $destination;
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps every answer, including those to questions that are hidden right now: switching an
|
||||
* answer back restores the follow-up already written.
|
||||
@@ -199,6 +218,11 @@ class QuestionnaireResponse implements BlameableEntityInterface, TimestampableEn
|
||||
return $this->disposition;
|
||||
}
|
||||
|
||||
public function getDestination(): ?Destination
|
||||
{
|
||||
return $this->destination;
|
||||
}
|
||||
|
||||
public function getLeg(): ?BusLeg
|
||||
{
|
||||
return BusLeg::tryFrom($this->leg);
|
||||
|
||||
@@ -5,6 +5,11 @@ namespace App\Enum;
|
||||
/**
|
||||
* The kinds of question a questionnaire definition may use. Each maps to exactly one form field
|
||||
* in QuestionnaireType; adding one means a case here and a line there, nothing more.
|
||||
*
|
||||
* TEAMER_GUIDINGS, TEAMER_COURSES and PROGRAMME are the house manager's bespoke widgets: their
|
||||
* options are the guiding types, course types and programme items, and each picked option carries
|
||||
* numbers of its own. The two teamer types offer the travel's placements, so they need the form's
|
||||
* `travel` option.
|
||||
*/
|
||||
enum QuestionType: string
|
||||
{
|
||||
@@ -14,9 +19,17 @@ enum QuestionType: string
|
||||
case MULTI = 'multi';
|
||||
case DATE = 'date';
|
||||
case RATING = 'rating';
|
||||
case TEAMER_GUIDINGS = 'teamer_guidings';
|
||||
case TEAMER_COURSES = 'teamer_courses';
|
||||
case PROGRAMME = 'programme';
|
||||
|
||||
public function hasOptions(): bool
|
||||
{
|
||||
return self::CHOICE === $this || self::MULTI === $this;
|
||||
return self::TEXT !== $this && self::TEXTAREA !== $this && self::DATE !== $this && self::RATING !== $this;
|
||||
}
|
||||
|
||||
public function needsTravel(): bool
|
||||
{
|
||||
return self::TEAMER_GUIDINGS === $this || self::TEAMER_COURSES === $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Questionnaire;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* The house manager's bespoke questionnaire widgets (TeamerGuidingsType, TeamerCoursesType,
|
||||
* ProgrammeType) are built from "picks": a checkbox, and below it the fields that only matter once
|
||||
* it is ticked. The questionnaire_pick_row block renders them, and the CSS rule for
|
||||
* .questionnaire-pick hides the fields while the box is unticked - no JavaScript. Unticked fields
|
||||
* are still submitted; reverseTransform() drops them.
|
||||
*
|
||||
* Each type's model data is its stored answer, a plain array; the form data is the same with a
|
||||
* PICKED flag per pick. Required checks run on submit only (QuestionnaireType asks addMissing()),
|
||||
* so a draft takes any half-filled state.
|
||||
*/
|
||||
abstract class AbstractPickType extends AbstractType
|
||||
{
|
||||
public const string PICKED = 'picked';
|
||||
|
||||
protected const string MISSING = 'Bitte beantworte diese Frage.';
|
||||
|
||||
/**
|
||||
* Adds the errors that stand in the way of submitting this answer. The field's data is the
|
||||
* stored answer; errors go on the field or its children, where the template shows them.
|
||||
*/
|
||||
abstract public static function addMissing(FormInterface $field): void;
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'compound' => true,
|
||||
'required' => false,
|
||||
'error_bubbling' => false,
|
||||
'empty_data' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Closure(FormBuilderInterface): void $addFields the fields shown once it is ticked
|
||||
*/
|
||||
protected function addPick(FormBuilderInterface $parent, string $name, string $label, \Closure $addFields, string $blockPrefix = 'questionnaire_pick'): void
|
||||
{
|
||||
$pick = $parent->create($name, FormType::class, [
|
||||
'label' => false,
|
||||
'required' => false,
|
||||
'error_bubbling' => false,
|
||||
'block_prefix' => $blockPrefix,
|
||||
]);
|
||||
|
||||
$pick->add(self::PICKED, CheckboxType::class, [
|
||||
'label' => $label,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$addFields($pick);
|
||||
|
||||
$parent->add($pick);
|
||||
}
|
||||
|
||||
protected function addCount(FormBuilderInterface $pick, string $name, string $label): void
|
||||
{
|
||||
$pick->add($name, IntegerType::class, [
|
||||
'label' => $label,
|
||||
'required' => false,
|
||||
'invalid_message' => 'Bitte gib eine ganze Zahl ein.',
|
||||
'attr' => ['min' => 1],
|
||||
]);
|
||||
}
|
||||
|
||||
protected static function isPicked(mixed $data): bool
|
||||
{
|
||||
return is_array($data) && true === ($data[self::PICKED] ?? false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requires each named child of a ticked pick to hold a number above zero.
|
||||
*
|
||||
* @param list<string> $names
|
||||
*/
|
||||
protected static function requirePositive(FormInterface $pick, array $names): void
|
||||
{
|
||||
foreach ($names as $name) {
|
||||
$value = $pick->get($name)->getData();
|
||||
|
||||
if (null === $value) {
|
||||
$pick->get($name)->addError(new FormError(self::MISSING));
|
||||
} elseif ($value <= 0) {
|
||||
$pick->get($name)->addError(new FormError('Bitte gib eine Zahl größer als 0 ein.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Questionnaire;
|
||||
|
||||
use App\Model\Questionnaire\Option;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* A pick per teamer of the travel (option `teamers`, disposition uuid => label), and inside each a
|
||||
* pick per type the question offers (option `question_options`).
|
||||
*
|
||||
* Stored as a flat list, one row per teamer and type, so that a report unnests it with a single
|
||||
* JSON_TABLE(answers, '$.<question>[*]' ...) and groups by any of its fields:
|
||||
* [{disposition: <uuid>, type: <option key>, <field>: value, ...}, ...]. A teamer ticked without a
|
||||
* type yet is a row without `type`; only a draft can hold one, since submitting demands a type.
|
||||
*/
|
||||
abstract class AbstractTeamerPickType extends AbstractPickType
|
||||
{
|
||||
public const string DISPOSITION = 'disposition';
|
||||
public const string TYPE = 'type';
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver
|
||||
->setRequired(['teamers', 'question_options'])
|
||||
->setAllowedTypes('teamers', 'string[]')
|
||||
->setAllowedTypes('question_options', Option::class.'[]')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Every ticked teamer needs a ticked type, and every ticked type its fields.
|
||||
*
|
||||
* @param \Closure(FormInterface): void $checkType
|
||||
*/
|
||||
protected static function addMissingPerTeamer(FormInterface $field, \Closure $checkType, string $noTypeMessage): void
|
||||
{
|
||||
foreach ($field as $teamer) {
|
||||
if (true !== $teamer->get(self::PICKED)->getData()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$picked = 0;
|
||||
|
||||
foreach ($teamer as $name => $type) {
|
||||
if (self::PICKED === $name || true !== $type->get(self::PICKED)->getData()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
++$picked;
|
||||
$checkType($type);
|
||||
}
|
||||
|
||||
if (0 === $picked) {
|
||||
$teamer->addError(new FormError($noTypeMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $stored one row per teamer and type, see the class docblock
|
||||
* @param list<string> $fields
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected static function toForm(array $stored, array $fields): array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
foreach ($stored as $row) {
|
||||
$uuid = (string) ($row[self::DISPOSITION] ?? '');
|
||||
$data[$uuid][self::PICKED] = true;
|
||||
|
||||
if (null !== $type = $row[self::TYPE] ?? null) {
|
||||
$data[$uuid][$type] = [self::PICKED => true] + array_intersect_key($row, array_flip($fields));
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @param list<string> $fields
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
protected static function toStored(array $data, array $fields): array
|
||||
{
|
||||
$stored = [];
|
||||
|
||||
foreach ($data as $uuid => $teamer) {
|
||||
if (!self::isPicked($teamer)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$types = array_filter(
|
||||
$teamer,
|
||||
static fn (mixed $type, string $key): bool => self::PICKED !== $key && self::isPicked($type),
|
||||
ARRAY_FILTER_USE_BOTH,
|
||||
);
|
||||
|
||||
if ([] === $types) {
|
||||
// ticked without a type yet: kept so a draft remembers the tick
|
||||
$stored[] = [self::DISPOSITION => (string) $uuid];
|
||||
}
|
||||
|
||||
foreach ($types as $key => $type) {
|
||||
$values = array_intersect_key($type, array_flip($fields));
|
||||
$stored[] = [self::DISPOSITION => (string) $uuid, self::TYPE => $key] + array_replace(array_fill_keys($fields, null), $values);
|
||||
}
|
||||
}
|
||||
|
||||
return $stored;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Questionnaire;
|
||||
|
||||
use App\Form\AutosizeTextareaType;
|
||||
use App\Model\Questionnaire\Option;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* "Welches Programm hat stattgefunden?": the programme items (the question's options), each with
|
||||
* its number of participants once ticked, and "Sonstiges" with a free text.
|
||||
*
|
||||
* Stored as {items: [{item: <option key>, participants}, ...], other: text}, either part only when
|
||||
* ticked, an empty array when nothing is. The items are a flat list like the teamer questions', so a
|
||||
* report unnests them with one JSON_TABLE(answers, '$.programme.items[*]' ...).
|
||||
*/
|
||||
class ProgrammeType extends AbstractPickType
|
||||
{
|
||||
public const string ITEMS = 'items';
|
||||
public const string ITEM = 'item';
|
||||
public const string OTHER = 'other';
|
||||
public const string PARTICIPANTS = 'participants';
|
||||
public const string TEXT = 'text';
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
/** @var list<Option> $items */
|
||||
$items = $options['question_options'];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$this->addPick($builder, $item->key, $item->label, function (FormBuilderInterface $pick): void {
|
||||
$this->addCount($pick, self::PARTICIPANTS, 'Teilnehmende');
|
||||
}, 'questionnaire_pick_inline');
|
||||
}
|
||||
|
||||
$this->addPick($builder, self::OTHER, 'Sonstiges', function (FormBuilderInterface $pick): void {
|
||||
$pick->add(self::TEXT, AutosizeTextareaType::class, [
|
||||
'label' => 'Was hat noch stattgefunden?',
|
||||
'required' => false,
|
||||
'min_rows' => 2,
|
||||
]);
|
||||
});
|
||||
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
static function (?array $stored): array {
|
||||
$data = [];
|
||||
|
||||
foreach ($stored[self::ITEMS] ?? [] as $row) {
|
||||
$data[(string) $row[self::ITEM]] = [self::PICKED => true, self::PARTICIPANTS => $row[self::PARTICIPANTS] ?? null];
|
||||
}
|
||||
|
||||
if (array_key_exists(self::OTHER, $stored ?? [])) {
|
||||
$data[self::OTHER] = [self::PICKED => true, self::TEXT => $stored[self::OTHER]];
|
||||
}
|
||||
|
||||
return $data;
|
||||
},
|
||||
static function (?array $data): array {
|
||||
$stored = [];
|
||||
|
||||
foreach ($data ?? [] as $key => $pick) {
|
||||
if (!self::isPicked($pick)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (self::OTHER === $key) {
|
||||
$stored[self::OTHER] = $pick[self::TEXT] ?? null;
|
||||
} else {
|
||||
$stored[self::ITEMS][] = [self::ITEM => $key, self::PARTICIPANTS => $pick[self::PARTICIPANTS] ?? null];
|
||||
}
|
||||
}
|
||||
|
||||
return $stored;
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver
|
||||
->setRequired('question_options')
|
||||
->setAllowedTypes('question_options', Option::class.'[]')
|
||||
// "other" is the Sonstiges pick
|
||||
->setAllowedValues('question_options', static fn (array $items): bool => [] === array_filter($items, static fn (Option $item): bool => self::OTHER === $item->key))
|
||||
;
|
||||
}
|
||||
|
||||
public static function addMissing(FormInterface $field): void
|
||||
{
|
||||
foreach ($field as $name => $pick) {
|
||||
if (true !== $pick->get(self::PICKED)->getData()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (self::OTHER !== $name) {
|
||||
self::requirePositive($pick, [self::PARTICIPANTS]);
|
||||
} elseif ('' === trim((string) $pick->get(self::TEXT)->getData())) {
|
||||
$pick->get(self::TEXT)->addError(new FormError(self::MISSING));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Questionnaire;
|
||||
|
||||
use App\Model\Questionnaire\Option;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* "Wer hat welche Kurse gegeben?": the travel's teamers to tick, per ticked teamer the course types
|
||||
* (the question's options), and per ticked course type days × hours per day and the days it took
|
||||
* place. The days to pick are the travel's own dates rather than Sunday to Saturday: a travel runs
|
||||
* Saturday to Saturday, so a weekday alone would not say which Saturday.
|
||||
*
|
||||
* Stored as [{disposition, type, days, hours_per_day, dates: [Y-m-d, ...]}, ...]
|
||||
* (AbstractTeamerPickType). The number of days is not checked against the dates picked.
|
||||
*/
|
||||
class TeamerCoursesType extends AbstractTeamerPickType
|
||||
{
|
||||
public const string DAYS = 'days';
|
||||
public const string HOURS_PER_DAY = 'hours_per_day';
|
||||
public const string DATES = 'dates';
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
/** @var list<Option> $courseTypes */
|
||||
$courseTypes = $options['question_options'];
|
||||
$dates = array_map(static fn (\DateTimeImmutable $day): string => $day->format('Y-m-d'), $options['days']);
|
||||
// "So. 28.03.", as _answers.html.twig shows them
|
||||
$dayLabel = new \IntlDateFormatter('de', \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, null, 'EEEEEE dd.MM.');
|
||||
|
||||
foreach ($options['teamers'] as $uuid => $label) {
|
||||
$this->addPick($builder, $uuid, $label, function (FormBuilderInterface $teamer) use ($courseTypes, $dates, $dayLabel): void {
|
||||
foreach ($courseTypes as $courseType) {
|
||||
$this->addPick($teamer, $courseType->key, $courseType->label, function (FormBuilderInterface $pick) use ($dates, $dayLabel): void {
|
||||
$this->addCount($pick, self::DAYS, 'Tage');
|
||||
$pick->add(self::HOURS_PER_DAY, NumberType::class, [
|
||||
'label' => 'Stunden pro Tag',
|
||||
'required' => false,
|
||||
'scale' => 2,
|
||||
'invalid_message' => 'Bitte gib eine Zahl ein.',
|
||||
'attr' => ['inputmode' => 'decimal'],
|
||||
]);
|
||||
$pick->add(self::DATES, ChoiceType::class, [
|
||||
'label' => 'Wann hat der Kurs stattgefunden?',
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $dates,
|
||||
'choice_label' => static fn (string $date): string => (string) $dayLabel->format(new \DateTimeImmutable($date)),
|
||||
'block_prefix' => 'questionnaire_days',
|
||||
]);
|
||||
}, 'questionnaire_pick_course');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
static fn (?array $stored): array => self::toForm($stored ?? [], [self::DAYS, self::HOURS_PER_DAY, self::DATES]),
|
||||
static fn (?array $data): array => self::toStored($data ?? [], [self::DAYS, self::HOURS_PER_DAY, self::DATES]),
|
||||
));
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver
|
||||
->setRequired('days')
|
||||
->setAllowedTypes('days', \DateTimeImmutable::class.'[]')
|
||||
;
|
||||
}
|
||||
|
||||
public static function addMissing(FormInterface $field): void
|
||||
{
|
||||
self::addMissingPerTeamer($field, static function (FormInterface $pick): void {
|
||||
self::requirePositive($pick, [self::DAYS, self::HOURS_PER_DAY]);
|
||||
|
||||
if ([] === ($pick->get(self::DATES)->getData() ?? [])) {
|
||||
$pick->get(self::DATES)->addError(new FormError('Bitte wähle mindestens einen Tag aus.'));
|
||||
}
|
||||
}, 'Bitte wähle mindestens eine Kursart aus.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Questionnaire;
|
||||
|
||||
use App\Model\Questionnaire\Option;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
/**
|
||||
* "Wer hat das Guiding gegeben?": the travel's teamers to tick, and per ticked teamer the guiding
|
||||
* types (the question's options) with the number of guidings and the participants per guiding.
|
||||
*
|
||||
* Stored as [{disposition, type, count, participants}, ...] (AbstractTeamerPickType).
|
||||
*/
|
||||
class TeamerGuidingsType extends AbstractTeamerPickType
|
||||
{
|
||||
public const string COUNT = 'count';
|
||||
public const string PARTICIPANTS = 'participants';
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
/** @var list<Option> $guidingTypes */
|
||||
$guidingTypes = $options['question_options'];
|
||||
|
||||
foreach ($options['teamers'] as $uuid => $label) {
|
||||
$this->addPick($builder, $uuid, $label, function (FormBuilderInterface $teamer) use ($guidingTypes): void {
|
||||
foreach ($guidingTypes as $guidingType) {
|
||||
$this->addPick($teamer, $guidingType->key, $guidingType->label, function (FormBuilderInterface $pick): void {
|
||||
$this->addCount($pick, self::COUNT, 'Guidings');
|
||||
$this->addCount($pick, self::PARTICIPANTS, 'Teilnehmende je Guiding');
|
||||
}, 'questionnaire_pick_inline');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
static fn (?array $stored): array => self::toForm($stored ?? [], [self::COUNT, self::PARTICIPANTS]),
|
||||
static fn (?array $data): array => self::toStored($data ?? [], [self::COUNT, self::PARTICIPANTS]),
|
||||
));
|
||||
}
|
||||
|
||||
public static function addMissing(FormInterface $field): void
|
||||
{
|
||||
self::addMissingPerTeamer($field, static fn (FormInterface $pick) => self::requirePositive($pick, [self::COUNT, self::PARTICIPANTS]), 'Bitte wähle mindestens ein Guiding aus.');
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,14 @@ namespace App\Form;
|
||||
use App\Enum\BusLeg;
|
||||
use App\Enum\ChoiceWidget;
|
||||
use App\Enum\QuestionType;
|
||||
use App\Form\Questionnaire\AbstractPickType;
|
||||
use App\Form\Questionnaire\ProgrammeType;
|
||||
use App\Form\Questionnaire\TeamerCoursesType;
|
||||
use App\Form\Questionnaire\TeamerGuidingsType;
|
||||
use App\Model\Questionnaire\Definition;
|
||||
use App\Model\Questionnaire\Option;
|
||||
use App\Model\Questionnaire\Question;
|
||||
use App\Model\Questionnaire\Travel;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\ClickableInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
@@ -33,8 +38,11 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
* {legs: 'outbound'|'return'|'both'|null, outbound: {...}, return: {...}}. answerSets() turns the
|
||||
* data into one answer set per questionnaire and chosen leg, the responses to store.
|
||||
*
|
||||
* The house manager's questionnaire asks about the travel's teamers; the `travel` option offers
|
||||
* them (and the travel's days), and a definition using such a question cannot be built without it.
|
||||
*
|
||||
* Two buttons: "draft" saves whatever is filled in, "submit" also demands every required question
|
||||
* that is shown. No field is HTML-required, or the browser would refuse to send a half-filled
|
||||
* that is shown, and of a bespoke widget (App\Form\Questionnaire) its own fields. No field is HTML-required, or the browser would refuse to send a half-filled
|
||||
* draft. Whether a question is shown is Definition::isVisible(), the same rule the
|
||||
* questionnaire Stimulus controller applies on screen via the row's data-show-if.
|
||||
*/
|
||||
@@ -47,10 +55,19 @@ class QuestionnaireType extends AbstractType
|
||||
|
||||
private const int RATING_MAX = 5;
|
||||
|
||||
/**
|
||||
* A radio question whose options are all this short - "Ja"/"Nein" and the like - is answered
|
||||
* with a row of buttons beside the question instead of one full-width row per option.
|
||||
*/
|
||||
private const int INLINE_OPTIONS_MAX = 4;
|
||||
private const int INLINE_LABEL_MAX = 20;
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
/** @var list<Definition> $definitions */
|
||||
$definitions = $options['definitions'];
|
||||
/** @var Travel|null $travel */
|
||||
$travel = $options['travel'];
|
||||
|
||||
foreach ($definitions as $definition) {
|
||||
$questionnaireBuilder = $builder->create($definition->key, FormType::class, [
|
||||
@@ -62,9 +79,9 @@ class QuestionnaireType extends AbstractType
|
||||
]);
|
||||
|
||||
if ($definition->perBusLeg) {
|
||||
$this->addLegs($builder, $questionnaireBuilder, $definition);
|
||||
$this->addLegs($builder, $questionnaireBuilder, $definition, $travel);
|
||||
} else {
|
||||
$this->addSections($builder, $questionnaireBuilder, $definition, $definition->key);
|
||||
$this->addSections($builder, $questionnaireBuilder, $definition, $definition->key, $travel);
|
||||
}
|
||||
|
||||
$builder->add($questionnaireBuilder);
|
||||
@@ -101,13 +118,20 @@ class QuestionnaireType extends AbstractType
|
||||
|
||||
foreach ($definition->sections as $section) {
|
||||
foreach ($section->questions as $question) {
|
||||
if ($question->required
|
||||
&& $definition->isVisible($question, $answers)
|
||||
&& $this->isEmpty($answers[$question->key] ?? null)
|
||||
) {
|
||||
$parent->get($section->key)->get($question->key)->addError(
|
||||
new FormError('Bitte beantworte diese Frage.')
|
||||
);
|
||||
if (!$definition->isVisible($question, $answers)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$field = $parent->get($section->key)->get($question->key);
|
||||
|
||||
if ($question->required && $this->isEmpty($answers[$question->key] ?? null)) {
|
||||
$field->addError(new FormError('Bitte beantworte diese Frage.'));
|
||||
}
|
||||
|
||||
$widget = $field->getConfig()->getType()->getInnerType();
|
||||
|
||||
if ($widget instanceof AbstractPickType) {
|
||||
$widget::addMissing($field);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +150,9 @@ class QuestionnaireType extends AbstractType
|
||||
->setDefaults([
|
||||
'data_class' => null,
|
||||
'empty_data' => [],
|
||||
'travel' => null,
|
||||
])
|
||||
->setAllowedTypes('travel', ['null', Travel::class])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -202,7 +228,7 @@ class QuestionnaireType extends AbstractType
|
||||
return self::BOTH_LEGS === $legs ? BusLeg::cases() : array_values(array_filter([BusLeg::tryFrom((string) $legs)]));
|
||||
}
|
||||
|
||||
private function addLegs(FormBuilderInterface $builder, FormBuilderInterface $questionnaireBuilder, Definition $definition): void
|
||||
private function addLegs(FormBuilderInterface $builder, FormBuilderInterface $questionnaireBuilder, Definition $definition, ?Travel $travel): void
|
||||
{
|
||||
$questionnaireBuilder->add(self::LEGS, ChoiceType::class, [
|
||||
'label' => 'Welche Fahrten hast du begleitet?',
|
||||
@@ -232,7 +258,7 @@ class QuestionnaireType extends AbstractType
|
||||
],
|
||||
]);
|
||||
|
||||
$this->addSections($builder, $legBuilder, $definition, $definition->key.'.'.$leg->value);
|
||||
$this->addSections($builder, $legBuilder, $definition, $definition->key.'.'.$leg->value, $travel);
|
||||
$questionnaireBuilder->add($legBuilder);
|
||||
}
|
||||
}
|
||||
@@ -240,7 +266,7 @@ class QuestionnaireType extends AbstractType
|
||||
/**
|
||||
* @param string $prefix makes the question keys the Stimulus controller sees unique on the page
|
||||
*/
|
||||
private function addSections(FormBuilderInterface $builder, FormBuilderInterface $parent, Definition $definition, string $prefix): void
|
||||
private function addSections(FormBuilderInterface $builder, FormBuilderInterface $parent, Definition $definition, string $prefix, ?Travel $travel): void
|
||||
{
|
||||
foreach ($definition->sections as $section) {
|
||||
$sectionBuilder = $builder->create($section->key, FormType::class, [
|
||||
@@ -251,7 +277,7 @@ class QuestionnaireType extends AbstractType
|
||||
]);
|
||||
|
||||
foreach ($section->questions as $question) {
|
||||
$sectionBuilder->add($question->key, ...$this->field($prefix, $question));
|
||||
$sectionBuilder->add($question->key, ...$this->field($prefix, $question, $travel));
|
||||
}
|
||||
|
||||
$parent->add($sectionBuilder);
|
||||
@@ -261,7 +287,7 @@ class QuestionnaireType extends AbstractType
|
||||
/**
|
||||
* @return array{0: class-string, 1: array<string, mixed>}
|
||||
*/
|
||||
private function field(string $prefix, Question $question): array
|
||||
private function field(string $prefix, Question $question, ?Travel $travel): array
|
||||
{
|
||||
$common = [
|
||||
'label' => $question->label,
|
||||
@@ -275,6 +301,8 @@ class QuestionnaireType extends AbstractType
|
||||
'operator' => $question->showIf->operator->value,
|
||||
'value' => $question->showIf->value,
|
||||
], JSON_THROW_ON_ERROR),
|
||||
// a follow-up is indented under the question that opened it
|
||||
'class' => '-mt-2 border-l-2 border-gray-200 pl-4',
|
||||
]),
|
||||
];
|
||||
|
||||
@@ -285,7 +313,7 @@ class QuestionnaireType extends AbstractType
|
||||
'expanded' => true,
|
||||
// a radio list needs no "none" entry
|
||||
'placeholder' => false,
|
||||
'block_prefix' => 'questionnaire_choice',
|
||||
'block_prefix' => $this->hasShortOptions($question) ? 'questionnaire_inline_choice' : 'questionnaire_choice',
|
||||
] : [
|
||||
'expanded' => false,
|
||||
// a select needs an empty first line, or the first option would be preselected
|
||||
@@ -306,6 +334,13 @@ class QuestionnaireType extends AbstractType
|
||||
'placeholder' => false,
|
||||
'block_prefix' => 'questionnaire_rating',
|
||||
]],
|
||||
QuestionType::TEAMER_GUIDINGS => [TeamerGuidingsType::class, $common + $this->travelOptions($question, $travel)],
|
||||
QuestionType::TEAMER_COURSES => [TeamerCoursesType::class, $common + $this->travelOptions($question, $travel) + [
|
||||
'days' => $travel->days,
|
||||
]],
|
||||
QuestionType::PROGRAMME => [ProgrammeType::class, $common + [
|
||||
'question_options' => $question->options,
|
||||
]],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -323,6 +358,27 @@ class QuestionnaireType extends AbstractType
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{teamers: array<string, string>, question_options: list<Option>}
|
||||
*/
|
||||
private function travelOptions(Question $question, ?Travel $travel): array
|
||||
{
|
||||
if (null === $travel) {
|
||||
throw new \LogicException(sprintf('Question "%s" needs the travel option', $question->key));
|
||||
}
|
||||
|
||||
return [
|
||||
'teamers' => $travel->teamers,
|
||||
'question_options' => $question->options,
|
||||
];
|
||||
}
|
||||
|
||||
private function hasShortOptions(Question $question): bool
|
||||
{
|
||||
return count($question->options) <= self::INLINE_OPTIONS_MAX
|
||||
&& [] === array_filter($question->options, static fn (Option $option): bool => mb_strlen($option->label) > self::INLINE_LABEL_MAX);
|
||||
}
|
||||
|
||||
private function isEmpty(mixed $answer): bool
|
||||
{
|
||||
return null === $answer || '' === $answer || [] === $answer;
|
||||
|
||||
@@ -28,6 +28,7 @@ class HouseManagerMenuBuilder extends AbstractMenuBuilder
|
||||
'icon' => 'feedback',
|
||||
'routes' => [
|
||||
['pattern' => '/^app_house_manager_feedback_/'],
|
||||
['pattern' => '/^app_house_manager_questionnaire_/'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\Questionnaire;
|
||||
|
||||
/**
|
||||
* What the house manager's teamer questions offer to pick from: the travel's teamers and its days.
|
||||
* Passed to QuestionnaireType as its `travel` option; built by DestinationContext::travel().
|
||||
*/
|
||||
readonly class Travel
|
||||
{
|
||||
/**
|
||||
* @param array<string, string> $teamers disposition uuid => label, in the order to show them
|
||||
* @param list<\DateTimeImmutable> $days every day of the travel, first to last
|
||||
*/
|
||||
public function __construct(
|
||||
public array $teamers,
|
||||
public array $days,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<\DateTimeImmutable>
|
||||
*/
|
||||
public static function daysBetween(\DateTimeImmutable $from, \DateTimeImmutable $to): array
|
||||
{
|
||||
$days = [];
|
||||
|
||||
for ($day = $from->setTime(0, 0); $day <= $to; $day = $day->modify('+1 day')) {
|
||||
$days[] = $day;
|
||||
}
|
||||
|
||||
return $days;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,17 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
use App\Enum\QuestionnaireResponseStatus;
|
||||
use App\Model\DestinationFilterDto;
|
||||
use App\Repository\Traits\QueryHelperTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -161,4 +168,117 @@ class DestinationRepository extends ServiceEntityRepository
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ended travels a house manager still owes something for, one row per travel: the
|
||||
* questionnaire is not submitted (only for travels ended on or after $goLive), or a placement
|
||||
* still has no rating and is not waived. The two are independent - the questionnaire can be
|
||||
* submitted while ratings are missing.
|
||||
*
|
||||
* A travel counts only with at least one placement a house manager rates
|
||||
* (DispositionRepository::findForHouseManagerQuestionnaire() spells the same rule): a travel
|
||||
* nobody worked on has nothing to report.
|
||||
*
|
||||
* Rows are [0 => Destination, 'questionnaireStatus' => ?string (QuestionnaireResponseStatus
|
||||
* value, null without a response), 'placements' => int, 'openFeedbacks' => int].
|
||||
*
|
||||
* @param list<string>|null $hotelCodes the house manager's (User::$hotelCodes), matched on
|
||||
* either end of the travel's code as everywhere else;
|
||||
* null for every house
|
||||
* @param Teamer|null $houseManager the house manager's own teamer, whose placement they
|
||||
* do not rate
|
||||
*/
|
||||
public function getPendingForHouseManagerQuery(?array $hotelCodes, \DateTimeImmutable $goLive, \DateTimeImmutable $endedBy, ?Teamer $houseManager = null): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('destination');
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
// a placement of this travel that a house manager rates; $alias keeps the subqueries apart
|
||||
$placements = static function (string $alias, string $select, bool $unrated = false) use ($em, $houseManager): string {
|
||||
$sub = $em->createQueryBuilder()
|
||||
->select(sprintf($select, $alias))
|
||||
->from(Disposition::class, $alias)
|
||||
->innerJoin($alias.'.assignment', $alias.'_assignment')
|
||||
->where($alias.'_assignment.destination = destination')
|
||||
->andWhere($alias.'.status <> :dispositionCalledOff')
|
||||
->andWhere($alias.'_assignment.status NOT IN (:assignmentStatuses)')
|
||||
->andWhere($alias.'_assignment.skipFormalities = :skipFormalities')
|
||||
;
|
||||
|
||||
if (null !== $houseManager) {
|
||||
$sub->andWhere($alias.'.teamer <> :houseManager');
|
||||
}
|
||||
|
||||
if ($unrated) {
|
||||
$sub
|
||||
->andWhere($alias.'.feedback IS NULL')
|
||||
->andWhere($alias.'.feedbackWaived = :feedbackWaived')
|
||||
;
|
||||
}
|
||||
|
||||
return $sub->getDQL();
|
||||
};
|
||||
|
||||
// this travel's house manager questionnaire
|
||||
$response = static function (string $alias, string $select, bool $submitted = false) use ($em): string {
|
||||
$sub = $em->createQueryBuilder()
|
||||
->select(sprintf($select, $alias))
|
||||
->from(QuestionnaireResponse::class, $alias)
|
||||
->where($alias.'.destination = destination')
|
||||
->andWhere($alias.'.questionnaire = :questionnaire')
|
||||
;
|
||||
|
||||
if ($submitted) {
|
||||
$sub->andWhere($alias.'.status = :submitted');
|
||||
}
|
||||
|
||||
return $sub->getDQL();
|
||||
};
|
||||
|
||||
$qb
|
||||
->select(
|
||||
'destination',
|
||||
'('.$response('status_response', '%s.status').') AS questionnaireStatus',
|
||||
'('.$placements('counted', 'COUNT(%s.id)').') AS placements',
|
||||
'('.$placements('unrated_count', 'COUNT(%s.id)', true).') AS openFeedbacks',
|
||||
)
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->isNull('destination.deletedAt'),
|
||||
$qb->expr()->lte('destination.dateTo', ':endedBy'),
|
||||
$qb->expr()->exists($placements('staffed', '%s.id')),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->gte('destination.dateTo', ':goLive'),
|
||||
$qb->expr()->not($qb->expr()->exists($response('submitted_response', '%s.id', true)))
|
||||
),
|
||||
$qb->expr()->exists($placements('unrated', '%s.id', true))
|
||||
)
|
||||
))
|
||||
->orderBy('destination.dateTo', \SortDirection::Ascending)
|
||||
->setParameter('endedBy', $endedBy, Types::DATE_IMMUTABLE)
|
||||
->setParameter('goLive', $goLive, Types::DATE_IMMUTABLE)
|
||||
->setParameter('questionnaire', QuestionnaireCatalog::HOUSE_MANAGER_FEEDBACK)
|
||||
->setParameter('submitted', QuestionnaireResponseStatus::SUBMITTED)
|
||||
->setParameter('dispositionCalledOff', Disposition::STATUS_CALLED_OFF)
|
||||
->setParameter('assignmentStatuses', [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED])
|
||||
->setParameter('skipFormalities', false)
|
||||
->setParameter('feedbackWaived', false)
|
||||
;
|
||||
|
||||
if (null !== $houseManager) {
|
||||
$qb->setParameter('houseManager', $houseManager);
|
||||
}
|
||||
|
||||
if (null !== $hotelCodes) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->in($qb->expr()->substring('destination.hotelCode', 1, 3), ':hotelCodes'),
|
||||
$qb->expr()->in($qb->expr()->substring('destination.hotelCode', -3, 3), ':hotelCodes'),
|
||||
))
|
||||
->setParameter('hotelCodes', $hotelCodes)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb->getQuery();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Entity\Teamer;
|
||||
@@ -393,6 +394,80 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* The travel's teamers as the house manager's questionnaire lists them: every placement on it
|
||||
* that is not called off, on an assignment that is neither called off nor deleted nor
|
||||
* skip-formalities - the placements a house manager rates. The house manager's own placement,
|
||||
* if they hold one, is left out: nobody rates themselves.
|
||||
*
|
||||
* DestinationRepository::getPendingForHouseManagerQuery() spells the same rule in DQL.
|
||||
*
|
||||
* @return list<Disposition> by job profile, then teamer; teamer, job profile and feedback loaded
|
||||
*/
|
||||
public function findForHouseManagerQuestionnaire(Destination $destination, ?Teamer $houseManager = null): array
|
||||
{
|
||||
$qb = $this->createHouseManagerPlacementsQueryBuilder([$destination]);
|
||||
|
||||
if (null !== $houseManager) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->neq('disposition.teamer', ':houseManager'))
|
||||
->setParameter('houseManager', $houseManager)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* The same placements for several travels at once, for the house manager's pending list.
|
||||
*
|
||||
* @param list<Destination> $destinations
|
||||
*
|
||||
* @return array<int, list<Disposition>> keyed by destination id
|
||||
*/
|
||||
public function findForHouseManagerByDestinations(array $destinations): array
|
||||
{
|
||||
if ([] === $destinations) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$placements = [];
|
||||
|
||||
foreach ($this->createHouseManagerPlacementsQueryBuilder($destinations)->getQuery()->getResult() as $disposition) {
|
||||
$placements[$disposition->getAssignment()->getDestination()->getId()][] = $disposition;
|
||||
}
|
||||
|
||||
return $placements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<Destination> $destinations
|
||||
*/
|
||||
private function createHouseManagerPlacementsQueryBuilder(array $destinations): QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
return $qb
|
||||
->select('disposition', 'assignment', 'job_profile', 'teamer', 'feedback')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.jobProfile', 'job_profile')
|
||||
->innerJoin('disposition.teamer', 'teamer')
|
||||
->leftJoin('disposition.feedback', 'feedback')
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->in('assignment.destination', ':destinations'),
|
||||
$qb->expr()->neq('disposition.status', ':dispositionCalledOff'),
|
||||
$qb->expr()->notIn('assignment.status', ':assignmentStatuses'),
|
||||
$this->excludesSkipFormalities($qb)
|
||||
))
|
||||
->orderBy('job_profile.name')
|
||||
->addOrderBy('teamer.lastName')
|
||||
->addOrderBy('teamer.firstName')
|
||||
->setParameter('destinations', $destinations)
|
||||
->setParameter('dispositionCalledOff', Disposition::STATUS_CALLED_OFF)
|
||||
->setParameter('assignmentStatuses', [Assignment::STATUS_CALLED_OFF, Assignment::STATUS_DELETED])
|
||||
;
|
||||
}
|
||||
|
||||
public function findDispositionsWithOverdueFeedback(?int $offsetDays = null): array
|
||||
{
|
||||
return $this
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\QuestionnaireResponse;
|
||||
use App\Enum\QuestionnaireResponseStatus;
|
||||
@@ -28,19 +30,16 @@ class QuestionnaireResponseRepository extends ServiceEntityRepository
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* respondent submits, a response is theirs. Filtered and sorted on the live disposition or
|
||||
* travel rather than the snapshot in `context`, which JSON would make neither sortable nor
|
||||
* indexable. The house manager's questionnaire is about a travel, so it has no teamer to
|
||||
* filter by.
|
||||
*/
|
||||
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')
|
||||
@@ -49,11 +48,26 @@ class QuestionnaireResponseRepository extends ServiceEntityRepository
|
||||
->setParameter('submitted', QuestionnaireResponseStatus::SUBMITTED)
|
||||
;
|
||||
|
||||
if (null !== $teamer = $filterDto->getTeamer()) {
|
||||
if (QuestionnaireCatalog::HOUSE_MANAGER_FEEDBACK === $questionnaire) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('disposition.teamer', ':teamer'))
|
||||
->setParameter('teamer', $teamer)
|
||||
->select('response', 'destination')
|
||||
->innerJoin('response.destination', 'destination')
|
||||
;
|
||||
} else {
|
||||
$qb
|
||||
->select('response', 'disposition', 'teamer', 'assignment', 'destination')
|
||||
->innerJoin('response.disposition', 'disposition')
|
||||
->innerJoin('disposition.teamer', 'teamer')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
;
|
||||
|
||||
if (null !== $teamer = $filterDto->getTeamer()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('disposition.teamer', ':teamer'))
|
||||
->setParameter('teamer', $teamer)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $hotel = $filterDto->getHotel()) {
|
||||
@@ -95,4 +109,15 @@ class QuestionnaireResponseRepository extends ServiceEntityRepository
|
||||
|
||||
return $responses;
|
||||
}
|
||||
|
||||
/**
|
||||
* The house manager's questionnaire about this travel, draft or submitted.
|
||||
*/
|
||||
public function findForDestination(Destination $destination): ?QuestionnaireResponse
|
||||
{
|
||||
return $this->findOneBy([
|
||||
'destination' => $destination,
|
||||
'questionnaire' => QuestionnaireCatalog::HOUSE_MANAGER_FEEDBACK,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security\Voter;
|
||||
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\User;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
|
||||
/**
|
||||
* @extends Voter<string, Destination>
|
||||
*/
|
||||
class DestinationVoter extends Voter
|
||||
{
|
||||
/**
|
||||
* Fill in, and read once submitted, the house manager's questionnaire about this travel.
|
||||
*/
|
||||
public const QUESTIONNAIRE = 'QUESTIONNAIRE';
|
||||
|
||||
private readonly \DateTimeImmutable $goLive;
|
||||
|
||||
/**
|
||||
* @param string $houseManagerQuestionnaireGoLive Y-m-d, the services.yaml parameter
|
||||
* house_manager_questionnaire_go_live
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly Security $security,
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
string $houseManagerQuestionnaireGoLive,
|
||||
) {
|
||||
$this->goLive = QuestionnaireCatalog::parseGoLive($houseManagerQuestionnaireGoLive);
|
||||
}
|
||||
|
||||
protected function supports(string $attribute, mixed $subject): bool
|
||||
{
|
||||
return $subject instanceof Destination && self::QUESTIONNAIRE === $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* A house manager of the travel's house (User::hasHotelCodeMatch(), as for rating its teamers),
|
||||
* once the travel has ended - anchored on the date, like the teamer questionnaire - if it
|
||||
* ended on or after the go-live and had at least one placement a house manager rates: a
|
||||
* travel nobody worked on has nothing to report.
|
||||
*/
|
||||
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token, ?Vote $vote = null): bool
|
||||
{
|
||||
if (!$this->security->isGranted('ROLE_HOUSE_MANAGER')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $token->getUser();
|
||||
|
||||
if (!$user instanceof User || !$user->hasHotelCodeMatch((string) $subject->getHotelCode())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dateTo = $subject->getDateTo();
|
||||
|
||||
return null === $subject->getDeletedAt()
|
||||
&& null !== $dateTo
|
||||
&& $dateTo >= $this->goLive
|
||||
&& $dateTo <= new \DateTimeImmutable('today')
|
||||
&& [] !== $this->dispositionRepository->findForHouseManagerQuestionnaire($subject);
|
||||
}
|
||||
}
|
||||
@@ -3,33 +3,46 @@
|
||||
namespace App\Service\Cron;
|
||||
|
||||
use App\BusProNet\DataProvider\HotelDataProvider;
|
||||
use App\Config\QuestionnaireCatalog;
|
||||
use App\Email\Mailer;
|
||||
use App\Entity\Disposition;
|
||||
use App\Repository\DispositionRepository;
|
||||
use App\Entity\Destination;
|
||||
use App\Repository\DestinationRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Reminds house managers, daily, of the travels they still owe something for: the questionnaire
|
||||
* about the travel or a teamer's rating - the house manager's pending list
|
||||
* (DestinationRepository::getPendingForHouseManagerQuery()).
|
||||
*/
|
||||
class FeedbackReminderService
|
||||
{
|
||||
private readonly \DateTimeImmutable $goLive;
|
||||
|
||||
public function __construct(
|
||||
private readonly DispositionRepository $dispositionRepository,
|
||||
private readonly DestinationRepository $destinationRepository,
|
||||
private readonly HotelDataProvider $hotelDataProvider,
|
||||
private readonly UserRepository $userRepository,
|
||||
private readonly Mailer $mailer,
|
||||
private readonly LoggerInterface $logger,
|
||||
string $houseManagerQuestionnaireGoLive,
|
||||
) {
|
||||
$this->goLive = QuestionnaireCatalog::parseGoLive($houseManagerQuestionnaireGoLive);
|
||||
}
|
||||
|
||||
public function sendFeedbackReminders(): string
|
||||
{
|
||||
/** @var Disposition[] $dispositionsWithPendingFeedbacks */
|
||||
$dispositionsWithPendingFeedbacks = $this->dispositionRepository->findDispositionsWithOverdueFeedback();
|
||||
/** @var list<Destination> $pendingTravels */
|
||||
$pendingTravels = array_column(
|
||||
$this->destinationRepository->getPendingForHouseManagerQuery(null, $this->goLive, new \DateTimeImmutable('today'))->getResult(),
|
||||
0,
|
||||
);
|
||||
|
||||
$sortedFeedbacks = [];
|
||||
|
||||
foreach ($dispositionsWithPendingFeedbacks as $disposition) {
|
||||
foreach ($pendingTravels as $destination) {
|
||||
// Get hotel by bus pro id
|
||||
$hotelBusProId = $disposition->getAssignment()->getDestination()->getHotelBusProId();
|
||||
$hotelBusProId = $destination->getHotelBusProId();
|
||||
$hotel = $this->hotelDataProvider->get($hotelBusProId);
|
||||
|
||||
if (null === $hotel) {
|
||||
@@ -45,7 +58,7 @@ class FeedbackReminderService
|
||||
}
|
||||
|
||||
// Sort feedback by hotel base code
|
||||
$sortedFeedbacks[$hotelCode][] = $disposition;
|
||||
$sortedFeedbacks[$hotelCode][] = $destination;
|
||||
}
|
||||
|
||||
// find hotel managers by hotel codes starting or ending with base code
|
||||
@@ -79,7 +92,7 @@ class FeedbackReminderService
|
||||
'feedbacks' => $feedbacksForManager,
|
||||
], [
|
||||
'to' => $manager->getEmail(),
|
||||
'subject' => 'Reminder: Offene Feedbacks',
|
||||
'subject' => 'Reminder: Offene Feedbacks und Fragebögen',
|
||||
'template' => 'email/reminder_pending_feedback.html.twig',
|
||||
'transport' => Mailer::MAILJET_TRANSPORT,
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Questionnaire;
|
||||
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Model\Questionnaire\Travel;
|
||||
|
||||
/**
|
||||
* What a travel already knows, for the house manager's questionnaire: snapshotted into the
|
||||
* response (build()), offered to its teamer questions (travel()) and used to preselect answers
|
||||
* (initialAnswers()).
|
||||
*
|
||||
* The placements are the travel's teamers as DispositionRepository::findForHouseManagerQuestionnaire()
|
||||
* returns them; the caller leaves out the house manager's own.
|
||||
*/
|
||||
final class DestinationContext
|
||||
{
|
||||
/**
|
||||
* The question preselected from the travel's pickups, and its options.
|
||||
*/
|
||||
private const string BUS_ARRIVAL = 'bus_arrival';
|
||||
private const string YES = 'ja';
|
||||
private const string NO = 'nein';
|
||||
|
||||
/**
|
||||
* @param list<Disposition> $dispositions
|
||||
*/
|
||||
public static function travel(Destination $destination, array $dispositions): Travel
|
||||
{
|
||||
return new Travel(
|
||||
array_column(array_map(static fn (Disposition $disposition): array => [
|
||||
$disposition->getUuid(),
|
||||
self::teamerLabel($disposition),
|
||||
], $dispositions), 1, 0),
|
||||
Travel::daysBetween($destination->getDateFrom(), $destination->getDateTo()),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plain scalars (dates as Y-m-d), stored as JSON: the answers keyed by disposition uuid stay
|
||||
* readable after a placement is called off or the teamer changes.
|
||||
*
|
||||
* @param list<Disposition> $dispositions
|
||||
*
|
||||
* @return array{
|
||||
* destinationProduct: ?string,
|
||||
* hotel: ?string,
|
||||
* hotelCode: ?string,
|
||||
* dateFrom: ?string,
|
||||
* dateTo: ?string,
|
||||
* teamers: array<string, array{name: ?string, jobProfileName: ?string}>,
|
||||
* }
|
||||
*/
|
||||
public static function build(Destination $destination, array $dispositions): array
|
||||
{
|
||||
$teamers = [];
|
||||
|
||||
foreach ($dispositions as $disposition) {
|
||||
$teamers[$disposition->getUuid()] = [
|
||||
'name' => $disposition->getTeamer()?->getFullName(),
|
||||
'jobProfileName' => $disposition->getAssignment()?->getJobProfile()?->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'destinationProduct' => $destination->getProduct(),
|
||||
'hotel' => $destination->getHotel(),
|
||||
'hotelCode' => $destination->getHotelCode(),
|
||||
'dateFrom' => $destination->getDateFrom()?->format('Y-m-d'),
|
||||
'dateTo' => $destination->getDateTo()?->format('Y-m-d'),
|
||||
'teamers' => $teamers,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The answers a new response starts with. "Busanreise?" is still asked, but preselected from
|
||||
* whether the travel has pickups; the house manager may change it.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function initialAnswers(Destination $destination): array
|
||||
{
|
||||
return [self::BUS_ARRIVAL => [] === $destination->getPickups() ? self::NO : self::YES];
|
||||
}
|
||||
|
||||
private static function teamerLabel(Disposition $disposition): string
|
||||
{
|
||||
return sprintf('%s (%s)', $disposition->getTeamer()?->getFullName(), $disposition->getAssignment()?->getJobProfile()?->getName());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user