wip: booking process

This commit is contained in:
Björn Fromme
2025-07-16 11:55:49 +02:00
parent bef18971c3
commit 47faa6b08e
26 changed files with 1123 additions and 271 deletions
+64
View File
@@ -0,0 +1,64 @@
<?php
namespace App\Form\Model;
use App\BusProNet\Model\Travel;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class BookingCreateDto
{
public int $currentStep = 1;
#[Assert\Valid]
/**
* @var array<int, RoomSelectionDto>
*/
public array $roomSelections = [];
/**
* @var array<int, ParticipantDto>
*/
#[Assert\Valid]
public array $participants = [];
public function __construct(public Travel $travelData, public int $hotelId)
{
}
#[Assert\Callback]
public function assertValidRoomSelections(ExecutionContextInterface $context): void
{
$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;
}
}
+3
View File
@@ -13,6 +13,9 @@ class BookingEditDto
public ?Booking $booking = null;
public ?Travel $travel = null;
/**
* @var array<int, ParticipantDto>
*/
#[Assert\Valid]
public array $participants = [];
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Form\Model;
use Symfony\Component\Validator\Constraints as Assert;
class RoomSelectionDto
{
#[Assert\NotNull(message: 'Bitte eine Zimmerkategorie auswählen')]
public ?int $roomId = null;
public ?string $roomLabel = null;
public ?int $quantity = null;
public int $maxQuantity = 100;
public int $minPax = 0;
public function getType(): string
{
if (1 === preg_match('/bett/i', $this->roomLabel)) {
return 'by_pax';
}
return 'by_room';
}
}