diff --git a/assets/styles/_components.css b/assets/styles/_components.css index 1439459..b4b1a9d 100644 --- a/assets/styles/_components.css +++ b/assets/styles/_components.css @@ -7,3 +7,4 @@ @import "./components/tooltip.css"; @import "./components/timeline.css"; @import "./components/mail-body.css"; +@import "./components/questionnaire.css"; diff --git a/assets/styles/components/questionnaire.css b/assets/styles/components/questionnaire.css new file mode 100644 index 0000000..fade71d --- /dev/null +++ b/assets/styles/components/questionnaire.css @@ -0,0 +1,9 @@ +/* + * A questionnaire "pick" (App\Form\Questionnaire\AbstractPickType): a checkbox, and below it the + * fields that only matter once it is ticked (templates/forms.html.twig, questionnaire_pick_*). They stay in the form, and are submitted, while + * hidden; the form type drops them. The child combinator keeps a nested pick (a guiding type + * inside a teamer) from answering for its parent. + */ +.questionnaire-pick:not(:has(> .questionnaire-pick__head input:checked)) > .questionnaire-pick__body { + display: none; +} diff --git a/config/questionnaires/house_manager_feedback.yaml b/config/questionnaires/house_manager_feedback.yaml new file mode 100644 index 0000000..b26bab7 --- /dev/null +++ b/config/questionnaires/house_manager_feedback.yaml @@ -0,0 +1,159 @@ +# Questionnaire the house manager fills in once per travel (Destination) after it has ended. +# +# From the stakeholder briefing of 2026-11-11; the plan is .ddev/plans/house-manager-questionnaire.md. +# What the travel already knows (product, house, dates, teamers) is not asked: it is snapshotted +# into the response's context. Its last point, "Bewerte dein Wochenteam", is not a question: the +# page lists the travel's teamers after the form, each linking to the existing rating form. +# +# Labels, help texts, section titles and option labels may be edited in place. Renaming or +# removing a question or option key, or changing a type, needs a new version: copy this file to +# house_manager_feedback.v1.yaml first, then bump `version` here. Submitted answers are keyed by it. +# +# Parsed and validated by App\Config\QuestionnaireCatalog; QuestionnaireCatalogTest builds it. +# +# Besides the types of teamer_feedback.yaml, this one uses the house manager's widgets, whose +# options are what can be picked per teamer or item: +# teamer_guidings (guiding types; count and participants each), teamer_courses (course types; +# days × hours per day and the days it took place) and programme (items with their participants, +# plus "Sonstiges" as free text; "other" is reserved for it). + +key: house_manager_feedback +version: 1 +title: "Hausleitungsfeedback" +description: |- + Dein Feedback zur Reise. Du kannst den Fragebogen jederzeit als Entwurf speichern und später + weiter ausfüllen. + +sections: + - key: arrival + title: "Gruppe & Anreise" + questions: + - key: groups_in_house + label: "Gruppe(n) im Haus?" + type: choice + required: true + options: &yes_no + - { key: ja, label: "Ja" } + - { key: nein, label: "Nein" } + + - key: bus_arrival + label: "Busanreise?" + type: choice + required: true + options: *yes_no + + - key: bus_late + label: "Unpünktlich?" + type: choice + required: true + options: *yes_no + show_if: { question: bus_arrival, equals: ja } + + - key: bus_arrival_time + label: "Wann kam der Bus?" + type: text + required: true + show_if: { question: bus_late, equals: ja } + + - key: no_shows + label: "Gab es No-Shows?" + type: choice + required: true + options: *yes_no + + - key: unused_services + label: "Wurden Leistungen nicht bezogen?" + type: choice + required: true + options: *yes_no + + - key: unused_services_details + label: "Bitte trage hier den Vorfall des Kunden mit VG-Nummer ein:" + type: textarea + required: true + show_if: { question: unused_services, equals: ja } + + - key: guidings_and_courses + title: "Guidings & Kurse" + questions: + - key: guidings + label: "Gab es Guidings?" + type: choice + required: true + options: *yes_no + + - key: guiding_teamers + label: "Wer hat das Guiding gegeben?" + help: "Bitte wähle aus, mehrere sind möglich." + type: teamer_guidings + required: true + options: + - { key: half_day, label: "Halbtagesguiding" } + - { key: full_day, label: "Ganztagesguiding" } + show_if: { question: guidings, equals: ja } + + - key: courses + label: "Gab es Kurse?" + type: choice + required: true + options: *yes_no + + - key: course_teamers + label: "Wer hat welchen Kurs gegeben?" + help: "Bitte wähle aus, mehrere sind möglich." + type: teamer_courses + required: true + options: + - { key: ski_beginner, label: "Ski-Anfänger:innen-Kurs" } + - { key: ski_advanced, label: "Ski-Fortgeschrittenen-Kurs" } + - { key: snowboard_beginner, label: "Snowboard-Anfänger:innen-Kurs" } + - { key: snowboard_advanced, label: "Snowboard-Fortgeschrittenen-Kurs" } + show_if: { question: courses, equals: ja } + + - key: activities + title: "Programm" + questions: + - key: programme_deviations + label: "Gab es Besonderheiten/Abweichungen vom Beispiel-Programm, welches im Reisebriefing verschickt wurde?" + type: choice + required: true + options: *yes_no + + - key: programme_deviations_details + label: "Bitte beschreibe, was genau." + type: textarea + required: true + show_if: { question: programme_deviations, equals: ja } + + - key: programme + label: "Welches Programm hat stattgefunden?" + help: "Mehrere sind möglich." + type: programme + required: true + options: + - { key: village_check, label: "Dorfcheck am Anreisetag" } + - { key: mulled_wine_party, label: "Glühweinparty" } + - { key: slope_snack, label: "Pistensnack" } + - { key: hut_evening, label: "Hüttenabend" } + - { key: torch_hike, label: "Fackelwanderung" } + - { key: toboggan_evening, label: "Rodelabend" } + - { key: witches_cauldron, label: "Hexenkessel" } + + - key: closing + title: "Vorkommnisse & Gruppe" + questions: + - key: incidents + label: "Gab es besondere Vorkommnisse, z. B. schwerwiegende Verletzungen oder Beschwerden?" + type: choice + required: true + options: *yes_no + + - key: incidents_details + label: "Was ist passiert?" + type: textarea + required: true + show_if: { question: incidents, equals: ja } + + - key: group_feedback + label: "Feedback zur Gruppe" + type: textarea diff --git a/config/services.yaml b/config/services.yaml index 41dbce8..fd98f0a 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -127,6 +127,12 @@ parameters: # Without a cutoff every past placement would be pending at once. questionnaire_go_live: '2026-11-10' + # The house manager's questionnaire about a travel (config/questionnaires/house_manager_feedback.yaml) + # is offered for travels ending on or after this day (Y-m-d), and keeps the travel pending - in + # the list, on the dashboard and in the daily reminder - until submitted. Teamer ratings stay + # pending as before, whatever this date. + house_manager_questionnaire_go_live: '2026-11-11' + # How far ahead of the destination's first travel day a season assignment's checklist # entries fall due. A relative date expression, applied to destination.dateFrom, and the # single definition of both deadlines: the first is this offset, the second defaults to @@ -191,6 +197,7 @@ services: # Likewise parsed on demand, by App\Config\QuestionnaireCatalog. $questionnaireDir: '%kernel.project_dir%/config/questionnaires' $questionnaireGoLive: '%questionnaire_go_live%' + $houseManagerQuestionnaireGoLive: '%house_manager_questionnaire_go_live%' $mailingBusTransport: '%mailing_bus_transport%' $seasonStart: '%season_start%' $seasonEnd: '%season_end%' @@ -518,3 +525,4 @@ when@test: mailing_bus_transport: 'sync' # the questionnaire tests need it offered; any day before the placements they create questionnaire_go_live: '2026-01-01' + house_manager_questionnaire_go_live: '2026-01-01' diff --git a/migrations/Version20261111100000.php b/migrations/Version20261111100000.php new file mode 100644 index 0000000..52c77a5 --- /dev/null +++ b/migrations/Version20261111100000.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE questionnaire_response ADD destination_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE questionnaire_response ADD CONSTRAINT FK_A0400276816C6140 FOREIGN KEY (destination_id) REFERENCES destination (id) ON DELETE CASCADE'); + $this->addSql('CREATE INDEX IDX_A0400276816C6140 ON questionnaire_response (destination_id)'); + $this->addSql('CREATE UNIQUE INDEX questionnaire_destination ON questionnaire_response (questionnaire, destination_id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP INDEX questionnaire_destination ON questionnaire_response'); + $this->addSql('ALTER TABLE questionnaire_response DROP FOREIGN KEY FK_A0400276816C6140'); + $this->addSql('DROP INDEX IDX_A0400276816C6140 ON questionnaire_response'); + $this->addSql('ALTER TABLE questionnaire_response DROP destination_id'); + } +} diff --git a/src/Config/QuestionnaireCatalog.php b/src/Config/QuestionnaireCatalog.php index 80c2cc2..38c2207 100644 --- a/src/Config/QuestionnaireCatalog.php +++ b/src/Config/QuestionnaireCatalog.php @@ -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)); } /** diff --git a/src/Controller/Administrative/Questionnaire/DetailController.php b/src/Controller/Administrative/Questionnaire/DetailController.php index 1716ef5..d0bd201 100644 --- a/src/Controller/Administrative/Questionnaire/DetailController.php +++ b/src/Controller/Administrative/Questionnaire/DetailController.php @@ -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(), ); diff --git a/src/Controller/Administrative/Questionnaire/HouseManagerTestController.php b/src/Controller/Administrative/Questionnaire/HouseManagerTestController.php new file mode 100644 index 0000000..7172f7e --- /dev/null +++ b/src/Controller/Administrative/Questionnaire/HouseManagerTestController.php @@ -0,0 +1,76 @@ + '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'), + ]); + } +} diff --git a/src/Controller/Administrative/Questionnaire/IndexController.php b/src/Controller/Administrative/Questionnaire/IndexController.php index 19b9057..c57cbb6 100644 --- a/src/Controller/Administrative/Questionnaire/IndexController.php +++ b/src/Controller/Administrative/Questionnaire/IndexController.php @@ -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 { diff --git a/src/Controller/HouseManager/Feedback/IndexController.php b/src/Controller/HouseManager/Feedback/IndexController.php index f2d2e75..a08da68 100644 --- a/src/Controller/HouseManager/Feedback/IndexController.php +++ b/src/Controller/HouseManager/Feedback/IndexController.php @@ -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, ]); } } diff --git a/src/Controller/HouseManager/IndexController.php b/src/Controller/HouseManager/IndexController.php index a57318e..5fbd185 100644 --- a/src/Controller/HouseManager/IndexController.php +++ b/src/Controller/HouseManager/IndexController.php @@ -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, ]); } } diff --git a/src/Controller/HouseManager/Questionnaire/DetailController.php b/src/Controller/HouseManager/Questionnaire/DetailController.php new file mode 100644 index 0000000..65fd029 --- /dev/null +++ b/src/Controller/HouseManager/Questionnaire/DetailController.php @@ -0,0 +1,49 @@ + 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, + ]); + } +} diff --git a/src/Controller/HouseManager/Questionnaire/EditController.php b/src/Controller/HouseManager/Questionnaire/EditController.php new file mode 100644 index 0000000..df19af9 --- /dev/null +++ b/src/Controller/HouseManager/Questionnaire/EditController.php @@ -0,0 +1,104 @@ + 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(), + ]); + } +} diff --git a/src/Entity/QuestionnaireResponse.php b/src/Entity/QuestionnaireResponse.php index 4024056..323d490 100644 --- a/src/Entity/QuestionnaireResponse.php +++ b/src/Entity/QuestionnaireResponse.php @@ -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); diff --git a/src/Enum/QuestionType.php b/src/Enum/QuestionType.php index c2ab1ac..b5f18bc 100644 --- a/src/Enum/QuestionType.php +++ b/src/Enum/QuestionType.php @@ -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; } } diff --git a/src/Form/Questionnaire/AbstractPickType.php b/src/Form/Questionnaire/AbstractPickType.php new file mode 100644 index 0000000..33e0cc2 --- /dev/null +++ b/src/Form/Questionnaire/AbstractPickType.php @@ -0,0 +1,101 @@ +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 $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.')); + } + } + } +} diff --git a/src/Form/Questionnaire/AbstractTeamerPickType.php b/src/Form/Questionnaire/AbstractTeamerPickType.php new file mode 100644 index 0000000..d8f58d5 --- /dev/null +++ b/src/Form/Questionnaire/AbstractTeamerPickType.php @@ -0,0 +1,120 @@ + 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, '$.[*]' ...) and groups by any of its fields: + * [{disposition: , type: