From 4d51f0334fe4d47bebeeb232151bb22d6c7e9946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 24 Jul 2025 11:59:27 +0200 Subject: [PATCH] wip: booking summary for step 1 --- .../Booking/CreateStep1Controller.php | 29 +++++++++++++++++-- src/Service/BookingService.php | 17 +++++++++++ templates/booking/_room_summary.html.twig | 15 ++++++++++ templates/booking/create_step_1.html.twig | 21 +++++++++----- 4 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 templates/booking/_room_summary.html.twig diff --git a/src/Controller/Booking/CreateStep1Controller.php b/src/Controller/Booking/CreateStep1Controller.php index 5043a97..9f3ca9c 100644 --- a/src/Controller/Booking/CreateStep1Controller.php +++ b/src/Controller/Booking/CreateStep1Controller.php @@ -33,7 +33,7 @@ class CreateStep1Controller extends AbstractController public function index(Request $request): Response { $bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request); - $participantsCount = $this->bookingService->getParticipantsCount($bookingCreateDto->roomSelections, $bookingCreateDto->travel); + $summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto); // Validate step access - allow step 1 or redirect to current step $this->validateStepAccess($bookingCreateDto, 1); @@ -53,8 +53,33 @@ class CreateStep1Controller extends AbstractController return $this->render('booking/create_step_1.html.twig', [ 'bookingCreateDto' => $bookingCreateDto, - 'participantsCount' => $participantsCount, + 'roomSummary' => $summary['selectedRooms'], + 'participantCount' => $summary['participantCount'], 'form' => $form->createView(), ]); } + + /** + * HTMX endpoint for live summary updates in step 1. + */ + #[Route('/bookings/create/room-summary', name: 'app_booking_create_step_1_room_summary', methods: ['POST'])] + public function roomSummary(Request $request): Response + { + $bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request); + + // Process the form to update the DTO with the latest room selection + $form = $this->createForm(BookingCreateStep1Type::class, $bookingCreateDto, [ + 'validation_groups' => false, + ]); + $form->handleRequest($request); + + $this->bookingService->saveBookingCreateDto($request, $bookingCreateDto); + + $summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto); + + return $this->render('booking/_room_summary.html.twig', [ + 'roomSummary' => $summary['selectedRooms'], + 'participantCount' => $summary['participantCount'], + ]); + } } diff --git a/src/Service/BookingService.php b/src/Service/BookingService.php index 7f32b9e..21db560 100644 --- a/src/Service/BookingService.php +++ b/src/Service/BookingService.php @@ -120,4 +120,21 @@ class BookingService return $counts; } + + /** + * Returns a summary of selected rooms and the resulting participant count for a booking. + * + * @param BookingCreateDto $bookingCreateDto + * @return array{selectedRooms: array, participantCount: int} + */ + public function getRoomSummaryAndParticipantCount(BookingCreateDto $bookingCreateDto): array + { + $selectedRooms = $bookingCreateDto->getSelectedRooms(); + $participantCount = $this->getParticipantsCount($selectedRooms, $bookingCreateDto->travel); + + return [ + 'selectedRooms' => $selectedRooms, + 'participantCount' => $participantCount, + ]; + } } diff --git a/templates/booking/_room_summary.html.twig b/templates/booking/_room_summary.html.twig new file mode 100644 index 0000000..aeab0bc --- /dev/null +++ b/templates/booking/_room_summary.html.twig @@ -0,0 +1,15 @@ +
+

Zusammenfassung

+

Zimmer

+ +

Anzahl Teilnehmer

+

+ {{ participantCount }} +

+
\ No newline at end of file diff --git a/templates/booking/create_step_1.html.twig b/templates/booking/create_step_1.html.twig index 3802763..5da51f9 100644 --- a/templates/booking/create_step_1.html.twig +++ b/templates/booking/create_step_1.html.twig @@ -7,7 +7,18 @@

Zimmerauswahl

{{ form_start(form) }} - {{ form_row(form.roomSelections) }} +
+ {% for roomSelection in form.roomSelections %} + {{ form_row(roomSelection, { + 'attr': { + 'hx-post': path('app_booking_create_step_1_room_summary'), + 'hx-target': '#booking-summary', + 'hx-swap': 'outerHTML', + 'hx-trigger': 'change' + } + }) }} + {% endfor %} +
@@ -15,13 +26,7 @@ {{ form_end(form) }}
-

Zusammenfassung

-

Reise: {{ bookingCreateDto.travel.label }}

-

Datum: {{ bookingCreateDto.travel.dateFrom | date('d.m.Y') }} - {{ bookingCreateDto.travel.dateTo | date('d.m.Y') }}

-

Hotel: {{ bookingCreateDto.travel.hotel.name }}

- {% if participantsCount > 0 %} -

Teilnehmerzahl: {{ participantsCount }}

- {% endif %} + {% include 'booking/_room_summary.html.twig' %}
{% endblock %}