55 lines
2.2 KiB
PHP
55 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Form\Model;
|
|
|
|
use App\BusProNet\Model\Booking;
|
|
use App\BusProNet\Model\PersonalData;
|
|
use App\BusProNet\Model\Service;
|
|
use App\BusProNet\Model\Travel;
|
|
use App\Validator\Constraints as AppAssert;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
#[Assert\GroupSequence(['BookingData', 'Api'])]
|
|
#[AppAssert\Booking(groups:['Api'])]
|
|
class BookingData
|
|
{
|
|
public ?Booking $booking = null;
|
|
public ?Travel $travel = null;
|
|
|
|
#[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 = ParticipantData::fromPersonalData($participant);
|
|
$participantData->index = $index;
|
|
$participantData->courses = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_COURSES);
|
|
$participantData->skiPass = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_SKI_PASS);
|
|
$participantData->additionalServices = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_ADDITIONAL);
|
|
$participantData->board = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_BOARD);
|
|
$participantData->rentals = $booking
|
|
->getAdditionalServicesForParticipantByGroup($index, Service::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;
|
|
}
|
|
} |