wip: booking process
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,9 @@ class BookingEditDto
|
||||
public ?Booking $booking = null;
|
||||
public ?Travel $travel = null;
|
||||
|
||||
/**
|
||||
* @var array<int, ParticipantDto>
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
public array $participants = [];
|
||||
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user