feat: new service category 'VEG'
This commit is contained in:
@@ -14,6 +14,7 @@ final class Constants
|
||||
public const TOKEN_SKI_PASS = 'SPA';
|
||||
public const TOKEN_ADDITIONAL = 'SON';
|
||||
public const TOKEN_BOARD = 'VPF';
|
||||
public const TOKEN_VEG = 'VEG';
|
||||
public const TOKEN_RENTALS = ['VER', 'VE2', 'VE3', 'VE4', 'VE5', 'VE6', 'VE7', 'VE8'];
|
||||
public const TOKEN_RENTAL_INSURANCE = 'LVS';
|
||||
public const TOKEN_INSURANCES = ['RRV', 'PAK', 'OHN', 'PKG'];
|
||||
@@ -37,6 +38,7 @@ final class Constants
|
||||
self::TOKEN_SKI_PASS => 'Skipässe',
|
||||
self::TOKEN_ADDITIONAL => 'Zusatzleistungen',
|
||||
self::TOKEN_BOARD => 'Verpflegung',
|
||||
self::TOKEN_VEG => 'Verpflegungswunsch',
|
||||
self::TOKEN_RENTAL_INSURANCE => 'Leihmaterial-Versicherung',
|
||||
self::TOKEN_PARKING => 'Parkplatz',
|
||||
self::GROUP_TRANSPORTATION => 'Beförderung',
|
||||
|
||||
@@ -57,6 +57,11 @@ class ServiceMappingCollector
|
||||
$serviceMap[$board->id][] = $participantId;
|
||||
}
|
||||
|
||||
// Veg (vegetarian/vegan) preference
|
||||
if (null !== $participant->veg) {
|
||||
$serviceMap[$participant->veg->id][] = $participantId;
|
||||
}
|
||||
|
||||
// Ski pass
|
||||
if (null !== $participant->skiPass) {
|
||||
$serviceMap[$participant->skiPass->id][] = $participantId;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -289,13 +289,17 @@ class ServicePricingCalculator
|
||||
array &$serviceAggregation,
|
||||
BookingDto $bookingDto,
|
||||
): void {
|
||||
// Handle single service selections (skiPass, rentalInsurance)
|
||||
// Handle single service selections (skiPass, veg, rentalInsurance)
|
||||
if (null !== $participant->skiPass && null !== $participant->skiPass->price) {
|
||||
$this->addToServiceAggregation($serviceAggregation, $participant->skiPass, 1);
|
||||
$this->addToServiceAggregation($serviceAggregation, $participant->skiPass);
|
||||
}
|
||||
|
||||
if (null !== $participant->veg && null !== $participant->veg->price) {
|
||||
$this->addToServiceAggregation($serviceAggregation, $participant->veg);
|
||||
}
|
||||
|
||||
if (null !== $participant->rentalInsurance && null !== $participant->rentalInsurance->price) {
|
||||
$this->addToServiceAggregation($serviceAggregation, $participant->rentalInsurance, 1);
|
||||
$this->addToServiceAggregation($serviceAggregation, $participant->rentalInsurance);
|
||||
}
|
||||
|
||||
// Resolve insurance: use price-tier-adjusted insurance for bulk assignment
|
||||
@@ -303,7 +307,7 @@ class ServicePricingCalculator
|
||||
$insuranceToAggregate = $this->resolveInsuranceForAggregation($participant, $bookingDto);
|
||||
|
||||
if (null !== $insuranceToAggregate && null !== $insuranceToAggregate->price && false === $insuranceToAggregate->isNoInsurance()) {
|
||||
$this->addInsuranceToServiceAggregation($serviceAggregation, $insuranceToAggregate, 1);
|
||||
$this->addInsuranceToServiceAggregation($serviceAggregation, $insuranceToAggregate);
|
||||
}
|
||||
|
||||
// Handle multiple service selections
|
||||
@@ -318,7 +322,7 @@ class ServicePricingCalculator
|
||||
if (true === is_array($serviceArray)) {
|
||||
foreach ($serviceArray as $service) {
|
||||
if ($service instanceof Service && null !== $service->price) {
|
||||
$this->addToServiceAggregation($serviceAggregation, $service, 1);
|
||||
$this->addToServiceAggregation($serviceAggregation, $service);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,7 +332,7 @@ class ServicePricingCalculator
|
||||
/**
|
||||
* Adds a service to the aggregation array, incrementing count and updating total price.
|
||||
*/
|
||||
private function addToServiceAggregation(array &$serviceAggregation, Service $service, int $quantity): void
|
||||
private function addToServiceAggregation(array &$serviceAggregation, Service $service, int $quantity = 1): void
|
||||
{
|
||||
$serviceKey = $service->id.'_'.$service->label;
|
||||
|
||||
@@ -354,7 +358,7 @@ class ServicePricingCalculator
|
||||
* @param Insurance $insurance The insurance to add
|
||||
* @param int $quantity The quantity of the insurance
|
||||
*/
|
||||
private function addInsuranceToServiceAggregation(array &$serviceAggregation, Insurance $insurance, int $quantity): void
|
||||
private function addInsuranceToServiceAggregation(array &$serviceAggregation, Insurance $insurance, int $quantity = 1): void
|
||||
{
|
||||
$serviceKey = $insurance->id.'_'.$insurance->label;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user