wip: selectable bus exits
This commit is contained in:
@@ -12,7 +12,7 @@ class BookingDataProcessor
|
||||
$travelData = $formData->travel;
|
||||
|
||||
// Reset mappings
|
||||
foreach ([...$bookingData->additionalServices, ...$bookingData->transportationServices, ...$bookingData->pickups] as $service) {
|
||||
foreach ([...$bookingData->additionalServices, ...$bookingData->transportationServices, ...$bookingData->pickupsTo, ...$bookingData->pickupsFro] as $service) {
|
||||
$service->mapping = [];
|
||||
}
|
||||
// Update mappings, add services and pickups
|
||||
@@ -40,11 +40,17 @@ class BookingDataProcessor
|
||||
}
|
||||
$bookingData->transportationServices[$service->id]->mapping[] = $participant->index;
|
||||
}
|
||||
if ('BUS' === $participant->transportationServiceTo->subType && null !== $selectedPickup = $participant->pickup) {
|
||||
if (false === isset($bookingData->pickups[$selectedPickup->id])) {
|
||||
$bookingData->pickups[$selectedPickup->id] = $selectedPickup;
|
||||
if ('BUS' === $participant->transportationServiceTo->subType && null !== $selectedPickup = $participant->pickupTo) {
|
||||
if (false === isset($bookingData->pickupsTo[$selectedPickup->id])) {
|
||||
$bookingData->pickupsTo[$selectedPickup->id] = $selectedPickup;
|
||||
}
|
||||
$bookingData->pickups[$selectedPickup->id]->mapping[] = $participant->index;
|
||||
$bookingData->pickupsTo[$selectedPickup->id]->mapping[] = $participant->index;
|
||||
}
|
||||
if ('BUS' === $participant->transportationServiceFro->subType && null !== $selectedPickup = $participant->pickupFro) {
|
||||
if (false === isset($bookingData->pickupsFro[$selectedPickup->id])) {
|
||||
$bookingData->pickupsFro[$selectedPickup->id] = $selectedPickup;
|
||||
}
|
||||
$bookingData->pickupsFro[$selectedPickup->id]->mapping[] = $participant->index;
|
||||
}
|
||||
}
|
||||
// Remove services/pickups with empty mappings
|
||||
@@ -58,9 +64,14 @@ class BookingDataProcessor
|
||||
unset($bookingData->transportationServices[$service->id]);
|
||||
}
|
||||
}
|
||||
foreach ($bookingData->pickups as $pickup) {
|
||||
foreach ($bookingData->pickupsTo as $pickup) {
|
||||
if (0 === count($pickup->mapping)) {
|
||||
unset($bookingData->pickups[$pickup->id]);
|
||||
unset($bookingData->pickupsTo[$pickup->id]);
|
||||
}
|
||||
}
|
||||
foreach ($bookingData->pickupsFro as $pickup) {
|
||||
if (0 === count($pickup->mapping)) {
|
||||
unset($bookingData->pickupsFro[$pickup->id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,9 +158,9 @@ class BookingDataProcessor
|
||||
];
|
||||
}
|
||||
|
||||
if (0 < count($bookingData->pickups)) {
|
||||
if (0 < count($bookingData->pickupsTo)) {
|
||||
$payload['zustiege']['zustieg'] = [];
|
||||
foreach ($bookingData->pickups as $pickup) {
|
||||
foreach ($bookingData->pickupsTo as $pickup) {
|
||||
$payload['zustiege']['zustieg'][] = [
|
||||
'@idzustieg' => $pickup->id,
|
||||
'@anzahl' => count($pickup->mapping),
|
||||
@@ -158,6 +169,17 @@ class BookingDataProcessor
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < count($bookingData->pickupsFro)) {
|
||||
$payload['zustiege_rueck']['zustieg_rueck'] = [];
|
||||
foreach ($bookingData->pickupsFro as $pickup) {
|
||||
$payload['zustiege_rueck']['zustieg_rueck'][] = [
|
||||
'@idzustieg' => $pickup->id,
|
||||
'@anzahl' => count($pickup->mapping),
|
||||
'@zuordnung' => implode(',', $pickup->mapping),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ class Booking
|
||||
public array $transportationServices = [];
|
||||
public array $additionalServices = [];
|
||||
public array $rooms = [];
|
||||
public array $pickups = [];
|
||||
public array $pickupsTo = [];
|
||||
public array $pickupsFro = [];
|
||||
public array $surcharges = [];
|
||||
public ?int $invoiceNumber = null;
|
||||
public ?float $totalPrice = null;
|
||||
@@ -75,9 +76,20 @@ class Booking
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPickupForParticipant(int $participantIndex): ?Pickup
|
||||
public function getPickupToForParticipant(int $participantIndex): ?Pickup
|
||||
{
|
||||
foreach ($this->pickups as $pickup) {
|
||||
foreach ($this->pickupsTo as $pickup) {
|
||||
if (in_array($participantIndex, $pickup->mapping)) {
|
||||
return $pickup;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPickupFroForParticipant(int $participantIndex): ?Pickup
|
||||
{
|
||||
foreach ($this->pickupsFro as $pickup) {
|
||||
if (in_array($participantIndex, $pickup->mapping)) {
|
||||
return $pickup;
|
||||
}
|
||||
@@ -132,4 +144,4 @@ class Booking
|
||||
{
|
||||
return $this->travelDate > new \DateTimeImmutable() && false === in_array($this->status, ['S', 'U']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,10 @@ class Travel
|
||||
public bool $transportationServicesMutable = true;
|
||||
|
||||
#[Groups(['api:single'])]
|
||||
public array $pickups = [];
|
||||
public array $pickupsTo = [];
|
||||
|
||||
#[Groups(['api:single'])]
|
||||
public array $pickupsFro = [];
|
||||
|
||||
#[Groups(['api:single'])]
|
||||
public bool $pickupsMutable = true;
|
||||
@@ -112,4 +115,4 @@ class Travel
|
||||
|
||||
return $services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,15 @@ class PickupLoader extends AbstractLoader
|
||||
|
||||
public function patchPickupsDetails(Travel $travel): void
|
||||
{
|
||||
foreach ($travel->pickups as $pickupId => $pickup) {
|
||||
foreach ($travel->pickupsTo as $pickupId => $pickup) {
|
||||
$pickupData = $this->loadById($pickupId);
|
||||
|
||||
$pickup->code = $pickupData->code;
|
||||
$pickup->postalCode = $pickupData->postalCode;
|
||||
$pickup->city = $pickupData->city;
|
||||
$pickup->street = $pickupData->street;
|
||||
}
|
||||
foreach ($travel->pickupsFro as $pickupId => $pickup) {
|
||||
$pickupData = $this->loadById($pickupId);
|
||||
|
||||
$pickup->code = $pickupData->code;
|
||||
@@ -63,4 +71,4 @@ class PickupLoader extends AbstractLoader
|
||||
$pickup->street = $pickupData->street;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,8 @@ class TravelLoader extends AbstractLoader
|
||||
$travel->transportationServices = $this
|
||||
->getTransportationServices($node->filterXPath('//lei_befoerderung/leistung'));
|
||||
$travel->rooms = $this->getRooms($hotelNode);
|
||||
$travel->pickups = $this->getPickups($node->filterXPath('//zustiege/zustieg'));
|
||||
$travel->pickupsTo = $this->getPickups($node->filterXPath('//zustiege/zustieg'));
|
||||
$travel->pickupsFro = $this->getPickups($node->filterXPath('//zustiege_rueck/zustieg_rueck'));
|
||||
|
||||
return $travel;
|
||||
}
|
||||
@@ -347,4 +348,4 @@ class TravelLoader extends AbstractLoader
|
||||
$booking->travelData = $this->loadById($travelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,11 @@ class BookingParser extends AbstractParser
|
||||
|
||||
$pickupsData = $node->filterXPath('//zustiege/zustieg');
|
||||
if (0 < $pickupsData->count()) {
|
||||
$booking->pickups = $this->pickupsParser->parse($pickupsData);
|
||||
$booking->pickupsTo = $this->pickupsParser->parse($pickupsData);
|
||||
}
|
||||
$pickupsData = $node->filterXPath('//zustiege_rueck/zustieg_rueck');
|
||||
if (0 < $pickupsData->count()) {
|
||||
$booking->pickupsFro = $this->pickupsParser->parse($pickupsData);
|
||||
}
|
||||
|
||||
$surchargesData = $node->filterXPath('//zuschlaege/zuschlag');
|
||||
@@ -151,4 +155,4 @@ class BookingParser extends AbstractParser
|
||||
|
||||
return $personalData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ final class BookingType extends AbstractType
|
||||
->getTransportationServicesByDirection('HIN'),
|
||||
'selectable_transportation_services_fro' => $travelData
|
||||
->getTransportationServicesByDirection('RUECK'),
|
||||
'selectable_pickups' => $travelData->pickups,
|
||||
'selectable_pickups_to' => $travelData->pickupsTo,
|
||||
'selectable_pickups_fro' => $travelData->pickupsFro,
|
||||
'personal_data_mutable' => $travelData->participantDataMutable,
|
||||
'additional_services_mutable' => $travelData->additionalServicesMutable,
|
||||
'transportation_services_mutable' => $travelData->transportationServicesMutable,
|
||||
@@ -72,4 +73,4 @@ final class BookingType extends AbstractType
|
||||
'anti_xss' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +42,12 @@ class BookingData
|
||||
->getTransportationServiceForParticipantAndDirection($index, 'H');
|
||||
$participantData->transportationServiceFro = $booking
|
||||
->getTransportationServiceForParticipantAndDirection($index, 'R');
|
||||
$participantData->pickup = $booking->getPickupForParticipant($index);
|
||||
$participantData->pickupTo = $booking->getPickupToForParticipant($index);
|
||||
$participantData->pickupFro = $booking->getPickupFroForParticipant($index);
|
||||
|
||||
$instance->participants[$index] = $participantData;
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ class ParticipantData
|
||||
public array $rentals = [];
|
||||
public ?Service $transportationServiceTo = null;
|
||||
public ?Service $transportationServiceFro = null;
|
||||
public ?Pickup $pickup = null;
|
||||
public ?Pickup $pickupTo = null;
|
||||
public ?Pickup $pickupFro = null;
|
||||
|
||||
#[Assert\Callback]
|
||||
public function assertBodyMeasurementsValid(ExecutionContextInterface $context): void
|
||||
@@ -77,12 +78,18 @@ class ParticipantData
|
||||
#[Assert\Callback]
|
||||
public function assertPickupSelected(ExecutionContextInterface $context): void
|
||||
{
|
||||
if (null !== $this->transportationServiceTo && null === $this->pickup) {
|
||||
if (null !== $this->transportationServiceTo && null === $this->pickupTo) {
|
||||
$context->buildViolation('Bitte auswählen')
|
||||
->atPath('pickupTo')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
if (null !== $this->transportationServiceFro && null === $this->pickupFro) {
|
||||
$context->buildViolation('Bitte auswählen')
|
||||
->atPath('pickupFro')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromPersonalData(PersonalData $personalData): static
|
||||
|
||||
@@ -133,9 +133,6 @@ class ParticipantType extends AbstractType
|
||||
'expanded' => true,
|
||||
'choice_value' => 'id',
|
||||
'choice_label' => function (?Service $service) use ($participantIndex) {
|
||||
if (null === $service) {
|
||||
return null;
|
||||
}
|
||||
$price = $service->individualPrice[$participantIndex] ?? $service->price;
|
||||
if (null === $price || 0.0 === $price) {
|
||||
return $service->label;
|
||||
@@ -175,7 +172,10 @@ class ParticipantType extends AbstractType
|
||||
|
||||
return $attributes;
|
||||
},
|
||||
'choice_filter' => function (Service $service) use ($participantData) {
|
||||
'choice_filter' => function (?Service $service) use ($participantData) {
|
||||
if (null === $service) {
|
||||
return false;
|
||||
}
|
||||
// remove choices only available in booking data and
|
||||
// which are not mapped to the current participant
|
||||
if (
|
||||
@@ -248,35 +248,53 @@ class ParticipantType extends AbstractType
|
||||
'required' => true,
|
||||
'multiple' => false,
|
||||
'choices' => $options['selectable_transportation_services_fro'],
|
||||
'choice_attr' => function (?Service $service) {
|
||||
return [
|
||||
'data-booking-target' => 'field',
|
||||
'data-action' => 'select-toggle#toggle booking#toggle',
|
||||
'data-select-toggle-value' => $service->subType,
|
||||
];
|
||||
},
|
||||
])
|
||||
;
|
||||
|
||||
// Pickup
|
||||
$form
|
||||
->add('pickup', ChoiceType::class, [
|
||||
'label' => 'Zustieg',
|
||||
$form->add('pickupTo', ChoiceType::class, [
|
||||
'label' => 'Zustieg',
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $options['selectable_pickups_to'],
|
||||
'choice_value' => 'id',
|
||||
'choice_label' => function (?Pickup $pickup) {
|
||||
if (null === $pickup) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$price = $pickup->price;
|
||||
|
||||
if (null === $price || 0.0 === $price) {
|
||||
return $pickup->city;
|
||||
}
|
||||
|
||||
return sprintf('%s (%s €)',
|
||||
$pickup->city,
|
||||
number_format($price, 2, ',', '.')
|
||||
);
|
||||
},
|
||||
]);
|
||||
|
||||
if (0 < count($options['selectable_pickups_fro'])) {
|
||||
$form->add('pickupFro', ChoiceType::class, [
|
||||
'label' => 'Ausstieg',
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $options['selectable_pickups'],
|
||||
'choices' => $options['selectable_pickups_fro'],
|
||||
'choice_value' => 'id',
|
||||
'choice_label' => function (?Pickup $pickup) {
|
||||
if (null === $pickup) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$price = $pickup->price;
|
||||
|
||||
if (null === $price || 0.0 === $price) {
|
||||
return $pickup->city;
|
||||
}
|
||||
|
||||
return sprintf('%s (%s €)',
|
||||
$pickup->city,
|
||||
number_format($price, 2, ',', '.')
|
||||
);
|
||||
return $pickup?->city;
|
||||
},
|
||||
])
|
||||
;
|
||||
]);
|
||||
}
|
||||
})
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
|
||||
$data = $event->getData();
|
||||
@@ -324,7 +342,8 @@ class ParticipantType extends AbstractType
|
||||
'selectable_rentals' => [],
|
||||
'selectable_transportation_services_to' => [],
|
||||
'selectable_transportation_services_fro' => [],
|
||||
'selectable_pickups' => [],
|
||||
'selectable_pickups_to' => [],
|
||||
'selectable_pickups_fro' => [],
|
||||
'personal_data_mutable' => true,
|
||||
'additional_services_mutable' => true,
|
||||
'transportation_services_mutable' => true,
|
||||
|
||||
Reference in New Issue
Block a user