getOrCreateBookingCreateDto($this->bookingService, $request); if ($result instanceof Response) { return $result; } $bookingCreateDto = $result; // Get or create baseline snapshot for change detection $oldRoomSelectionSnapshot = $this->bookingService->getOrCreateBaselineSnapshot($request, $bookingCreateDto); $summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto); // Validate step access - allow step 1 or redirect to current step if ($redirect = $this->validateStepAccess($bookingCreateDto, 1)) { return $redirect; } $form = $this->createForm(BookingCreateStep1Type::class, $bookingCreateDto, [ 'validation_groups' => ['booking_create_step_1'], ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { if ($this->bookingService->hasRoomSelectionChanged($oldRoomSelectionSnapshot, $bookingCreateDto)) { $this->bookingService->resetParticipantAssignments($bookingCreateDto); } $bookingCreateDto->currentStep = 2; $this->bookingService->saveBookingCreateDto($request, $bookingCreateDto); // Clear baseline snapshot when moving to step 2 $this->bookingService->clearBaselineSnapshot($request); return $this->redirectToRoute('app_booking_create_step_2'); } $availableRooms = $bookingCreateDto->travel->getAvailableRooms(); $groupedRooms = $this->bookingService->groupRoomsBySelectionType($availableRooms); $groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($summary['selectedRooms'], $availableRooms); return $this->render('booking/create_step_1.html.twig', [ 'bookingCreateDto' => $bookingCreateDto, 'roomSummary' => $summary['selectedRooms'], 'participantCount' => $summary['participantCount'], 'pricingData' => $summary['pricing'], 'form' => $form->createView(), 'groupedRooms' => $groupedRooms, 'groupedSelectedRooms' => $groupedSelectedRooms, ]); } /** * 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 { $result = $this->getOrCreateBookingCreateDto($this->bookingService, $request); if ($result instanceof Response) { return $result; } $bookingCreateDto = $result; // Process the form to update the DTO with the latest room selection $form = $this->createForm(BookingCreateStep1Type::class, $bookingCreateDto, [ 'validation_groups' => false, ]); $form->handleRequest($request); $summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto); $availableRooms = $bookingCreateDto->travel->getAvailableRooms(); $groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($summary['selectedRooms'], $availableRooms); return $this->render('booking/_summary.html.twig', [ 'bookingCreateDto' => $bookingCreateDto, 'roomSummary' => $summary['selectedRooms'], 'participantCount' => $summary['participantCount'], 'pricingData' => $summary['pricing'], 'groupedSelectedRooms' => $groupedSelectedRooms, ]); } }