feat: new service category 'VEG'

This commit is contained in:
Björn Fromme
2026-01-08 16:42:42 +01:00
parent 479a88e131
commit 6beb965c85
11 changed files with 437 additions and 12 deletions
+2
View File
@@ -14,6 +14,7 @@ final class Constants
public const TOKEN_SKI_PASS = 'SPA'; public const TOKEN_SKI_PASS = 'SPA';
public const TOKEN_ADDITIONAL = 'SON'; public const TOKEN_ADDITIONAL = 'SON';
public const TOKEN_BOARD = 'VPF'; 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_RENTALS = ['VER', 'VE2', 'VE3', 'VE4', 'VE5', 'VE6', 'VE7', 'VE8'];
public const TOKEN_RENTAL_INSURANCE = 'LVS'; public const TOKEN_RENTAL_INSURANCE = 'LVS';
public const TOKEN_INSURANCES = ['RRV', 'PAK', 'OHN', 'PKG']; public const TOKEN_INSURANCES = ['RRV', 'PAK', 'OHN', 'PKG'];
@@ -37,6 +38,7 @@ final class Constants
self::TOKEN_SKI_PASS => 'Skipässe', self::TOKEN_SKI_PASS => 'Skipässe',
self::TOKEN_ADDITIONAL => 'Zusatzleistungen', self::TOKEN_ADDITIONAL => 'Zusatzleistungen',
self::TOKEN_BOARD => 'Verpflegung', self::TOKEN_BOARD => 'Verpflegung',
self::TOKEN_VEG => 'Verpflegungswunsch',
self::TOKEN_RENTAL_INSURANCE => 'Leihmaterial-Versicherung', self::TOKEN_RENTAL_INSURANCE => 'Leihmaterial-Versicherung',
self::TOKEN_PARKING => 'Parkplatz', self::TOKEN_PARKING => 'Parkplatz',
self::GROUP_TRANSPORTATION => 'Beförderung', self::GROUP_TRANSPORTATION => 'Beförderung',
@@ -57,6 +57,11 @@ class ServiceMappingCollector
$serviceMap[$board->id][] = $participantId; $serviceMap[$board->id][] = $participantId;
} }
// Veg (vegetarian/vegan) preference
if (null !== $participant->veg) {
$serviceMap[$participant->veg->id][] = $participantId;
}
// Ski pass // Ski pass
if (null !== $participant->skiPass) { if (null !== $participant->skiPass) {
$serviceMap[$participant->skiPass->id][] = $participantId; $serviceMap[$participant->skiPass->id][] = $participantId;
+1
View File
@@ -334,6 +334,7 @@ class BookingParticipantType extends AbstractType
'courses' => ChoiceType::class, 'courses' => ChoiceType::class,
'additionalServices' => ChoiceType::class, 'additionalServices' => ChoiceType::class,
'board' => ChoiceType::class, 'board' => ChoiceType::class,
'veg' => ChoiceType::class,
'rentals' => ChoiceType::class, 'rentals' => ChoiceType::class,
'rentalInsurance' => CheckboxType::class, 'rentalInsurance' => CheckboxType::class,
'skiPass' => ChoiceType::class, 'skiPass' => ChoiceType::class,
+2
View File
@@ -25,6 +25,7 @@ class ParticipantDto
'courses', 'courses',
'additionalServices', 'additionalServices',
'board', 'board',
'veg',
'rentals', 'rentals',
'rentalInsurance', 'rentalInsurance',
'skiPass', 'skiPass',
@@ -89,6 +90,7 @@ class ParticipantDto
public ?Service $skiPass = null; public ?Service $skiPass = null;
public array $board = []; public array $board = [];
public ?Service $veg = null;
public array $rentals = []; public array $rentals = [];
public ?Service $rentalInsurance = null; 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 // Bulk insurance booking conditions
$bulkInsuranceBookingCondition = new BulkInsuranceBookingCondition(); $bulkInsuranceBookingCondition = new BulkInsuranceBookingCondition();
@@ -144,6 +144,11 @@ class EditFieldStateProvider extends AbstractFieldStateProvider
'readonly' => $additionalServicesMutabilityCondition, 'readonly' => $additionalServicesMutabilityCondition,
]; ];
$this->fieldStateConditions['veg'] = [
'hidden' => $hideUntilDobCondition,
'readonly' => $additionalServicesMutabilityCondition,
];
// Skipass - hidden until birth date (except first participant), readonly if services not mutable // Skipass - hidden until birth date (except first participant), readonly if services not mutable
$this->fieldStateConditions['skiPass'] = [ $this->fieldStateConditions['skiPass'] = [
'hidden' => $hideUntilDobCondition, '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 // Rentals field provider - provides age-appropriate rental options filtered by selected skipass duration
$this->fieldOptionProviders['rentals'] = fn (BookingDto $bookingDto, int $participantIndex, array $options = []) => [ $this->fieldOptionProviders['rentals'] = fn (BookingDto $bookingDto, int $participantIndex, array $options = []) => [
'label' => 'Leihmaterial', 'label' => 'Leihmaterial',
@@ -700,6 +745,7 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
'courses' => $this->hasServiceById($participant->courses, $service->id), 'courses' => $this->hasServiceById($participant->courses, $service->id),
'additionalServices' => $this->hasServiceById($participant->additionalServices, $service->id), 'additionalServices' => $this->hasServiceById($participant->additionalServices, $service->id),
'board' => $this->hasServiceById($participant->board, $service->id), 'board' => $this->hasServiceById($participant->board, $service->id),
'veg' => $participant->veg?->id === $service->id,
'rentals' => $this->hasServiceById($participant->rentals, $service->id), 'rentals' => $this->hasServiceById($participant->rentals, $service->id),
'skiPass' => $participant->skiPass?->id === $service->id, 'skiPass' => $participant->skiPass?->id === $service->id,
'transportationOutbound' => $participant->transportationOutbound?->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;
}
}
+11 -7
View File
@@ -289,13 +289,17 @@ class ServicePricingCalculator
array &$serviceAggregation, array &$serviceAggregation,
BookingDto $bookingDto, BookingDto $bookingDto,
): void { ): void {
// Handle single service selections (skiPass, rentalInsurance) // Handle single service selections (skiPass, veg, rentalInsurance)
if (null !== $participant->skiPass && null !== $participant->skiPass->price) { 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) { 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 // Resolve insurance: use price-tier-adjusted insurance for bulk assignment
@@ -303,7 +307,7 @@ class ServicePricingCalculator
$insuranceToAggregate = $this->resolveInsuranceForAggregation($participant, $bookingDto); $insuranceToAggregate = $this->resolveInsuranceForAggregation($participant, $bookingDto);
if (null !== $insuranceToAggregate && null !== $insuranceToAggregate->price && false === $insuranceToAggregate->isNoInsurance()) { if (null !== $insuranceToAggregate && null !== $insuranceToAggregate->price && false === $insuranceToAggregate->isNoInsurance()) {
$this->addInsuranceToServiceAggregation($serviceAggregation, $insuranceToAggregate, 1); $this->addInsuranceToServiceAggregation($serviceAggregation, $insuranceToAggregate);
} }
// Handle multiple service selections // Handle multiple service selections
@@ -318,7 +322,7 @@ class ServicePricingCalculator
if (true === is_array($serviceArray)) { if (true === is_array($serviceArray)) {
foreach ($serviceArray as $service) { foreach ($serviceArray as $service) {
if ($service instanceof Service && null !== $service->price) { 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. * 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; $serviceKey = $service->id.'_'.$service->label;
@@ -354,7 +358,7 @@ class ServicePricingCalculator
* @param Insurance $insurance The insurance to add * @param Insurance $insurance The insurance to add
* @param int $quantity The quantity of the insurance * @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; $serviceKey = $insurance->id.'_'.$insurance->label;
+11 -5
View File
@@ -279,7 +279,6 @@
{# Room assignment - hidden until date of birth is provided, or shown as static text in edit mode #} {# Room assignment - hidden until date of birth is provided, or shown as static text in edit mode #}
{% if form.assignedRoomId is defined or is_static_text('assignedRoomId', bookingDto, participantIndex) %} {% if form.assignedRoomId is defined or is_static_text('assignedRoomId', bookingDto, participantIndex) %}
<hr>
<div> <div>
{% set assignedRoom = bookingDto.travel.getRoomById(form.vars.data.participant.assignedRoomId) %} {% set assignedRoom = bookingDto.travel.getRoomById(form.vars.data.participant.assignedRoomId) %}
{% set roomLabel = assignedRoom ? assignedRoom.label : 'Kein Zimmer zugewiesen' %} {% set roomLabel = assignedRoom ? assignedRoom.label : 'Kein Zimmer zugewiesen' %}
@@ -298,7 +297,6 @@
{{ form_row(form.remarksRoom) }} {{ form_row(form.remarksRoom) }}
{% endif %} {% endif %}
</div> </div>
<hr>
{% endif %} {% endif %}
{# Service selection #} {# Service selection #}
@@ -338,6 +336,17 @@
} }
}) }} }) }}
{# VEG field - only render when defined (hide completely when no VEG services available) #}
{% if form.veg is defined %}
{{ macros.service_field(form, 'veg', 'Verpflegungswunsch', {
'attr': {
'hx-trigger': htmx_change_trigger,
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
}
}) }}
{% endif %}
{% set htmxAttr = { {% set htmxAttr = {
'hx-trigger': htmx_change_trigger, 'hx-trigger': htmx_change_trigger,
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})), 'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
@@ -524,8 +533,6 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
<hr>
{# Transportation Services Section #} {# Transportation Services Section #}
<h3 class="font-semibold text-lg mb-4"> <h3 class="font-semibold text-lg mb-4">
Anreise Anreise
@@ -587,7 +594,6 @@
{# Voucher fields - available for all participants regardless of eligibility #} {# Voucher fields - available for all participants regardless of eligibility #}
{% if form.purchaseVoucherCode is defined or form.promoVoucherCode is defined %} {% if form.purchaseVoucherCode is defined or form.promoVoucherCode is defined %}
<hr>
<h3 class="font-semibold text-lg mb-4"> <h3 class="font-semibold text-lg mb-4">
Gutscheine Gutscheine
</h3> </h3>
@@ -0,0 +1,215 @@
<?php
declare(strict_types=1);
namespace App\Tests\Form\Service;
use App\BusProNet\Constants;
use App\BusProNet\Model\Service;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Service\ParticipantVegFieldHandler;
use PHPUnit\Framework\TestCase;
class ParticipantVegFieldHandlerTest extends TestCase
{
private ParticipantVegFieldHandler $handler;
protected function setUp(): void
{
$this->handler = new ParticipantVegFieldHandler();
}
public function testGetFieldName(): void
{
$this->assertEquals('veg', $this->handler->getFieldName());
}
public function testGetDependencies(): void
{
$dependencies = $this->handler->getDependencies();
$this->assertEquals(['dateOfBirth'], $dependencies);
}
public function testShouldProcessAlwaysReturnsTrue(): void
{
// Should always process to handle deselection cases
$this->assertTrue($this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0));
$this->assertTrue($this->handler->shouldProcess([], BookingDto::MODE_EDIT, 0));
$this->assertTrue($this->handler->shouldProcess(['veg' => '123'], BookingDto::MODE_CREATE, 0));
}
public function testProcessFieldDoesNothingWhenNoParticipant(): void
{
$bookingDto = $this->createMockBookingDto();
$bookingDto->method('getParticipants')->willReturn([]);
$this->handler->processField(['veg' => '123'], $bookingDto, 0);
// No assertions needed - just ensure no exceptions are thrown
$this->addToAssertionCount(1);
}
public function testProcessFieldClearsVegWhenNullSelection(): void
{
$participant = new ParticipantDto();
$participant->veg = $this->createService(123);
$travel = $this->createMockTravel([]);
$bookingDto = $this->createMockBookingDto($travel);
$bookingDto->method('getParticipants')->willReturn([$participant]);
$this->handler->processField(['veg' => null], $bookingDto, 0);
$this->assertNull($participant->veg);
}
public function testProcessFieldClearsVegWhenEmptyStringSelection(): void
{
$participant = new ParticipantDto();
$participant->veg = $this->createService(123);
$travel = $this->createMockTravel([]);
$bookingDto = $this->createMockBookingDto($travel);
$bookingDto->method('getParticipants')->willReturn([$participant]);
$this->handler->processField(['veg' => ''], $bookingDto, 0);
$this->assertNull($participant->veg);
}
public function testProcessFieldClearsVegWhenMissingFromData(): void
{
$participant = new ParticipantDto();
$participant->veg = $this->createService(123);
$travel = $this->createMockTravel([]);
$bookingDto = $this->createMockBookingDto($travel);
$bookingDto->method('getParticipants')->willReturn([$participant]);
$this->handler->processField([], $bookingDto, 0);
$this->assertNull($participant->veg);
}
public function testProcessFieldClearsVegWhenNotFoundInAvailableServices(): void
{
$participant = new ParticipantDto();
$otherService = $this->createService(456);
$travel = $this->createMockTravel([$otherService]);
$bookingDto = $this->createMockBookingDto($travel);
$bookingDto->method('getParticipants')->willReturn([$participant]);
$this->handler->processField(['veg' => '123'], $bookingDto, 0);
$this->assertNull($participant->veg);
}
public function testProcessFieldSetsVegWhenAvailable(): void
{
$vegService = $this->createService(123);
$participant = new ParticipantDto();
$travel = $this->createMockTravel([$vegService]);
$bookingDto = $this->createMockBookingDto($travel);
$bookingDto->method('getParticipants')->willReturn([$participant]);
$this->handler->processField(['veg' => '123'], $bookingDto, 0);
$this->assertSame($vegService, $participant->veg);
}
public function testProcessFieldWorksWithStringAndIntegerIds(): void
{
$vegService = $this->createService(123); // Integer ID
$participant = new ParticipantDto();
$travel = $this->createMockTravel([$vegService]);
$bookingDto = $this->createMockBookingDto($travel);
$bookingDto->method('getParticipants')->willReturn([$participant]);
$this->handler->processField(['veg' => '123'], $bookingDto, 0); // String selection
$this->assertSame($vegService, $participant->veg);
}
public function testProcessFieldHandlesEmptyServicesArray(): void
{
$participant = new ParticipantDto();
$travel = $this->createMockTravel([]);
$bookingDto = $this->createMockBookingDto($travel);
$bookingDto->method('getParticipants')->willReturn([$participant]);
$this->handler->processField(['veg' => '123'], $bookingDto, 0);
$this->assertNull($participant->veg);
}
public function testProcessFieldSelectsFromMultipleVegOptions(): void
{
$vegetarian = $this->createService(1, 'Vegetarisch');
$vegan = $this->createService(2, 'Vegan');
$participant = new ParticipantDto();
$travel = $this->createMockTravel([$vegetarian, $vegan]);
$bookingDto = $this->createMockBookingDto($travel);
$bookingDto->method('getParticipants')->willReturn([$participant]);
$this->handler->processField(['veg' => '2'], $bookingDto, 0);
$this->assertSame($vegan, $participant->veg);
}
public function testGetFieldStateModificationsReturnsEmptyArray(): void
{
$bookingDto = $this->createMockBookingDto();
$result = $this->handler->getFieldStateModifications([], $bookingDto, 0);
$this->assertIsArray($result);
$this->assertEmpty($result);
}
public function testGetAffectedFieldNamesReturnsEmptyArray(): void
{
$result = $this->handler->getAffectedFieldNames();
$this->assertIsArray($result);
$this->assertEmpty($result);
}
private function createService(int $id, string $label = 'Test Service'): Service
{
$service = new Service();
$service->id = $id;
$service->label = $label;
$service->subType = Constants::TOKEN_VEG;
return $service;
}
private function createMockTravel(array $vegServices): Travel
{
$travel = $this->createMock(Travel::class);
$travel->method('getAdditionalServicesBySubTypes')
->with(Constants::TOKEN_VEG, true)
->willReturn($vegServices);
return $travel;
}
private function createMockBookingDto(?Travel $travel = null): BookingDto
{
$bookingDto = $this->createMock(BookingDto::class);
if (null !== $travel) {
$bookingDto->travel = $travel;
}
return $bookingDto;
}
}