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 @@ +
+ {{ participantCount }} +
+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' %}