97 lines
3.0 KiB
PHP
97 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Form\Model;
|
|
|
|
use App\BusProNet\Constants;
|
|
use App\BusProNet\Model\Booking;
|
|
use App\BusProNet\Model\PersonalData;
|
|
use App\BusProNet\Model\Travel;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
class BookingEditDto implements BookingDtoInterface
|
|
{
|
|
public ?Booking $booking = null;
|
|
public ?Travel $travel = null;
|
|
|
|
/**
|
|
* @var array<int, ParticipantDto>
|
|
*/
|
|
#[Assert\Valid]
|
|
public array $participants = [];
|
|
|
|
public static function fromBooking(Booking $booking, Travel $travel): static
|
|
{
|
|
$instance = new static();
|
|
|
|
$instance->booking = $booking;
|
|
$instance->travel = $travel;
|
|
|
|
foreach ($booking->participants as $index => $participant) {
|
|
/** @var PersonalData $participant */
|
|
$participantData = ParticipantDto::fromPersonalData($participant);
|
|
$participantData->index = $index;
|
|
|
|
$participantData->courses = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_COURSES);
|
|
$participantData->skiPass = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_SKI_PASS);
|
|
$participantData->additionalServices = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_ADDITIONAL);
|
|
$participantData->board = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_BOARD);
|
|
$participantData->rentals = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_RENTALS);
|
|
// Different keys for direction used in booking data (H <=> HIN, R <=> RUECK)!
|
|
$participantData->transportationServiceTo = $booking
|
|
->getTransportationServiceForParticipantAndDirection($index, 'H');
|
|
$participantData->transportationServiceFro = $booking
|
|
->getTransportationServiceForParticipantAndDirection($index, 'R');
|
|
$participantData->pickup = $booking->getPickupForParticipant($index);
|
|
|
|
$instance->participants[$index] = $participantData;
|
|
}
|
|
|
|
return $instance;
|
|
}
|
|
|
|
public function isCanceled(): bool
|
|
{
|
|
return 'S' === $this->booking->status;
|
|
}
|
|
|
|
public function isOption(): bool
|
|
{
|
|
return 'O' === $this->booking->status;
|
|
}
|
|
|
|
public function getParticipants(): array
|
|
{
|
|
return $this->participants;
|
|
}
|
|
|
|
public function getTravel(): Travel
|
|
{
|
|
return $this->travel;
|
|
}
|
|
|
|
public function hasParticipant(int $index): bool
|
|
{
|
|
return isset($this->participants[$index]);
|
|
}
|
|
|
|
public function getParticipant(int $index): ?ParticipantDto
|
|
{
|
|
return $this->participants[$index] ?? null;
|
|
}
|
|
|
|
/**
|
|
* Gets all selected rooms for the booking (edit context).
|
|
*
|
|
* @return array<int, RoomSelectionDto> Always returns an empty array for edit DTOs unless implemented.
|
|
*/
|
|
public function getSelectedRooms(): array
|
|
{
|
|
return [];
|
|
}
|
|
}
|