wip: rentals insurance field
This commit is contained in:
@@ -15,6 +15,7 @@ final class Constants
|
||||
public const TOKEN_ADDITIONAL = 'SON';
|
||||
public const TOKEN_BOARD = 'VPF';
|
||||
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 STATUS_AVAILABLE = 'Frei';
|
||||
|
||||
@@ -147,15 +147,10 @@ class BookingCreateParticipantType extends AbstractType
|
||||
'clean_xss' => true,
|
||||
], $getFieldState('mobile')));
|
||||
|
||||
// Add body dimensions with state handling
|
||||
$bodyDimensionStates = ['height' => $getFieldState('height'), 'weight' => $getFieldState('weight'), 'shoeSize' => $getFieldState('shoeSize')];
|
||||
$bodyDimensionOptions = [];
|
||||
foreach ($bodyDimensionStates as $fieldName => $fieldState) {
|
||||
if (isset($fieldState['required']) && true === $fieldState['required']) {
|
||||
$bodyDimensionOptions[$fieldName.'_required'] = true;
|
||||
}
|
||||
// Add body dimensions with state handling - use shouldIncludeField method
|
||||
if ($this->fieldStateProvider->shouldIncludeField('bodyDimensions', $bookingDto, $participantIndex)) {
|
||||
$form->add('bodyDimensions', BodyDimensionsType::class);
|
||||
}
|
||||
$form->add('bodyDimensions', BodyDimensionsType::class, $bodyDimensionOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,6 +173,7 @@ class BookingCreateParticipantType extends AbstractType
|
||||
'additionalServices',
|
||||
'board',
|
||||
'rentals',
|
||||
'rentalInsurance',
|
||||
'skiPass',
|
||||
'transportationOutbound',
|
||||
'transportationInbound',
|
||||
@@ -204,7 +200,7 @@ class BookingCreateParticipantType extends AbstractType
|
||||
// Clear the form and rebuild from scratch 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) {
|
||||
if ($form->has($fieldName)) {
|
||||
$form->remove($fieldName);
|
||||
@@ -215,7 +211,7 @@ class BookingCreateParticipantType extends AbstractType
|
||||
$this->addBaseFields($form, $bookingDto, $participantIndex);
|
||||
|
||||
// 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) {
|
||||
if ($form->has($fieldName)) {
|
||||
$form->remove($fieldName);
|
||||
@@ -238,6 +234,7 @@ class BookingCreateParticipantType extends AbstractType
|
||||
'additionalServices' => ChoiceType::class,
|
||||
'board' => ChoiceType::class,
|
||||
'rentals' => ChoiceType::class,
|
||||
'rentalInsurance' => CheckboxType::class,
|
||||
'skiPass' => ChoiceType::class,
|
||||
'transportationOutbound' => ChoiceType::class,
|
||||
'transportationInbound' => ChoiceType::class,
|
||||
|
||||
@@ -10,7 +10,6 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
#[AppAssert\Participant(groups: ['booking_edit'])]
|
||||
#[Assert\Callback('validateBodyDimensionsForRentals', groups: ['booking_create_step_2', 'booking_edit'])]
|
||||
class ParticipantDto
|
||||
{
|
||||
public ?int $index = null;
|
||||
@@ -51,6 +50,10 @@ class ParticipantDto
|
||||
public ?Service $skiPass = null;
|
||||
public array $board = [];
|
||||
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)
|
||||
public ?Service $transportationOutbound = null;
|
||||
@@ -103,43 +106,4 @@ class ParticipantDto
|
||||
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.
|
||||
*
|
||||
* 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
|
||||
* - 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
|
||||
@@ -56,17 +56,9 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
{
|
||||
$rentalCondition = new RentalSelectionCondition();
|
||||
|
||||
// Make body dimension fields required when rental services are selected
|
||||
$this->fieldStateConditions['height'] = [
|
||||
'required' => $rentalCondition,
|
||||
];
|
||||
|
||||
$this->fieldStateConditions['weight'] = [
|
||||
'required' => $rentalCondition,
|
||||
];
|
||||
|
||||
$this->fieldStateConditions['shoeSize'] = [
|
||||
'required' => $rentalCondition,
|
||||
// Hide body dimensions section unless rental services are selected
|
||||
$this->fieldStateConditions['bodyDimensions'] = [
|
||||
'hidden' => CompositeCondition::not($rentalCondition),
|
||||
];
|
||||
|
||||
// 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
|
||||
// For demonstration purposes, here are some example patterns:
|
||||
|
||||
|
||||
@@ -183,6 +183,13 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'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
|
||||
$this->fieldOptionProviders['skiPass'] = fn (BookingDtoInterface $bookingDto, int $participantIndex, array $options = []) => [
|
||||
'label' => 'Skipass',
|
||||
@@ -477,4 +484,16 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
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';
|
||||
}
|
||||
|
||||
public function getDependencies(): array
|
||||
{
|
||||
return ['dateOfBirth'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_ADDITIONAL => 'Zusatzleistungen',
|
||||
Constants::TOKEN_BOARD => 'Verpflegung',
|
||||
Constants::TOKEN_RENTAL_INSURANCE => 'Leihmaterial-Versicherung',
|
||||
'transportation' => 'Beförderung',
|
||||
'rentals' => 'Leihmaterial', // Normalized rental subtype
|
||||
];
|
||||
@@ -354,11 +355,15 @@ class BookingPriceCalculatorService
|
||||
*/
|
||||
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) {
|
||||
$this->addToServiceAggregation($serviceAggregation, $participant->skiPass, 1);
|
||||
}
|
||||
|
||||
if (null !== $participant->rentalInsurance && null !== $participant->rentalInsurance->price) {
|
||||
$this->addToServiceAggregation($serviceAggregation, $participant->rentalInsurance, 1);
|
||||
}
|
||||
|
||||
// Handle multiple service selections
|
||||
$multipleServiceArrays = [
|
||||
'courses' => $participant->courses,
|
||||
|
||||
Reference in New Issue
Block a user