wip: booking process, room assignment
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Booking;
|
||||||
|
|
||||||
|
use App\Form\Model\BookingCreateDto;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides common functionality for booking creation controllers.
|
||||||
|
*
|
||||||
|
* This trait contains shared validation and redirect logic used across
|
||||||
|
* all booking creation steps to ensure consistent behavior and reduce
|
||||||
|
* code duplication.
|
||||||
|
*/
|
||||||
|
trait BookingCreateTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Validates step access and redirects if necessary.
|
||||||
|
*
|
||||||
|
* @param BookingCreateDto $bookingCreateDto
|
||||||
|
* @param int $expectedStep
|
||||||
|
*/
|
||||||
|
private function validateStepAccess(BookingCreateDto $bookingCreateDto, int $expectedStep): void
|
||||||
|
{
|
||||||
|
// Allow access to current step or any previous step
|
||||||
|
if ($expectedStep > $bookingCreateDto->currentStep) {
|
||||||
|
$this->addFlash('error', 'Bitte erst die vorherigen Schritte abschließen.');
|
||||||
|
|
||||||
|
$this->redirectToCurrentStep($bookingCreateDto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects to the current step based on the DTO's currentStep.
|
||||||
|
*
|
||||||
|
* @param BookingCreateDto $bookingCreateDto
|
||||||
|
*/
|
||||||
|
private function redirectToCurrentStep(BookingCreateDto $bookingCreateDto): RedirectResponse
|
||||||
|
{
|
||||||
|
$routeParams = [
|
||||||
|
'date_id' => $bookingCreateDto->travelData->id,
|
||||||
|
'hotel_id' => $bookingCreateDto->travelData->hotelId,
|
||||||
|
];
|
||||||
|
|
||||||
|
$route = match ($bookingCreateDto->currentStep) {
|
||||||
|
1 => 'app_booking_create_step_1',
|
||||||
|
2 => 'app_booking_create_step_2',
|
||||||
|
3 => 'app_booking_create_step_3',
|
||||||
|
default => 'app_booking_create_step_1',
|
||||||
|
};
|
||||||
|
|
||||||
|
return $this->redirectToRoute($route, $routeParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller\Booking;
|
|
||||||
|
|
||||||
use App\Form\BookingCreateStep1Type;
|
|
||||||
use App\Form\BookingCreateStep2Type;
|
|
||||||
use App\Form\Model\ParticipantDto;
|
|
||||||
use App\Service\BookingService;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
|
||||||
|
|
||||||
class CreateController extends AbstractController
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly BookingService $bookingCreateService,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/bookings/create', name: 'app_booking_create_step_1')]
|
|
||||||
public function index(Request $request): Response
|
|
||||||
{
|
|
||||||
$bookingCreateDto = $this->bookingCreateService->getOrCreateBookingCreateDto($request);
|
|
||||||
|
|
||||||
// Validate step access - allow step 1 or redirect to current step
|
|
||||||
$this->validateStepAccess($bookingCreateDto, 1);
|
|
||||||
|
|
||||||
$form = $this->createForm(BookingCreateStep1Type::class, $bookingCreateDto, [
|
|
||||||
'validation_groups' => ['booking_create_step_1'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$form->handleRequest($request);
|
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
|
||||||
$bookingCreateDto->currentStep = 2;
|
|
||||||
$this->bookingCreateService->saveBookingCreateDto($request, $bookingCreateDto);
|
|
||||||
|
|
||||||
return $this->redirectToRoute('app_booking_create_step_2');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render('booking/create_step_1.html.twig', [
|
|
||||||
'bookingCreateDto' => $bookingCreateDto,
|
|
||||||
'form' => $form->createView(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/bookings/create/participants', name: 'app_booking_create_step_2')]
|
|
||||||
public function participants(Request $request): Response
|
|
||||||
{
|
|
||||||
$bookingCreateDto = $this->bookingCreateService->getOrCreateBookingCreateDto($request);
|
|
||||||
|
|
||||||
// Validate step access
|
|
||||||
$this->validateStepAccess($bookingCreateDto, 2);
|
|
||||||
|
|
||||||
// Ensure correct number of participants
|
|
||||||
if ($bookingCreateDto->getParticipantsCount() !== count($bookingCreateDto->participants)) {
|
|
||||||
$participants = $bookingCreateDto->participants;
|
|
||||||
$bookingCreateDto->participants = [];
|
|
||||||
for ($i = 0; $i < $bookingCreateDto->getParticipantsCount(); ++$i) {
|
|
||||||
$bookingCreateDto->participants[] = $participants[$i] ?? new ParticipantDto();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto, [
|
|
||||||
'attr' => ['novalidate' => 'novalidate'],
|
|
||||||
'validation_groups' => ['booking_create_step_2'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$form->handleRequest($request);
|
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
|
||||||
$bookingCreateDto->currentStep = 3;
|
|
||||||
$this->bookingCreateService->saveBookingCreateDto($request, $bookingCreateDto);
|
|
||||||
|
|
||||||
return $this->redirectToRoute('app_booking_create_step_3');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render('booking/create_step_2.html.twig', [
|
|
||||||
'bookingCreateDto' => $bookingCreateDto,
|
|
||||||
'form' => $form->createView(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/bookings/create/confirm', name: 'app_booking_create_step_3')]
|
|
||||||
public function confirm(Request $request): Response
|
|
||||||
{
|
|
||||||
$bookingCreateDto = $this->bookingCreateService->getOrCreateBookingCreateDto($request);
|
|
||||||
|
|
||||||
// Validate step access
|
|
||||||
$this->validateStepAccess($bookingCreateDto, 3);
|
|
||||||
|
|
||||||
return $this->render('booking/confirm.html.twig', [
|
|
||||||
'bookingCreateDto' => $bookingCreateDto,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates step access and redirects if necessary.
|
|
||||||
*
|
|
||||||
* @param \App\Form\Model\BookingCreateDto $bookingCreateDto
|
|
||||||
*/
|
|
||||||
private function validateStepAccess($bookingCreateDto, int $expectedStep): void
|
|
||||||
{
|
|
||||||
// Allow access to current step or any previous step
|
|
||||||
if ($expectedStep > $bookingCreateDto->currentStep) {
|
|
||||||
$this->addFlash('error', 'Bitte erst die vorherigen Schritte abschließen.');
|
|
||||||
|
|
||||||
$this->redirectToCurrentStep($bookingCreateDto);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redirects to the current step based on the DTO's currentStep.
|
|
||||||
*/
|
|
||||||
private function redirectToCurrentStep($bookingCreateDto): void
|
|
||||||
{
|
|
||||||
$routeParams = [
|
|
||||||
'date_id' => $bookingCreateDto->travelData->id,
|
|
||||||
'hotel_id' => $bookingCreateDto->travelData->hotelId,
|
|
||||||
];
|
|
||||||
|
|
||||||
$route = match ($bookingCreateDto->currentStep) {
|
|
||||||
1 => 'app_booking_create_step_1',
|
|
||||||
2 => 'app_booking_create_step_2',
|
|
||||||
3 => 'app_booking_create_step_3',
|
|
||||||
default => 'app_booking_create_step_1',
|
|
||||||
};
|
|
||||||
|
|
||||||
$this->redirectToRoute($route, $routeParams);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Booking;
|
||||||
|
|
||||||
|
use App\Form\BookingCreateStep1Type;
|
||||||
|
use App\Service\BookingService;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the first step of the booking creation process.
|
||||||
|
*
|
||||||
|
* This controller manages room selection functionality where users
|
||||||
|
* choose the types and quantities of rooms for their booking.
|
||||||
|
*/
|
||||||
|
class CreateStep1Controller extends AbstractController
|
||||||
|
{
|
||||||
|
use BookingCreateTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly BookingService $bookingService,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays and processes the room selection form.
|
||||||
|
*/
|
||||||
|
#[Route('/bookings/create', name: 'app_booking_create_step_1')]
|
||||||
|
public function index(Request $request): Response
|
||||||
|
{
|
||||||
|
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
|
||||||
|
$participantsCount = $this->bookingService->getParticipantsCount($bookingCreateDto->roomSelections, $bookingCreateDto->travelData);
|
||||||
|
|
||||||
|
// Validate step access - allow step 1 or redirect to current step
|
||||||
|
$this->validateStepAccess($bookingCreateDto, 1);
|
||||||
|
|
||||||
|
$form = $this->createForm(BookingCreateStep1Type::class, $bookingCreateDto, [
|
||||||
|
'validation_groups' => ['booking_create_step_1'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$bookingCreateDto->currentStep = 2;
|
||||||
|
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_booking_create_step_2');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('booking/create_step_1.html.twig', [
|
||||||
|
'bookingCreateDto' => $bookingCreateDto,
|
||||||
|
'participantsCount' => $participantsCount,
|
||||||
|
'form' => $form->createView(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Booking;
|
||||||
|
|
||||||
|
use App\Form\BookingCreateStep2Type;
|
||||||
|
use App\Form\Model\BookingCreateDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Service\BookingService;
|
||||||
|
use App\Validator\Constraints\Participant;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the second step of the booking creation process.
|
||||||
|
*
|
||||||
|
* This controller manages participant information collection including
|
||||||
|
* dynamic room assignment functionality with HTMX-based form updates.
|
||||||
|
*/
|
||||||
|
class CreateStep2Controller extends AbstractController
|
||||||
|
{
|
||||||
|
use BookingCreateTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly BookingService $bookingService,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays and processes the participant information form.
|
||||||
|
*/
|
||||||
|
#[Route('/bookings/create/participants', name: 'app_booking_create_step_2')]
|
||||||
|
public function participants(Request $request): Response
|
||||||
|
{
|
||||||
|
$bookingCreateDto = $this
|
||||||
|
->bookingService
|
||||||
|
->getOrCreateBookingCreateDto($request);
|
||||||
|
|
||||||
|
// Validate step access
|
||||||
|
$this->validateStepAccess($bookingCreateDto, 2);
|
||||||
|
|
||||||
|
// Ensure correct number of participants
|
||||||
|
$this->ensureCorrectNumberOfParticipants($bookingCreateDto);
|
||||||
|
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
|
||||||
|
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||||
|
|
||||||
|
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto, [
|
||||||
|
'attr' => ['novalidate' => 'novalidate'],
|
||||||
|
'validation_groups' => ['booking_create_step_2'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$bookingCreateDto->currentStep = 3;
|
||||||
|
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_booking_create_step_3');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('booking/create_step_2.html.twig', [
|
||||||
|
'bookingCreateDto' => $bookingCreateDto,
|
||||||
|
'participantsCount' => $participantsCount,
|
||||||
|
'form' => $form->createView(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles HTMX requests for dynamic form updates when room selections change.
|
||||||
|
*/
|
||||||
|
#[Route('/bookings/create/participants/refresh', name: 'app_booking_create_step_2_refresh', methods: ['POST'])]
|
||||||
|
public function refreshParticipantForm(Request $request): Response
|
||||||
|
{
|
||||||
|
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
|
||||||
|
|
||||||
|
// Process form data without validation to capture current state
|
||||||
|
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto, [
|
||||||
|
'attr' => ['novalidate' => 'novalidate'],
|
||||||
|
'validation_groups' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||||
|
|
||||||
|
return $this->renderBlock('booking/create_step_2.html.twig', 'participants_form', [
|
||||||
|
'form' => $form->createView(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getParticipantsCount(BookingCreateDto $bookingCreateDto): int
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->bookingService
|
||||||
|
->getParticipantsCount($bookingCreateDto->roomSelections, $bookingCreateDto->travelData);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function ensureCorrectNumberOfParticipants(BookingCreateDto $bookingCreateDto): void
|
||||||
|
{
|
||||||
|
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
|
||||||
|
|
||||||
|
$participants = $bookingCreateDto->participants;
|
||||||
|
$bookingCreateDto->participants = [];
|
||||||
|
for ($i = 0; $i < $participantsCount; ++$i) {
|
||||||
|
$participant = $participants[$i] ?? new ParticipantDto();
|
||||||
|
$participant->index = $i;
|
||||||
|
$bookingCreateDto->participants[$i] = $participant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Booking;
|
||||||
|
|
||||||
|
use App\Service\BookingService;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the third step of the booking creation process.
|
||||||
|
*
|
||||||
|
* This controller manages the booking confirmation and final review
|
||||||
|
* before completing the booking process.
|
||||||
|
*/
|
||||||
|
class CreateStep3Controller extends AbstractController
|
||||||
|
{
|
||||||
|
use BookingCreateTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly BookingService $bookingCreateService,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the booking confirmation page.
|
||||||
|
*/
|
||||||
|
#[Route('/bookings/create/confirm', name: 'app_booking_create_step_3')]
|
||||||
|
public function confirm(Request $request): Response
|
||||||
|
{
|
||||||
|
$bookingCreateDto = $this->bookingCreateService->getOrCreateBookingCreateDto($request);
|
||||||
|
|
||||||
|
// Validate step access
|
||||||
|
$this->validateStepAccess($bookingCreateDto, 3);
|
||||||
|
|
||||||
|
return $this->render('booking/confirm.html.twig', [
|
||||||
|
'bookingCreateDto' => $bookingCreateDto,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\Form\FormEvent;
|
||||||
|
use Symfony\Component\Form\FormEvents;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
class BookingCreateParticipantType extends AbstractType
|
class BookingCreateParticipantType extends AbstractType
|
||||||
@@ -52,6 +54,16 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
'label' => 'Telefon (mobil)',
|
'label' => 'Telefon (mobil)',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
|
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
|
||||||
|
$data = $event->getData();
|
||||||
|
$form = $event->getForm();
|
||||||
|
|
||||||
|
$form->add('assignedRoomId', ChoiceType::class, [
|
||||||
|
'label' => 'Zimmer',
|
||||||
|
'placeholder' => 'Bitte wählen',
|
||||||
|
'choices' => $options['room_choices'][$data->index],
|
||||||
|
]);
|
||||||
|
})
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +71,7 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
{
|
{
|
||||||
$resolver->setDefaults([
|
$resolver->setDefaults([
|
||||||
'data_class' => ParticipantDto::class,
|
'data_class' => ParticipantDto::class,
|
||||||
|
'room_choices' => [],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,19 +6,123 @@ use App\Form\Model\BookingCreateDto;
|
|||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\Form\FormEvent;
|
||||||
|
use Symfony\Component\Form\FormEvents;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
class BookingCreateStep2Type extends AbstractType
|
class BookingCreateStep2Type extends AbstractType
|
||||||
{
|
{
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
{
|
{
|
||||||
$builder
|
$builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'onPreSetData']);
|
||||||
->add('participants', CollectionType::class, [
|
$builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit']);
|
||||||
'entry_type' => BookingCreateParticipantType::class,
|
}
|
||||||
'allow_add' => false,
|
|
||||||
'allow_delete' => false,
|
public function onPreSetData(FormEvent $event): void
|
||||||
'by_reference' => false,
|
{
|
||||||
]);
|
/** @var BookingCreateDto $bookingCreateDto */
|
||||||
|
$bookingCreateDto = $event->getData();
|
||||||
|
$form = $event->getForm();
|
||||||
|
|
||||||
|
if (null === $bookingCreateDto) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count participants assigned to each room
|
||||||
|
$roomOccupancy = [];
|
||||||
|
foreach ($bookingCreateDto->participants as $participant) {
|
||||||
|
if (null !== $participant->assignedRoomId) {
|
||||||
|
$roomOccupancy[$participant->assignedRoomId] = ($roomOccupancy[$participant->assignedRoomId] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate per-participant room choices
|
||||||
|
$roomChoices = [];
|
||||||
|
foreach ($bookingCreateDto->participants as $index => $participant) {
|
||||||
|
$participantRoomChoices = [];
|
||||||
|
|
||||||
|
foreach ($bookingCreateDto->getSelectedRooms() as $roomSelection) {
|
||||||
|
$currentOccupancy = $roomOccupancy[$roomSelection->roomId] ?? 0;
|
||||||
|
|
||||||
|
// If this participant is already assigned to this room, exclude them from occupancy count
|
||||||
|
$adjustedOccupancy = $currentOccupancy;
|
||||||
|
if ($participant->assignedRoomId === $roomSelection->roomId) {
|
||||||
|
--$adjustedOccupancy;
|
||||||
|
}
|
||||||
|
|
||||||
|
$remainingCapacity = $roomSelection->minPax - $adjustedOccupancy;
|
||||||
|
|
||||||
|
// Include room if it has capacity OR if it's the participant's current assignment
|
||||||
|
if ($remainingCapacity > 0 || $participant->assignedRoomId === $roomSelection->roomId) {
|
||||||
|
$participantRoomChoices[$roomSelection->roomLabel] = $roomSelection->roomId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$roomChoices[$index] = $participantRoomChoices;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a custom form type that handles per-participant room choices
|
||||||
|
$form->add('participants', CollectionType::class, [
|
||||||
|
'entry_type' => BookingCreateParticipantType::class,
|
||||||
|
'allow_add' => false,
|
||||||
|
'allow_delete' => false,
|
||||||
|
'by_reference' => false,
|
||||||
|
'entry_options' => [
|
||||||
|
'room_choices' => $roomChoices,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPreSubmit(FormEvent $event): void
|
||||||
|
{
|
||||||
|
$data = $event->getData();
|
||||||
|
$form = $event->getForm();
|
||||||
|
/** @var BookingCreateDto $bookingCreateDto */
|
||||||
|
$bookingCreateDto = $form->getData();
|
||||||
|
|
||||||
|
$roomOccupancy = [];
|
||||||
|
foreach ($data['participants'] as $participant) {
|
||||||
|
if (null !== $participant['assignedRoomId']) {
|
||||||
|
$assignedRoomId = (int) $participant['assignedRoomId'];
|
||||||
|
$roomOccupancy[$assignedRoomId] = ($roomOccupancy[$assignedRoomId] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$roomChoices = [];
|
||||||
|
foreach ($data['participants'] as $index => $participant) {
|
||||||
|
$participantRoomChoices = [];
|
||||||
|
$assignedRoomId = (int) $participant['assignedRoomId'];
|
||||||
|
|
||||||
|
foreach ($bookingCreateDto->getSelectedRooms() as $roomSelection) {
|
||||||
|
$currentOccupancy = $roomOccupancy[$roomSelection->roomId] ?? 0;
|
||||||
|
|
||||||
|
// If this participant is already assigned to this room, exclude them from occupancy count
|
||||||
|
$adjustedOccupancy = $currentOccupancy;
|
||||||
|
if ($assignedRoomId === $roomSelection->roomId) {
|
||||||
|
--$adjustedOccupancy;
|
||||||
|
}
|
||||||
|
|
||||||
|
$remainingCapacity = $roomSelection->minPax - $adjustedOccupancy;
|
||||||
|
|
||||||
|
// Include room if it has capacity OR if it's the participant's current assignment
|
||||||
|
if ($remainingCapacity > 0 || $assignedRoomId === $roomSelection->roomId) {
|
||||||
|
$participantRoomChoices[$roomSelection->roomLabel] = $roomSelection->roomId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$roomChoices[$index] = $participantRoomChoices;
|
||||||
|
}
|
||||||
|
$form->remove('participants');
|
||||||
|
$form->add('participants', CollectionType::class, [
|
||||||
|
'entry_type' => BookingCreateParticipantType::class,
|
||||||
|
'allow_add' => false,
|
||||||
|
'allow_delete' => false,
|
||||||
|
'by_reference' => false,
|
||||||
|
'entry_options' => [
|
||||||
|
'room_choices' => $roomChoices,
|
||||||
|
],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver): void
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
|||||||
@@ -4,16 +4,15 @@ namespace App\Form\Model;
|
|||||||
|
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
||||||
|
|
||||||
class BookingCreateDto
|
class BookingCreateDto
|
||||||
{
|
{
|
||||||
public int $currentStep = 1;
|
public int $currentStep = 1;
|
||||||
|
|
||||||
#[Assert\Valid]
|
|
||||||
/**
|
/**
|
||||||
* @var array<int, RoomSelectionDto>
|
* @var array<int, RoomSelectionDto>
|
||||||
*/
|
*/
|
||||||
|
#[Assert\Valid]
|
||||||
public array $roomSelections = [];
|
public array $roomSelections = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,42 +25,9 @@ class BookingCreateDto
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Assert\Callback(groups: ['booking_create_step_1'])]
|
/**
|
||||||
public function assertValidRoomSelections(ExecutionContextInterface $context): void
|
* @return array<int, RoomSelectionDto>
|
||||||
{
|
*/
|
||||||
$participantsCount = $this->getParticipantsCount();
|
|
||||||
$selectedContingent = 0;
|
|
||||||
|
|
||||||
foreach ($this->roomSelections as $roomSelection) {
|
|
||||||
$selectedContingent += $roomSelection->quantity * $roomSelection->minPax;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 === $selectedContingent) {
|
|
||||||
$context->buildViolation('Bitte mindestens ein Zimmer auswählen.')
|
|
||||||
->atPath('roomSelections')
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($selectedContingent !== $participantsCount) {
|
|
||||||
$context->buildViolation('Die ausgewählten Zimmer passen nicht zur Teilnehmerzahl.')
|
|
||||||
->atPath('roomSelections')
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getParticipantsCount(): int
|
|
||||||
{
|
|
||||||
$participantsCount = 0;
|
|
||||||
$rooms = $this->travelData->getAvailableRooms();
|
|
||||||
|
|
||||||
foreach ($this->roomSelections as $roomSelection) {
|
|
||||||
$room = $rooms[$roomSelection->roomId];
|
|
||||||
$participantsCount += $room->minPax * $roomSelection->quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $participantsCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSelectedRooms(): array
|
public function getSelectedRooms(): array
|
||||||
{
|
{
|
||||||
return array_filter($this->roomSelections, function (RoomSelectionDto $roomSelection) {
|
return array_filter($this->roomSelections, function (RoomSelectionDto $roomSelection) {
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ class ParticipantDto
|
|||||||
public ?string $email = null;
|
public ?string $email = null;
|
||||||
|
|
||||||
public ?string $mobile = null;
|
public ?string $mobile = null;
|
||||||
|
|
||||||
|
#[Assert\NotNull(message: 'Bitte ein Zimmer auswählen', groups: ['booking_create_step_2'])]
|
||||||
|
public ?int $assignedRoomId = null;
|
||||||
|
|
||||||
public array $courses = [];
|
public array $courses = [];
|
||||||
public array $additionalServices = [];
|
public array $additionalServices = [];
|
||||||
public array $skiPass = [];
|
public array $skiPass = [];
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\BusProNet\Model\Room;
|
use App\BusProNet\Model\Room;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
use App\Form\Model\BookingCreateDto;
|
use App\Form\Model\BookingCreateDto;
|
||||||
use App\Form\Model\RoomSelectionDto;
|
use App\Form\Model\RoomSelectionDto;
|
||||||
use App\Service\TravelDataService;
|
use App\Service\TravelDataService;
|
||||||
@@ -88,4 +89,17 @@ class BookingService
|
|||||||
|
|
||||||
return array_map('intval', array_filter($rooms, 'strlen'));
|
return array_map('intval', array_filter($rooms, 'strlen'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParticipantsCount(array $roomSelections, Travel $travelData): int
|
||||||
|
{
|
||||||
|
$participantsCount = 0;
|
||||||
|
$rooms = $travelData->getAvailableRooms();
|
||||||
|
|
||||||
|
foreach ($roomSelections as $roomSelection) {
|
||||||
|
$room = $rooms[$roomSelection->roomId];
|
||||||
|
$participantsCount += $room->minPax * $roomSelection->quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $participantsCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
<p>Reise: {{ bookingCreateDto.travelData.label }}</p>
|
<p>Reise: {{ bookingCreateDto.travelData.label }}</p>
|
||||||
<p>Datum: {{ bookingCreateDto.travelData.dateFrom | date('d.m.Y') }} - {{ bookingCreateDto.travelData.dateTo | date('d.m.Y') }}</p>
|
<p>Datum: {{ bookingCreateDto.travelData.dateFrom | date('d.m.Y') }} - {{ bookingCreateDto.travelData.dateTo | date('d.m.Y') }}</p>
|
||||||
<p>Hotel: {{ bookingCreateDto.travelData.hotel.name }}</p>
|
<p>Hotel: {{ bookingCreateDto.travelData.hotel.name }}</p>
|
||||||
{% if bookingCreateDto.participantsCount > 0 %}
|
{% if participantsCount > 0 %}
|
||||||
<p>Teilnehmerzahl: {{ bookingCreateDto.participantsCount }}</p>
|
<p>Teilnehmerzahl: {{ participantsCount }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,26 +8,38 @@
|
|||||||
<h2>Teilnehmer</h2>
|
<h2>Teilnehmer</h2>
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
{% do form.participants.setRendered %}
|
{% do form.participants.setRendered %}
|
||||||
<div class="space-y-8 pb-8">
|
{% block participants_form %}
|
||||||
{% for participant in form.participants %}
|
<div id="participants-form" class="space-y-8 pb-8">
|
||||||
<fieldset class="border rounded-md p-8 pt-4">
|
{% for participant in form.participants %}
|
||||||
<legend class="font-bold text-xl px-2">
|
<fieldset class="border rounded-md p-8 pt-4">
|
||||||
Teilnehmer:in {{ loop.index }}
|
<legend class="font-bold text-xl px-2">
|
||||||
</legend>
|
Teilnehmer:in {{ loop.index }}
|
||||||
<div class="grid grid-cols-2 gap-4 pb-4">
|
</legend>
|
||||||
{{ form_row(participant.firstName) }}
|
<div class="grid grid-cols-2 gap-4 pb-4">
|
||||||
{{ form_row(participant.lastName) }}
|
{{ form_row(participant.firstName) }}
|
||||||
{{ form_row(participant.dateOfBirth) }}
|
{{ form_row(participant.lastName) }}
|
||||||
{{ form_row(participant.gender) }}
|
{{ form_row(participant.dateOfBirth) }}
|
||||||
{{ form_row(participant.nationality) }}
|
{{ form_row(participant.gender) }}
|
||||||
</div>
|
{{ form_row(participant.nationality) }}
|
||||||
<div class="grid grid-cols-2 gap-4">
|
</div>
|
||||||
{{ form_row(participant.email) }}
|
<div class="grid grid-cols-2 gap-4">
|
||||||
{{ form_row(participant.mobile) }}
|
{{ form_row(participant.email) }}
|
||||||
</div>
|
{{ form_row(participant.mobile) }}
|
||||||
</fieldset>
|
</div>
|
||||||
{% endfor %}
|
<div class="grid grid-cols-1 gap-4 pt-4">
|
||||||
</div>
|
{{ form_row(participant.assignedRoomId, {
|
||||||
|
'attr': {
|
||||||
|
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||||
|
'hx-target': '#participants-form',
|
||||||
|
'hx-select': '#participants-form',
|
||||||
|
'hx-swap': 'outerHTML'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<a href="{{ path('app_booking_create_step_1') }}" class="button bg-button bg-button--secondary">Zurück</a>
|
<a href="{{ path('app_booking_create_step_1') }}" class="button bg-button bg-button--secondary">Zurück</a>
|
||||||
<button type="submit" class="button bg-button bg-button--secondary">Weiter</button>
|
<button type="submit" class="button bg-button bg-button--secondary">Weiter</button>
|
||||||
@@ -55,12 +67,12 @@
|
|||||||
<p>
|
<p>
|
||||||
{{ bookingCreateDto.travelData.hotel.name }}
|
{{ bookingCreateDto.travelData.hotel.name }}
|
||||||
</p>
|
</p>
|
||||||
{% if bookingCreateDto.participantsCount > 0 %}
|
{% if participantsCount > 0 %}
|
||||||
<h4>
|
<h4>
|
||||||
Anzahl Teilnehmer
|
Anzahl Teilnehmer
|
||||||
</h4>
|
</h4>
|
||||||
<p>
|
<p>
|
||||||
{{ bookingCreateDto.participantsCount }}
|
{{ participantsCount }}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h4>
|
<h4>
|
||||||
|
|||||||
Reference in New Issue
Block a user