Files
myep/src/Controller/Groups/AbstractAccommodationController.php
T

53 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Controller\Groups;
use App\Exception\AccommodationSessionNotFoundException;
use App\Form\Model\AccommodationBookingDto;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
abstract class AbstractAccommodationController extends AbstractController
{
protected function validateStepAccess(AccommodationBookingDto $dto, int $expectedStep): ?RedirectResponse
{
if ($expectedStep > $dto->currentStep) {
$this->addFlash('error', 'Bitte erst die vorherigen Schritte abschließen.');
return $this->redirectToCurrentStep($dto);
}
return null;
}
protected function createFailureResponse(\Throwable $exception, bool $htmx): Response
{
if ($htmx) {
return new Response('', 400);
}
$message = $exception instanceof AccommodationSessionNotFoundException
? 'Deine Sitzung ist abgelaufen. Bitte starte die Anfrage erneut.'
: 'Die Anfrage konnte nicht geladen werden.';
$this->addFlash('error', $message);
return $this->redirectToRoute('app_groups_booking_error');
}
private function redirectToCurrentStep(AccommodationBookingDto $dto): RedirectResponse
{
$route = match ($dto->currentStep) {
2 => 'app_groups_booking_step_2',
3 => 'app_groups_booking_step_3',
4 => 'app_groups_booking_step_4',
default => 'app_groups_booking_step_1',
};
return $this->redirectToRoute($route);
}
}