wip: rentals insurance field
This commit is contained in:
@@ -85,3 +85,4 @@ services:
|
|||||||
- 'App\Form\Service\ParticipantPickupOutboundFieldHandler'
|
- 'App\Form\Service\ParticipantPickupOutboundFieldHandler'
|
||||||
- 'App\Form\Service\ParticipantPickupInboundFieldHandler'
|
- 'App\Form\Service\ParticipantPickupInboundFieldHandler'
|
||||||
- 'App\Form\Service\ParticipantParkingFieldHandler'
|
- 'App\Form\Service\ParticipantParkingFieldHandler'
|
||||||
|
- 'App\Form\Service\ParticipantRentalInsuranceFieldHandler'
|
||||||
|
|||||||
@@ -297,4 +297,72 @@ class CustomFieldOptionsProvider extends AbstractFieldOptionsProvider
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Current Implementation Examples
|
||||||
|
|
||||||
|
### Body Dimensions and Rental Insurance Conditional Fields
|
||||||
|
|
||||||
|
The current system implements sophisticated conditional field visibility for body dimensions and rental insurance:
|
||||||
|
|
||||||
|
```php
|
||||||
|
// CreateFieldStateProvider.php
|
||||||
|
protected function registerFieldStateConditions(): void
|
||||||
|
{
|
||||||
|
$rentalCondition = new RentalSelectionCondition();
|
||||||
|
|
||||||
|
// Hide body dimensions section unless rental services are selected
|
||||||
|
$this->fieldStateConditions['bodyDimensions'] = [
|
||||||
|
'hidden' => CompositeCondition::not($rentalCondition),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Hide rental insurance unless rental services are selected
|
||||||
|
$this->fieldStateConditions['rentalInsurance'] = [
|
||||||
|
'hidden' => CompositeCondition::not($rentalCondition),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Hide parking unless outbound transportation is PKW (car)
|
||||||
|
$this->fieldStateConditions['parking'] = [
|
||||||
|
'hidden' => CompositeCondition::not(
|
||||||
|
ServiceSubTypeCondition::equals('transportationOutbound', DirectionMapper::SUBTYPE_CAR_API)
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rental Insurance Checkbox Implementation
|
||||||
|
|
||||||
|
The rental insurance field demonstrates the checkbox pattern used for service selection:
|
||||||
|
|
||||||
|
```php
|
||||||
|
// Field Options Provider
|
||||||
|
$this->fieldOptionProviders['rentalInsurance'] = fn (BookingDtoInterface $bookingDto, int $participantIndex, array $options = []) => [
|
||||||
|
'label' => $this->getRentalInsuranceCheckboxLabel($rentalInsuranceServices),
|
||||||
|
'required' => false,
|
||||||
|
'property_path' => 'rentalInsuranceSelected', // Maps to boolean property
|
||||||
|
];
|
||||||
|
|
||||||
|
// Field Handler Processing
|
||||||
|
public function processField(array $submittedData, BookingDtoInterface $bookingDto, int $participantIndex): void
|
||||||
|
{
|
||||||
|
$isRentalInsuranceSelected = (bool) $this->getFieldValue($submittedData, $this->getFieldName());
|
||||||
|
|
||||||
|
// Store boolean value for form state
|
||||||
|
$participant->rentalInsuranceSelected = $isRentalInsuranceSelected;
|
||||||
|
|
||||||
|
// Store Service object for pricing calculations
|
||||||
|
if ($isRentalInsuranceSelected) {
|
||||||
|
$participant->rentalInsurance = $this->findRentalInsuranceService($bookingDto);
|
||||||
|
} else {
|
||||||
|
$participant->rentalInsurance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Benefits of Current Architecture
|
||||||
|
|
||||||
|
1. **Clean Separation**: Boolean properties handle form state, Service objects handle business logic
|
||||||
|
2. **Automatic Pricing Integration**: Service objects are automatically included in pricing calculations
|
||||||
|
3. **Dynamic Visibility**: Fields appear/disappear based on related selections
|
||||||
|
4. **Consistent UX**: Checkbox pattern provides intuitive user interface
|
||||||
|
5. **Validation-Free**: Conditional visibility eliminates need for complex validation rules
|
||||||
|
|
||||||
This system provides a powerful, maintainable foundation for complex conditional field behavior while maintaining clean separation of concerns and extensibility.
|
This system provides a powerful, maintainable foundation for complex conditional field behavior while maintaining clean separation of concerns and extensibility.
|
||||||
+49
-10
@@ -35,7 +35,8 @@ class BookingCreateDto implements BookingDtoInterface
|
|||||||
#### ParticipantDto (`src/Form/Model/ParticipantDto.php`)
|
#### ParticipantDto (`src/Form/Model/ParticipantDto.php`)
|
||||||
- Individual participant data container
|
- Individual participant data container
|
||||||
- Includes personal data, body dimensions, and service selections
|
- Includes personal data, body dimensions, and service selections
|
||||||
- Custom validation for body dimensions when rental services are selected
|
- Body dimensions are hidden unless rental services are selected (conditional visibility)
|
||||||
|
- Rental insurance field with checkbox interface and boolean state tracking
|
||||||
|
|
||||||
```php
|
```php
|
||||||
class ParticipantDto
|
class ParticipantDto
|
||||||
@@ -46,7 +47,7 @@ class ParticipantDto
|
|||||||
public ?\DateTimeImmutable $dateOfBirth = null;
|
public ?\DateTimeImmutable $dateOfBirth = null;
|
||||||
public ?string $email = null;
|
public ?string $email = null;
|
||||||
|
|
||||||
// Body dimensions (conditional)
|
// Body dimensions (hidden unless rental services are selected)
|
||||||
public ?string $height = null;
|
public ?string $height = null;
|
||||||
public ?string $weight = null;
|
public ?string $weight = null;
|
||||||
public ?string $shoeSize = null;
|
public ?string $shoeSize = null;
|
||||||
@@ -56,7 +57,16 @@ class ParticipantDto
|
|||||||
public array $courses = [];
|
public array $courses = [];
|
||||||
public array $additionalServices = [];
|
public array $additionalServices = [];
|
||||||
public array $rentals = [];
|
public array $rentals = [];
|
||||||
// ... other service arrays
|
public ?Service $rentalInsurance = null;
|
||||||
|
public bool $rentalInsuranceSelected = false; // Checkbox state
|
||||||
|
|
||||||
|
// Transportation services
|
||||||
|
public ?Service $transportationOutbound = null;
|
||||||
|
public ?Service $transportationInbound = null;
|
||||||
|
public ?Pickup $pickupOutbound = null;
|
||||||
|
public ?Pickup $pickupInbound = null;
|
||||||
|
public bool $parking = false;
|
||||||
|
public ?Service $parkingService = null;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -87,9 +97,21 @@ Central registry for dynamic field configurations using a provider pattern with
|
|||||||
|
|
||||||
- **`rentals`**: Rental equipment options
|
- **`rentals`**: Rental equipment options
|
||||||
- Date-filtered rental services
|
- Date-filtered rental services
|
||||||
- Triggers body dimension requirements when selected
|
- Controls visibility of body dimensions and rental insurance fields
|
||||||
- Populated from `TOKEN_RENTALS` subtype services
|
- Populated from `TOKEN_RENTALS` subtype services
|
||||||
|
|
||||||
|
- **`rentalInsurance`**: Rental insurance checkbox
|
||||||
|
- Checkbox interface (similar to parking field)
|
||||||
|
- Maps to `rentalInsuranceSelected` boolean property
|
||||||
|
- Only visible when rental services are selected
|
||||||
|
- Automatically manages Service object for pricing calculations
|
||||||
|
- Populated from `TOKEN_RENTAL_INSURANCE` subtype services
|
||||||
|
|
||||||
|
- **`parking`**: Parking service checkbox
|
||||||
|
- Boolean checkbox for self-organized transportation
|
||||||
|
- Only visible when outbound transportation is PKW (car)
|
||||||
|
- Manages both boolean state and Service object for pricing
|
||||||
|
|
||||||
**Provider Pattern Implementation:**
|
**Provider Pattern Implementation:**
|
||||||
```php
|
```php
|
||||||
protected function registerFieldOptionProviders(): void
|
protected function registerFieldOptionProviders(): void
|
||||||
@@ -108,7 +130,8 @@ protected function registerFieldOptionProviders(): void
|
|||||||
|
|
||||||
**CreateFieldStateProvider (`src/Form/Service/CreateFieldStateProvider.php`)**
|
**CreateFieldStateProvider (`src/Form/Service/CreateFieldStateProvider.php`)**
|
||||||
- Manages field states for the booking creation workflow
|
- Manages field states for the booking creation workflow
|
||||||
- Currently implements body dimension requirements for rental services
|
- Controls conditional field visibility and state based on participant data
|
||||||
|
- Implements body dimensions and rental insurance conditional visibility
|
||||||
|
|
||||||
**Field State Types:**
|
**Field State Types:**
|
||||||
- `readonly`: Field is visible but not editable
|
- `readonly`: Field is visible but not editable
|
||||||
@@ -122,10 +145,22 @@ protected function registerFieldStateConditions(): void
|
|||||||
{
|
{
|
||||||
$rentalCondition = new RentalSelectionCondition();
|
$rentalCondition = new RentalSelectionCondition();
|
||||||
|
|
||||||
// Body dimensions become required when rentals are selected
|
// Hide body dimensions section unless rental services are selected
|
||||||
$this->fieldStateConditions['height'] = ['required' => $rentalCondition];
|
$this->fieldStateConditions['bodyDimensions'] = [
|
||||||
$this->fieldStateConditions['weight'] = ['required' => $rentalCondition];
|
'hidden' => CompositeCondition::not($rentalCondition),
|
||||||
$this->fieldStateConditions['shoeSize'] = ['required' => $rentalCondition];
|
];
|
||||||
|
|
||||||
|
// Hide rental insurance unless rental services are selected
|
||||||
|
$this->fieldStateConditions['rentalInsurance'] = [
|
||||||
|
'hidden' => CompositeCondition::not($rentalCondition),
|
||||||
|
];
|
||||||
|
|
||||||
|
// Hide parking unless outbound transportation is PKW (car)
|
||||||
|
$this->fieldStateConditions['parking'] = [
|
||||||
|
'hidden' => CompositeCondition::not(
|
||||||
|
ServiceSubTypeCondition::equals('transportationOutbound', DirectionMapper::SUBTYPE_CAR_API)
|
||||||
|
),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -227,10 +262,14 @@ Base class providing common functionality:
|
|||||||
- **`ParticipantCoursesFieldHandler`**: Course selections filtering
|
- **`ParticipantCoursesFieldHandler`**: Course selections filtering
|
||||||
- **`ParticipantBoardFieldHandler`**: Board/meal options filtering
|
- **`ParticipantBoardFieldHandler`**: Board/meal options filtering
|
||||||
- **`ParticipantRentalsFieldHandler`**: Rental equipment filtering
|
- **`ParticipantRentalsFieldHandler`**: Rental equipment filtering
|
||||||
|
- **`ParticipantRentalInsuranceFieldHandler`**: Rental insurance checkbox handling
|
||||||
|
- Depends on `['dateOfBirth', 'rentals']` (only visible when rentals selected)
|
||||||
|
- Processes boolean checkbox input and converts to Service object
|
||||||
|
- Manages both `rentalInsuranceSelected` (bool) and `rentalInsurance` (Service) properties
|
||||||
|
|
||||||
All service handlers share these characteristics:
|
All service handlers share these characteristics:
|
||||||
- Depend on `dateOfBirth` field (processed first)
|
- Depend on `dateOfBirth` field (processed first)
|
||||||
- Filter selections based on age constraints
|
- Filter selections based on age constraints (except rental insurance which uses conditional visibility)
|
||||||
- Instantiate `ServiceAgeEvaluator` directly when needed
|
- Instantiate `ServiceAgeEvaluator` directly when needed
|
||||||
- Remove invalid selections to prevent form validation errors
|
- Remove invalid selections to prevent form validation errors
|
||||||
- **Store complete Service objects** in ParticipantDto (not just IDs) for pricing calculations
|
- **Store complete Service objects** in ParticipantDto (not just IDs) for pricing calculations
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
- **Parking Services**: Self-organized transport handling ✅
|
- **Parking Services**: Self-organized transport handling ✅
|
||||||
- **Accommodation Services**: Board selection, room assignment ✅
|
- **Accommodation Services**: Board selection, room assignment ✅
|
||||||
- **Activity Services**: Ski passes, courses, rentals ✅
|
- **Activity Services**: Ski passes, courses, rentals ✅
|
||||||
|
- **Rental Insurance**: Checkbox interface with conditional visibility ✅
|
||||||
|
- **Body Dimensions**: Hidden unless rental services selected ✅
|
||||||
- **Additional Services**: Flexible service extension system ✅
|
- **Additional Services**: Flexible service extension system ✅
|
||||||
|
|
||||||
#### Pricing & Display System
|
#### Pricing & Display System
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ final class Constants
|
|||||||
public const TOKEN_ADDITIONAL = 'SON';
|
public const TOKEN_ADDITIONAL = 'SON';
|
||||||
public const TOKEN_BOARD = 'VPF';
|
public const TOKEN_BOARD = 'VPF';
|
||||||
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_PARKING = 'PAR';
|
public const TOKEN_PARKING = 'PAR';
|
||||||
|
|
||||||
public const STATUS_AVAILABLE = 'Frei';
|
public const STATUS_AVAILABLE = 'Frei';
|
||||||
|
|||||||
@@ -147,15 +147,10 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
'clean_xss' => true,
|
'clean_xss' => true,
|
||||||
], $getFieldState('mobile')));
|
], $getFieldState('mobile')));
|
||||||
|
|
||||||
// Add body dimensions with state handling
|
// Add body dimensions with state handling - use shouldIncludeField method
|
||||||
$bodyDimensionStates = ['height' => $getFieldState('height'), 'weight' => $getFieldState('weight'), 'shoeSize' => $getFieldState('shoeSize')];
|
if ($this->fieldStateProvider->shouldIncludeField('bodyDimensions', $bookingDto, $participantIndex)) {
|
||||||
$bodyDimensionOptions = [];
|
$form->add('bodyDimensions', BodyDimensionsType::class);
|
||||||
foreach ($bodyDimensionStates as $fieldName => $fieldState) {
|
|
||||||
if (isset($fieldState['required']) && true === $fieldState['required']) {
|
|
||||||
$bodyDimensionOptions[$fieldName.'_required'] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$form->add('bodyDimensions', BodyDimensionsType::class, $bodyDimensionOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,6 +173,7 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
'additionalServices',
|
'additionalServices',
|
||||||
'board',
|
'board',
|
||||||
'rentals',
|
'rentals',
|
||||||
|
'rentalInsurance',
|
||||||
'skiPass',
|
'skiPass',
|
||||||
'transportationOutbound',
|
'transportationOutbound',
|
||||||
'transportationInbound',
|
'transportationInbound',
|
||||||
@@ -204,7 +200,7 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
// Clear the form and rebuild from scratch with updated states
|
// Clear the form and rebuild from scratch with updated states
|
||||||
|
|
||||||
// Rebuild base fields with updated states
|
// Rebuild base fields with updated states
|
||||||
$baseFields = ['firstName', 'lastName', 'dateOfBirth', 'gender', 'nationality', 'email', 'mobile'];
|
$baseFields = ['firstName', 'lastName', 'dateOfBirth', 'gender', 'nationality', 'email', 'mobile', 'bodyDimensions'];
|
||||||
foreach ($baseFields as $fieldName) {
|
foreach ($baseFields as $fieldName) {
|
||||||
if ($form->has($fieldName)) {
|
if ($form->has($fieldName)) {
|
||||||
$form->remove($fieldName);
|
$form->remove($fieldName);
|
||||||
@@ -215,7 +211,7 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
$this->addBaseFields($form, $bookingDto, $participantIndex);
|
$this->addBaseFields($form, $bookingDto, $participantIndex);
|
||||||
|
|
||||||
// Rebuild dynamic fields
|
// Rebuild dynamic fields
|
||||||
$dynamicFields = ['assignedRoomId', 'remarksRoom', 'courses', 'additionalServices', 'board', 'rentals', 'skiPass', 'transportationOutbound', 'transportationInbound', 'pickupOutbound', 'pickupInbound', 'parking'];
|
$dynamicFields = ['assignedRoomId', 'remarksRoom', 'courses', 'additionalServices', 'board', 'rentals', 'rentalInsurance', 'skiPass', 'transportationOutbound', 'transportationInbound', 'pickupOutbound', 'pickupInbound', 'parking'];
|
||||||
foreach ($dynamicFields as $fieldName) {
|
foreach ($dynamicFields as $fieldName) {
|
||||||
if ($form->has($fieldName)) {
|
if ($form->has($fieldName)) {
|
||||||
$form->remove($fieldName);
|
$form->remove($fieldName);
|
||||||
@@ -238,6 +234,7 @@ class BookingCreateParticipantType extends AbstractType
|
|||||||
'additionalServices' => ChoiceType::class,
|
'additionalServices' => ChoiceType::class,
|
||||||
'board' => ChoiceType::class,
|
'board' => ChoiceType::class,
|
||||||
'rentals' => ChoiceType::class,
|
'rentals' => ChoiceType::class,
|
||||||
|
'rentalInsurance' => CheckboxType::class,
|
||||||
'skiPass' => ChoiceType::class,
|
'skiPass' => ChoiceType::class,
|
||||||
'transportationOutbound' => ChoiceType::class,
|
'transportationOutbound' => ChoiceType::class,
|
||||||
'transportationInbound' => ChoiceType::class,
|
'transportationInbound' => ChoiceType::class,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
|
||||||
#[AppAssert\Participant(groups: ['booking_edit'])]
|
#[AppAssert\Participant(groups: ['booking_edit'])]
|
||||||
#[Assert\Callback('validateBodyDimensionsForRentals', groups: ['booking_create_step_2', 'booking_edit'])]
|
|
||||||
class ParticipantDto
|
class ParticipantDto
|
||||||
{
|
{
|
||||||
public ?int $index = null;
|
public ?int $index = null;
|
||||||
@@ -51,6 +50,10 @@ class ParticipantDto
|
|||||||
public ?Service $skiPass = null;
|
public ?Service $skiPass = null;
|
||||||
public array $board = [];
|
public array $board = [];
|
||||||
public array $rentals = [];
|
public array $rentals = [];
|
||||||
|
public ?Service $rentalInsurance = null;
|
||||||
|
|
||||||
|
// Rental insurance checkbox state (boolean: true if rental insurance requested)
|
||||||
|
public bool $rentalInsuranceSelected = false;
|
||||||
|
|
||||||
// Transportation services with improved naming (outbound/inbound)
|
// Transportation services with improved naming (outbound/inbound)
|
||||||
public ?Service $transportationOutbound = null;
|
public ?Service $transportationOutbound = null;
|
||||||
@@ -103,43 +106,4 @@ class ParticipantDto
|
|||||||
return 'O' === $this->status;
|
return 'O' === $this->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates that body dimension fields are provided when rental services are selected.
|
|
||||||
*
|
|
||||||
* This callback validator ensures that height, weight, and shoe size are mandatory
|
|
||||||
* when the participant has selected any rental services. This is required for
|
|
||||||
* proper equipment sizing and rental fulfillment.
|
|
||||||
*
|
|
||||||
* @param ExecutionContextInterface $context The validation context
|
|
||||||
*/
|
|
||||||
public function validateBodyDimensionsForRentals(ExecutionContextInterface $context): void
|
|
||||||
{
|
|
||||||
$rentals = $this->rentals ?? [];
|
|
||||||
|
|
||||||
// If no rental services are selected, body dimensions are not required
|
|
||||||
if (empty($rentals)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate height field
|
|
||||||
if (true === empty($this->height)) {
|
|
||||||
$context->buildViolation('Deine Körpergröße ist erforderlich wenn Leihmaterial ausgewählt wurde')
|
|
||||||
->atPath('height')
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate weight field
|
|
||||||
if (true === empty($this->weight)) {
|
|
||||||
$context->buildViolation('Dein Gewicht ist erforderlich wenn Leihmaterial ausgewählt wurde')
|
|
||||||
->atPath('weight')
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate shoe size field
|
|
||||||
if (true === empty($this->shoeSize)) {
|
|
||||||
$context->buildViolation('Deine Schuhgröße ist erforderlich wenn Leihmaterial ausgewählt wurde')
|
|
||||||
->atPath('shoeSize')
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use App\Form\Service\Condition\ServiceSubTypeCondition;
|
|||||||
* state functionality provided by AbstractFieldStateProvider.
|
* state functionality provided by AbstractFieldStateProvider.
|
||||||
*
|
*
|
||||||
* Current field state conditions:
|
* Current field state conditions:
|
||||||
* - Body dimension fields become required when rental services are selected
|
* - Body dimension fields are hidden unless rental services are selected
|
||||||
* - Age-dependent service fields are hidden until birth date is provided
|
* - Age-dependent service fields are hidden until birth date is provided
|
||||||
* - Transportation pickup fields are hidden by default, shown only when transportation type is BUS
|
* - Transportation pickup fields are hidden by default, shown only when transportation type is BUS
|
||||||
* - Parking field is hidden by default, shown only when outbound transportation is PKW
|
* - Parking field is hidden by default, shown only when outbound transportation is PKW
|
||||||
@@ -56,17 +56,9 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
|||||||
{
|
{
|
||||||
$rentalCondition = new RentalSelectionCondition();
|
$rentalCondition = new RentalSelectionCondition();
|
||||||
|
|
||||||
// Make body dimension fields required when rental services are selected
|
// Hide body dimensions section unless rental services are selected
|
||||||
$this->fieldStateConditions['height'] = [
|
$this->fieldStateConditions['bodyDimensions'] = [
|
||||||
'required' => $rentalCondition,
|
'hidden' => CompositeCondition::not($rentalCondition),
|
||||||
];
|
|
||||||
|
|
||||||
$this->fieldStateConditions['weight'] = [
|
|
||||||
'required' => $rentalCondition,
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->fieldStateConditions['shoeSize'] = [
|
|
||||||
'required' => $rentalCondition,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Hide age-dependent fields when no date of birth is provided
|
// Hide age-dependent fields when no date of birth is provided
|
||||||
@@ -121,6 +113,11 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Show rental insurance only when rental services are selected (hidden by default)
|
||||||
|
$this->fieldStateConditions['rentalInsurance'] = [
|
||||||
|
'hidden' => CompositeCondition::not($rentalCondition),
|
||||||
|
];
|
||||||
|
|
||||||
// Example field state conditions would be registered here
|
// Example field state conditions would be registered here
|
||||||
// For demonstration purposes, here are some example patterns:
|
// For demonstration purposes, here are some example patterns:
|
||||||
|
|
||||||
|
|||||||
@@ -183,6 +183,13 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
|||||||
'choice_label' => fn (?Service $service) => $this->formatServiceLabelWithPrice($service),
|
'choice_label' => fn (?Service $service) => $this->formatServiceLabelWithPrice($service),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Rental insurance field provider - provides rental insurance options when rental services are selected
|
||||||
|
$this->fieldOptionProviders['rentalInsurance'] = fn (BookingDtoInterface $bookingDto, int $participantIndex, array $options = []) => [
|
||||||
|
'label' => $this->getRentalInsuranceCheckboxLabel($bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_RENTAL_INSURANCE, true, true)),
|
||||||
|
'required' => false,
|
||||||
|
'property_path' => 'rentalInsuranceSelected',
|
||||||
|
];
|
||||||
|
|
||||||
// Skipass field provider - provides age-appropriate skipass options from travel data filtered by date range
|
// Skipass field provider - provides age-appropriate skipass options from travel data filtered by date range
|
||||||
$this->fieldOptionProviders['skiPass'] = fn (BookingDtoInterface $bookingDto, int $participantIndex, array $options = []) => [
|
$this->fieldOptionProviders['skiPass'] = fn (BookingDtoInterface $bookingDto, int $participantIndex, array $options = []) => [
|
||||||
'label' => 'Skipass',
|
'label' => 'Skipass',
|
||||||
@@ -477,4 +484,16 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
|||||||
return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates label for rental insurance checkbox including pricing information.
|
||||||
|
*/
|
||||||
|
private function getRentalInsuranceCheckboxLabel(array $rentalInsuranceServices): string
|
||||||
|
{
|
||||||
|
if (empty($rentalInsuranceServices)) {
|
||||||
|
return 'Leihmaterial-Versicherung';
|
||||||
|
}
|
||||||
|
$rentalInsuranceService = reset($rentalInsuranceServices); // Get the first (and only) rental insurance service
|
||||||
|
return $this->formatServiceLabelWithPrice($rentalInsuranceService);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Constants;
|
||||||
|
use App\BusProNet\Model\Service;
|
||||||
|
use App\Form\Model\BookingDtoInterface;
|
||||||
|
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles processing of the rentalInsurance field for booking participants.
|
||||||
|
*
|
||||||
|
* This handler manages rental insurance selections for participants in the booking
|
||||||
|
* creation process. It processes the rentalInsurance field from form submissions,
|
||||||
|
* validates the selection, and updates the participant DTO with the valid selection.
|
||||||
|
*
|
||||||
|
* The rental insurance field is only shown when the participant has selected
|
||||||
|
* rental services, creating a dependency chain where rental insurance depends
|
||||||
|
* on rental selections.
|
||||||
|
*
|
||||||
|
* Dependencies: dateOfBirth (for age evaluation) and rentals (for field visibility)
|
||||||
|
*/
|
||||||
|
class ParticipantRentalInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the form field name this handler processes.
|
||||||
|
*
|
||||||
|
* @return string The field name 'rentalInsurance'
|
||||||
|
*/
|
||||||
|
public function getFieldName(): string
|
||||||
|
{
|
||||||
|
return 'rentalInsurance';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the field dependencies for proper processing order.
|
||||||
|
*
|
||||||
|
* This handler depends on both dateOfBirth (for age evaluation) and rentals
|
||||||
|
* (because rental insurance is only relevant when rentals are selected).
|
||||||
|
*
|
||||||
|
* @return string[] Array containing 'dateOfBirth' and 'rentals' dependencies
|
||||||
|
*/
|
||||||
|
public function getDependencies(): array
|
||||||
|
{
|
||||||
|
return ['dateOfBirth', 'rentals'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if this handler should process the field based on submitted data.
|
||||||
|
*
|
||||||
|
* For service selection fields like rental insurance, 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
|
||||||
|
* rental insurance is selected.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $submittedData The submitted participant form data
|
||||||
|
* @param int $participantIndex The index of the participant being processed
|
||||||
|
*
|
||||||
|
* @return bool Always returns true for service selection fields
|
||||||
|
*/
|
||||||
|
public function shouldProcess(array $submittedData, int $participantIndex): bool
|
||||||
|
{
|
||||||
|
return true; // Always process to handle deselection cases
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the rentalInsurance field for a specific participant.
|
||||||
|
*
|
||||||
|
* This method extracts the rental insurance selection from submitted form data,
|
||||||
|
* validates the selection against the participant's age constraints, and
|
||||||
|
* updates the participant DTO with the valid selection. If the rental insurance
|
||||||
|
* is no longer appropriate for the participant's age, it is automatically cleared.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $submittedData The submitted participant form data
|
||||||
|
* @param BookingDtoInterface $bookingDto The booking DTO to update (create or edit)
|
||||||
|
* @param int $participantIndex The index of the participant being processed
|
||||||
|
*/
|
||||||
|
public function processField(array $submittedData, BookingDtoInterface $bookingDto, int $participantIndex): void
|
||||||
|
{
|
||||||
|
// Safely get the participant object, returning early if not found
|
||||||
|
$participant = $this->getParticipant($bookingDto, $participantIndex);
|
||||||
|
if (null === $participant) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if rental insurance should be visible based on rental selections
|
||||||
|
$hasRentals = false === empty($participant->rentals);
|
||||||
|
|
||||||
|
if (false === $hasRentals) {
|
||||||
|
// If no rentals are selected, clear rental insurance data
|
||||||
|
$participant->rentalInsuranceSelected = false;
|
||||||
|
$participant->rentalInsurance = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract checkbox value from submitted data (this comes from the rentalInsuranceSelected property)
|
||||||
|
$rentalInsuranceSelected = $this->getFieldValue($submittedData, $this->getFieldName());
|
||||||
|
$isRentalInsuranceSelected = (bool) $rentalInsuranceSelected;
|
||||||
|
|
||||||
|
// Store boolean value
|
||||||
|
$participant->rentalInsuranceSelected = $isRentalInsuranceSelected;
|
||||||
|
|
||||||
|
// Store service object based on checkbox state for pricing calculations
|
||||||
|
if (true === $isRentalInsuranceSelected) {
|
||||||
|
$participant->rentalInsurance = $this->findRentalInsuranceService($bookingDto);
|
||||||
|
} else {
|
||||||
|
$participant->rentalInsurance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the rental insurance service from available services.
|
||||||
|
*
|
||||||
|
* Gets the first (and typically only) rental insurance service.
|
||||||
|
* Returns null if no rental insurance services are available.
|
||||||
|
*
|
||||||
|
* @param BookingDtoInterface $bookingDto The booking DTO containing travel data
|
||||||
|
*
|
||||||
|
* @return Service|null The rental insurance service object, or null if not found
|
||||||
|
*/
|
||||||
|
private function findRentalInsuranceService(BookingDtoInterface $bookingDto): ?Service
|
||||||
|
{
|
||||||
|
$rentalInsuranceServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_RENTAL_INSURANCE, true, true);
|
||||||
|
|
||||||
|
if (empty($rentalInsuranceServices)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return reset($rentalInsuranceServices); // Get the first (and typically only) rental insurance service
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,11 +26,6 @@ class ParticipantRentalsFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
return 'rentals';
|
return 'rentals';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDependencies(): array
|
|
||||||
{
|
|
||||||
return ['dateOfBirth'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if this handler should process the field based on submitted data.
|
* Determines if this handler should process the field based on submitted data.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -337,6 +337,7 @@ class BookingPriceCalculatorService
|
|||||||
Constants::TOKEN_SKI_PASS => 'Skipässe',
|
Constants::TOKEN_SKI_PASS => 'Skipässe',
|
||||||
Constants::TOKEN_ADDITIONAL => 'Zusatzleistungen',
|
Constants::TOKEN_ADDITIONAL => 'Zusatzleistungen',
|
||||||
Constants::TOKEN_BOARD => 'Verpflegung',
|
Constants::TOKEN_BOARD => 'Verpflegung',
|
||||||
|
Constants::TOKEN_RENTAL_INSURANCE => 'Leihmaterial-Versicherung',
|
||||||
'transportation' => 'Beförderung',
|
'transportation' => 'Beförderung',
|
||||||
'rentals' => 'Leihmaterial', // Normalized rental subtype
|
'rentals' => 'Leihmaterial', // Normalized rental subtype
|
||||||
];
|
];
|
||||||
@@ -354,11 +355,15 @@ class BookingPriceCalculatorService
|
|||||||
*/
|
*/
|
||||||
private function aggregateParticipantServices(ParticipantDto $participant, array &$serviceAggregation): void
|
private function aggregateParticipantServices(ParticipantDto $participant, array &$serviceAggregation): void
|
||||||
{
|
{
|
||||||
// Handle single service selections (skiPass)
|
// Handle single service selections (skiPass, 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, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null !== $participant->rentalInsurance && null !== $participant->rentalInsurance->price) {
|
||||||
|
$this->addToServiceAggregation($serviceAggregation, $participant->rentalInsurance, 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Handle multiple service selections
|
// Handle multiple service selections
|
||||||
$multipleServiceArrays = [
|
$multipleServiceArrays = [
|
||||||
'courses' => $participant->courses,
|
'courses' => $participant->courses,
|
||||||
|
|||||||
@@ -41,11 +41,13 @@
|
|||||||
{{ form_row(participant.email) }}
|
{{ form_row(participant.email) }}
|
||||||
{{ form_row(participant.mobile) }}
|
{{ form_row(participant.mobile) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 gap-4">
|
{% if participant.bodyDimensions is defined %}
|
||||||
{{ form_row(participant.bodyDimensions.height) }}
|
<div class="grid grid-cols-2 gap-4">
|
||||||
{{ form_row(participant.bodyDimensions.shoeSize) }}
|
{{ form_row(participant.bodyDimensions.height) }}
|
||||||
{{ form_row(participant.bodyDimensions.weight) }}
|
{{ form_row(participant.bodyDimensions.shoeSize) }}
|
||||||
</div>
|
{{ form_row(participant.bodyDimensions.weight) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="grid grid-cols-2 gap-4">
|
<div class="grid grid-cols-2 gap-4">
|
||||||
{{ form_row(participant.assignedRoomId, {
|
{{ form_row(participant.assignedRoomId, {
|
||||||
'attr': {
|
'attr': {
|
||||||
@@ -113,6 +115,15 @@
|
|||||||
}
|
}
|
||||||
}) }}
|
}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if participant.rentalInsurance is defined %}
|
||||||
|
{{ form_row(participant.rentalInsurance, {
|
||||||
|
'attr': {
|
||||||
|
'hx-trigger': 'change',
|
||||||
|
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||||
|
'hx-swap': 'none'
|
||||||
|
}
|
||||||
|
}) }}
|
||||||
|
{% endif %}
|
||||||
{% if participant.board is defined %}
|
{% if participant.board is defined %}
|
||||||
{{ form_row(participant.board, {
|
{{ form_row(participant.board, {
|
||||||
'attr': {
|
'attr': {
|
||||||
|
|||||||
Reference in New Issue
Block a user