feat: new service category 'VEG'

This commit is contained in:
Björn Fromme
2026-03-16 12:02:27 +01:00
parent 75366167e8
commit 95d0ce33d4
11 changed files with 437 additions and 12 deletions
+1
View File
@@ -334,6 +334,7 @@ class BookingParticipantType extends AbstractType
'courses' => ChoiceType::class,
'additionalServices' => ChoiceType::class,
'board' => ChoiceType::class,
'veg' => ChoiceType::class,
'rentals' => ChoiceType::class,
'rentalInsurance' => CheckboxType::class,
'skiPass' => ChoiceType::class,
+2
View File
@@ -25,6 +25,7 @@ class ParticipantDto
'courses',
'additionalServices',
'board',
'veg',
'rentals',
'rentalInsurance',
'skiPass',
@@ -89,6 +90,7 @@ class ParticipantDto
public ?Service $skiPass = null;
public array $board = [];
public ?Service $veg = null;
public array $rentals = [];
public ?Service $rentalInsurance = null;
@@ -193,6 +193,13 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
),
];
$this->fieldStateConditions['veg'] = [
'hidden' => CompositeCondition::or(
CompositeCondition::not($dateOfBirthProvidedCondition),
$bookingEligibilityCondition
),
];
// Bulk insurance booking conditions
$bulkInsuranceBookingCondition = new BulkInsuranceBookingCondition();
@@ -144,6 +144,11 @@ class EditFieldStateProvider extends AbstractFieldStateProvider
'readonly' => $additionalServicesMutabilityCondition,
];
$this->fieldStateConditions['veg'] = [
'hidden' => $hideUntilDobCondition,
'readonly' => $additionalServicesMutabilityCondition,
];
// Skipass - hidden until birth date (except first participant), readonly if services not mutable
$this->fieldStateConditions['skiPass'] = [
'hidden' => $hideUntilDobCondition,
@@ -211,6 +211,51 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
},
];
// Veg (vegetarian/vegan) field provider - provides dietary preference options as radio buttons (mutually exclusive)
$this->fieldOptionProviders['veg'] = fn (BookingDto $bookingDto, int $participantIndex, array $options = []) => [
'label' => 'Verpflegungswunsch',
'multiple' => false,
'expanded' => true,
'required' => false,
'choices' => $this->filterServicesByAgeConstraints(
$bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_VEG, true),
$bookingDto,
$participantIndex
),
'choice_value' => 'id',
'choice_label' => fn (?Service $service) => $service?->label,
'choice_attr' => function (?Service $service) use ($bookingDto, $participantIndex) {
if (null === $service) {
return [];
}
$attributes = [];
// Add service description as data attribute for frontend use
if (null !== $service->description && '' !== trim($service->description)) {
$attributes['data-description'] = $service->description;
}
// Check age restriction first (takes precedence over availability)
$ageEvaluator = new ServiceAgeEvaluator();
if ($ageEvaluator->canEvaluate($service)
&& false === $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex)) {
$attributes['readonly'] = true;
$attributes['data-tooltip'] = $this->getAgeRestrictionTooltip($service);
return $attributes;
}
// Make readonly if service is unavailable (intelligently handles edit mode)
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'veg')) {
$attributes['readonly'] = true;
$attributes['data-tooltip'] = 'ausgebucht';
}
return $attributes;
},
];
// Rentals field provider - provides age-appropriate rental options filtered by selected skipass duration
$this->fieldOptionProviders['rentals'] = fn (BookingDto $bookingDto, int $participantIndex, array $options = []) => [
'label' => 'Leihmaterial',
@@ -700,6 +745,7 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
'courses' => $this->hasServiceById($participant->courses, $service->id),
'additionalServices' => $this->hasServiceById($participant->additionalServices, $service->id),
'board' => $this->hasServiceById($participant->board, $service->id),
'veg' => $participant->veg?->id === $service->id,
'rentals' => $this->hasServiceById($participant->rentals, $service->id),
'skiPass' => $participant->skiPass?->id === $service->id,
'transportationOutbound' => $participant->transportationOutbound?->id === $service->id,
@@ -0,0 +1,132 @@
<?php
declare(strict_types=1);
namespace App\Form\Service;
use App\BusProNet\Constants;
use App\BusProNet\Model\Service;
use App\Form\Model\BookingDto;
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
/**
* Handles processing of the veg (vegetarian/vegan) field for booking participants.
*
* This handler manages dietary preference selection for participants in the booking
* process. It processes the veg field from form submissions, validates age-appropriate
* options if constraints exist, and updates the participant DTO with the valid selection.
*
* The field is rendered as radio buttons (mutually exclusive single selection) since
* vegetarian and vegan options should not be combined.
*
* Dependencies: dateOfBirth (for potential future age constraints)
*/
class ParticipantVegFieldHandler extends AbstractParticipantFieldHandler
{
/**
* Returns the form field name this handler processes.
*
* @return string The field name 'veg'
*/
public function getFieldName(): string
{
return 'veg';
}
/**
* Returns the field dependencies for proper processing order.
*
* This handler depends on dateOfBirth being processed first because
* age evaluation requires the participant's birth date to be available.
*
* @return string[] Array containing 'dateOfBirth' dependency
*/
public function getDependencies(): array
{
return ['dateOfBirth'];
}
/**
* Determines if this handler should process the field based on submitted data.
*
* For service selection fields, we always need to process to handle cases where
* the selection is cleared (field not present in data). This ensures the participant
* DTO is updated with null when no option is selected.
*
* @param array<string, mixed> $submittedData The submitted participant form data
* @param string $mode The booking mode (BookingDto::MODE_CREATE or MODE_EDIT)
* @param int $participantIndex The index of the participant being processed
*
* @return bool Always returns true for service selection fields
*/
public function shouldProcess(array $submittedData, string $mode, int $participantIndex): bool
{
return true;
}
/**
* Processes the veg field for a specific participant.
*
* This method extracts the dietary preference selection from submitted form data,
* validates the selection against any age constraints if present, and updates the
* participant DTO with the valid selection.
*
* @param array<string, mixed> $submittedData The submitted participant form data
* @param BookingDto $bookingDto The booking DTO to update (create or edit)
* @param int $participantIndex The index of the participant being processed
*/
public function processField(array $submittedData, BookingDto $bookingDto, int $participantIndex): void
{
$participant = $this->getParticipant($bookingDto, $participantIndex);
if (null === $participant) {
return;
}
$selectedVeg = $this->getFieldValue($submittedData, $this->getFieldName());
$availableVegOptions = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_VEG, true);
$validSelection = null;
if (null !== $selectedVeg) {
if ($this->isServiceValidForParticipant($selectedVeg, $availableVegOptions, $bookingDto, $participantIndex)) {
$validSelection = $this->findServiceInAvailableServices($selectedVeg, $availableVegOptions);
}
}
$participant->veg = $validSelection;
}
/**
* Validates if a selected veg option is still valid for the participant.
*
* This method checks age constraints if they exist for the service.
*
* @param mixed $selectedService The selected veg option to validate
* @param array $availableServices Array of available veg options
* @param BookingDto $bookingDto The booking DTO for context
* @param int $participantIndex The participant index for age evaluation
*
* @return bool True if the option is valid for the participant, false otherwise
*/
private function isServiceValidForParticipant(
mixed $selectedService,
array $availableServices,
BookingDto $bookingDto,
int $participantIndex,
): bool {
$service = $this->findServiceInAvailableServices($selectedService, $availableServices);
if (null === $service) {
return false;
}
$ageEvaluator = new ServiceAgeEvaluator();
if ($ageEvaluator->canEvaluate($service)) {
if (false === $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex)) {
return false;
}
}
return true;
}
}