fix: prevent updating booked services unless mutable

This commit is contained in:
Björn Fromme
2025-03-24 17:11:37 +01:00
parent c8d8c62ff8
commit 7bcda3e6f8
3 changed files with 38 additions and 31 deletions
+34 -18
View File
@@ -149,7 +149,7 @@ class ParticipantType extends AbstractType
number_format($price, 2, ',', '.')
);
},
'choice_attr' => function (?Service $service) {
'choice_attr' => function (?Service $service) use ($options) {
$attributes = [
'data-booking-target' => 'field',
'data-action' => 'booking#toggle',
@@ -158,24 +158,28 @@ class ParticipantType extends AbstractType
// forcibly select mandatory services
if (true === $service->mandatory) {
$attributes['checked'] = true;
$attributes['disabled'] = true;
$attributes['readonly'] = true;
$attributes['class'] = 'text-pink';
$attributes['tooltip'] = 'Diese Leistung ist nicht abwählbar';
}
// disable selection of services only available in booking data
if (Service::SOURCE_BOOKING === $service->source) {
$attributes['disabled'] = true;
$attributes['class'] = 'text-pink';
}
// disable selection of services that are unavailable according to their status
if (Service::STATUS_BLOCKED === $service->status) {
$attributes['checked'] = false;
$attributes['disabled'] = true;
$attributes['readonly'] = true;
$attributes['tooltip'] = 'Diese Leistung ist derzeit leider nicht buchbar';
}
if (false === $options['additional_services_mutable']) {
$attributes['readonly'] = true;
$attributes['tooltip'] = 'Diese Leistung kann nicht mehr geändert werden';
}
return $attributes;
},
'choice_filter' => function (?Service $service) use ($participantData) {
@@ -233,6 +237,19 @@ class ParticipantType extends AbstractType
}
// Transportation
$transportationChoiceAttributes = function (?Service $service) use ($options) {
$attributes = [
'data-booking-target' => 'field',
'data-action' => 'select-toggle#toggle booking#toggle',
'data-select-toggle-value' => $service->subType,
];
if (false === $options['transportation_services_mutable']) {
$attributes['readonly'] = true;
$attributes['tooltip'] = 'Diese Leistung kann nicht mehr geändert werden';
}
return $attributes;
};
$form
->add('transportationServiceTo', ChoiceType::class, [
...$commonChoiceFieldOptions,
@@ -240,13 +257,7 @@ class ParticipantType extends AbstractType
'required' => true,
'multiple' => false,
'choices' => $options['selectable_transportation_services_to'],
'choice_attr' => function (?Service $service) {
return [
'data-booking-target' => 'field',
'data-action' => 'select-toggle#toggle booking#toggle',
'data-select-toggle-value' => $service->subType,
];
},
'choice_attr' => $transportationChoiceAttributes,
])
->add('transportationServiceFro', ChoiceType::class, [
...$commonChoiceFieldOptions,
@@ -254,13 +265,7 @@ 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,
];
},
'choice_attr' => $transportationChoiceAttributes,
])
;
@@ -287,6 +292,17 @@ class ParticipantType extends AbstractType
number_format($price, 2, ',', '.')
);
},
'choice_attr' => function (?Pickup $pickup) use ($options) {
$attributes = [];
if (false === $options['pickups_mutable']) {
$attributes['readonly'] = true;
}
return $attributes;
},
'attr' => [
'readonly' => false === $options['pickups_mutable'],
]
]);
})
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {