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;
}
}