wip: selectable bus exits

This commit is contained in:
Björn Fromme
2025-03-12 18:05:21 +01:00
parent 778d79fd23
commit 851c7086ba
14 changed files with 162 additions and 75 deletions
+3 -2
View File
@@ -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,
]);
}
}
}
+3 -2
View File
@@ -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;
}
}
}
+9 -2
View File
@@ -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
+44 -25
View File
@@ -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,