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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user