fix: process canceled participants correctly
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user