diff --git a/src/BusProNet/DataProcessor/BookingDataProcessor.php b/src/BusProNet/DataProcessor/BookingDataProcessor.php index def3354..d496c34 100644 --- a/src/BusProNet/DataProcessor/BookingDataProcessor.php +++ b/src/BusProNet/DataProcessor/BookingDataProcessor.php @@ -17,6 +17,11 @@ class BookingDataProcessor } // Update mappings, add services and pickups foreach ($formData->participants as $participant) { + // skip canceled participants + if ('F' !== $participant->status) { + continue; + } + $servicesToMap = [ ...$participant->courses, ...$participant->additionalServices, @@ -46,12 +51,6 @@ class BookingDataProcessor } $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 foreach ($bookingData->additionalServices as $service) { @@ -77,8 +76,12 @@ class BookingDataProcessor // Update participants' personal data foreach ($formData->participants as $participant) { + // skip canceled participants + if ('F' !== $participant->status) { + continue; + } $bookingData->participants[$participant->index]->firstName = $participant->firstName; - $bookingData->participants[$participant->index]->lastName = $participant->lastName; + $bookingData->participants[$participant->index]->name = $participant->lastName; $bookingData->participants[$participant->index]->dateOfBirth = $participant->dateOfBirth; $bookingData->participants[$participant->index]->gender = $participant->gender; $bookingData->participants[$participant->index]->nationality = $participant->nationality; @@ -169,17 +172,6 @@ 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; } } diff --git a/src/BusProNet/Model/Booking.php b/src/BusProNet/Model/Booking.php index 9e0de2f..afa8dc3 100644 --- a/src/BusProNet/Model/Booking.php +++ b/src/BusProNet/Model/Booking.php @@ -76,7 +76,7 @@ class Booking return null; } - public function getPickupToForParticipant(int $participantIndex): ?Pickup + public function getPickupForParticipant(int $participantIndex): ?Pickup { foreach ($this->pickupsTo as $pickup) { if (in_array($participantIndex, $pickup->mapping)) { @@ -87,17 +87,6 @@ class Booking return null; } - public function getPickupFroForParticipant(int $participantIndex): ?Pickup - { - foreach ($this->pickupsFro as $pickup) { - if (in_array($participantIndex, $pickup->mapping)) { - return $pickup; - } - } - - return null; - } - public function getRoomForParticipant(int $participantIndex): ?Room { foreach ($this->rooms as $room) { diff --git a/src/BusProNet/Model/PersonalData.php b/src/BusProNet/Model/PersonalData.php index 7a80a56..899ffbc 100644 --- a/src/BusProNet/Model/PersonalData.php +++ b/src/BusProNet/Model/PersonalData.php @@ -9,6 +9,7 @@ class PersonalData public ?int $addressId = null; public ?int $personId = null; public bool $mutable = false; + public ?string $status = null; #[Assert\NotBlank(message: 'Bitte angeben')] public ?string $name = null; @@ -57,4 +58,4 @@ class PersonalData 'bemerkung' => $this->remarks, ]; } -} \ No newline at end of file +} diff --git a/src/BusProNet/TypeConversionTrait.php b/src/BusProNet/TypeConversionTrait.php index 8c59fd0..5cdff27 100644 --- a/src/BusProNet/TypeConversionTrait.php +++ b/src/BusProNet/TypeConversionTrait.php @@ -36,7 +36,7 @@ trait TypeConversionTrait return false; } - return 'True' === $string; + return 'True' === $string || 'J' === $string; } protected function boolToString(bool $bool): string @@ -71,4 +71,4 @@ trait TypeConversionTrait return null; } } -} \ No newline at end of file +} diff --git a/src/BusProNet/XmlParser/BookingParser.php b/src/BusProNet/XmlParser/BookingParser.php index 7272349..00217a1 100644 --- a/src/BusProNet/XmlParser/BookingParser.php +++ b/src/BusProNet/XmlParser/BookingParser.php @@ -109,6 +109,8 @@ class BookingParser extends AbstractParser { $personalData = new PersonalData(); + $personalData->status = $this->getStringOrNullValue($node->filterXPath('//status')); + $personalData->addressId = $this->getIntOrNullValue($node->filterXPath('//idadresse')); $personalData->personId = $this->getIntOrNullValue($node->filterXPath('//idadresseperson')); $personalData->mutable = $this->getBoolValue($node->filterXPath('//aenderungmoeglich')); diff --git a/src/Form/BookingType.php b/src/Form/BookingType.php index 8a35e1f..a36b08a 100644 --- a/src/Form/BookingType.php +++ b/src/Form/BookingType.php @@ -33,14 +33,12 @@ final class BookingType extends AbstractType ->getTransportationServicesByDirection('HIN'), 'selectable_transportation_services_fro' => $travelData ->getTransportationServicesByDirection('RUECK'), - 'selectable_pickups_to' => $travelData->pickupsTo, - 'selectable_pickups_fro' => $travelData->pickupsFro, + 'selectable_pickups' => $travelData->pickupsTo, 'personal_data_mutable' => $travelData->participantDataMutable, 'additional_services_mutable' => $travelData->additionalServicesMutable, 'transportation_services_mutable' => $travelData->transportationServicesMutable, 'pickups_mutable' => $travelData->pickupsMutable, 'applicant_id' => $data->booking->applicant->personId, - ], 'allow_add' => false, 'allow_delete' => false, diff --git a/src/Form/Model/BookingData.php b/src/Form/Model/BookingData.php index 91bb809..9e6405a 100644 --- a/src/Form/Model/BookingData.php +++ b/src/Form/Model/BookingData.php @@ -27,23 +27,26 @@ class BookingData /** @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->pickupTo = $booking->getPickupToForParticipant($index); - $participantData->pickupFro = $booking->getPickupFroForParticipant($index); + + // update services only for active participants + if ('F' === $participantData->status) { + $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->pickupTo = $booking->getPickupForParticipant($index); + } $instance->participants[$index] = $participantData; } diff --git a/src/Form/Model/ParticipantData.php b/src/Form/Model/ParticipantData.php index 13a9413..7d78c1a 100644 --- a/src/Form/Model/ParticipantData.php +++ b/src/Form/Model/ParticipantData.php @@ -34,7 +34,6 @@ class ParticipantData #[Assert\Email(message: 'Bitte eine gültige E-Mail Adresse angeben', mode: 'strict')] public ?string $email = null; - #[Assert\NotBlank(message: 'Bitte angeben')] public ?string $mobile = null; public array $courses = []; public array $additionalServices = []; @@ -43,8 +42,7 @@ class ParticipantData public array $rentals = []; public ?Service $transportationServiceTo = null; public ?Service $transportationServiceFro = null; - public ?Pickup $pickupTo = null; - public ?Pickup $pickupFro = null; + public ?Pickup $pickup = null; #[Assert\Callback] public function assertBodyMeasurementsValid(ExecutionContextInterface $context): void @@ -78,15 +76,9 @@ class ParticipantData #[Assert\Callback] public function assertPickupSelected(ExecutionContextInterface $context): void { - if (null !== $this->transportationServiceTo && null === $this->pickupTo) { + if (null !== $this->transportationServiceTo && null === $this->pickup) { $context->buildViolation('Bitte auswählen') - ->atPath('pickupTo') - ->addViolation() - ; - } - if (null !== $this->transportationServiceFro && null === $this->pickupFro) { - $context->buildViolation('Bitte auswählen') - ->atPath('pickupFro') + ->atPath('pickup') ->addViolation() ; } @@ -96,6 +88,7 @@ class ParticipantData { $instance = new static(); + $instance->status = $personalData->status; $instance->addressId = $personalData->addressId; $instance->personId = $personalData->personId; $instance->mutable = $personalData->mutable; diff --git a/src/Form/ParticipantType.php b/src/Form/ParticipantType.php index 5303364..8ef8d8d 100644 --- a/src/Form/ParticipantType.php +++ b/src/Form/ParticipantType.php @@ -25,6 +25,11 @@ class ParticipantType extends AbstractType $participantData = $event->getData(); $participantIndex = $participantData->index; + // don't add any fields for canceled participants + if ('F' !== $participantData->status) { + return; + } + $form = $event->getForm(); $personalDataMutable = $options['personal_data_mutable'] && $participantData->mutable; @@ -83,6 +88,7 @@ class ParticipantType extends AbstractType ]) ->add('mobile', TextType::class, [ 'label' => 'Telefon (mobil)', + 'required' => false, 'attr' => [ 'readonly' => false === $personalDataMutable, ] @@ -259,11 +265,11 @@ class ParticipantType extends AbstractType ; // Pickup - $form->add('pickupTo', ChoiceType::class, [ + $form->add('pickup', ChoiceType::class, [ 'label' => 'Zustieg', 'multiple' => false, 'expanded' => false, - 'choices' => $options['selectable_pickups_to'], + 'choices' => $options['selectable_pickups'], 'choice_value' => 'id', 'choice_label' => function (?Pickup $pickup) { if (null === $pickup) { @@ -282,24 +288,16 @@ class ParticipantType extends AbstractType ); }, ]); - - if (0 < count($options['selectable_pickups_fro'])) { - $form->add('pickupFro', ChoiceType::class, [ - 'label' => 'Ausstieg', - 'multiple' => false, - 'expanded' => false, - 'choices' => $options['selectable_pickups_fro'], - 'choice_value' => 'id', - 'choice_label' => function (?Pickup $pickup) { - return $pickup?->city; - }, - ]); - } }) ->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) { $data = $event->getData(); $form = $event->getForm(); + // skip processing for canceled participants + if ('F' !== $form->getData()->status) { + return; + } + $transportationId = $data['transportationServiceTo']; $transportation = $options['travel']->pickups[$transportationId] ?? null; @@ -342,8 +340,7 @@ class ParticipantType extends AbstractType 'selectable_rentals' => [], 'selectable_transportation_services_to' => [], 'selectable_transportation_services_fro' => [], - 'selectable_pickups_to' => [], - 'selectable_pickups_fro' => [], + 'selectable_pickups' => [], 'personal_data_mutable' => true, 'additional_services_mutable' => true, 'transportation_services_mutable' => true, diff --git a/templates/booking/edit.html.twig b/templates/booking/edit.html.twig index 150e79b..49cbfd0 100644 --- a/templates/booking/edit.html.twig +++ b/templates/booking/edit.html.twig @@ -111,112 +111,22 @@ {% for child in form.participants %}