wip: finalize implementation
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
@@ -45,13 +46,11 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
* @param ParticipantRoomChoiceLoaderFactory $roomChoiceLoaderFactory Factory for creating room choice loaders
|
||||
* @param ServiceAvailabilityCalculator $serviceAvailabilityCalculator Service for calculating dynamic availability
|
||||
* @param InsuranceMatchingService $insuranceMatchingService Service for matching insurances to participants
|
||||
* @param UrlGeneratorInterface $urlGenerator URL generator for HTMX endpoints
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ParticipantRoomChoiceLoaderFactory $roomChoiceLoaderFactory,
|
||||
private readonly ServiceAvailabilityCalculator $serviceAvailabilityCalculator,
|
||||
private readonly InsuranceMatchingService $insuranceMatchingService,
|
||||
private readonly UrlGeneratorInterface $urlGenerator,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -435,7 +434,18 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'insurances' => $this->getEligibleInsurances($bookingDto, $participantIndex),
|
||||
'choices' => $this->getEligibleInsurances($bookingDto, $participantIndex),
|
||||
'choice_value' => 'id',
|
||||
'choice_label' => function (?Insurance $insurance) {
|
||||
$label = $insurance->label;
|
||||
|
||||
if (null !== $insurance->price && $insurance->price > 0) {
|
||||
$label .= sprintf(' (€%s)', number_format($insurance->price, 2, ',', '.'));
|
||||
}
|
||||
|
||||
return $label;
|
||||
},
|
||||
'placeholder' => 'Keine Versicherung gewünscht',
|
||||
];
|
||||
|
||||
// Future field providers would be added here, for example:
|
||||
|
||||
@@ -76,7 +76,7 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
/**
|
||||
* Determines if this handler should process the field based on submitted data.
|
||||
*
|
||||
* Insurance handler should NOT process in edit mode because the BPN API does not
|
||||
* Insurance handler should NOT procefss in edit mode because the BPN API does not
|
||||
* return insurance data. In edit mode, insurance data must be preserved as-is
|
||||
* and passed through to the update endpoint unchanged.
|
||||
*
|
||||
@@ -172,8 +172,6 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
// Insurance not found - clear selection
|
||||
$participant->insurance = null;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle form resubmission with existing insurance (automatic reassignment check)
|
||||
@@ -241,15 +239,15 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
/**
|
||||
* Finds an insurance by ID from the available insurances array.
|
||||
*
|
||||
* @param array<Insurance> $insurances Array of available insurances
|
||||
* @param string|int $insuranceId The insurance ID to find
|
||||
* @param array<Insurance> $insurances Array of available insurances
|
||||
* @param string $insuranceId The insurance ID to find
|
||||
*
|
||||
* @return Insurance|null The found insurance or null if not found
|
||||
*/
|
||||
private function findInsuranceById(array $insurances, string|int $insuranceId): ?Insurance
|
||||
private function findInsuranceById(array $insurances, string $insuranceId): ?Insurance
|
||||
{
|
||||
foreach ($insurances as $insurance) {
|
||||
if ($insurance->id === $insuranceId || (string) $insurance->id === (string) $insuranceId) {
|
||||
if ($insurance->id === $insuranceId) {
|
||||
return $insurance;
|
||||
}
|
||||
}
|
||||
@@ -268,7 +266,7 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
private function isInsuranceInList(Insurance $targetInsurance, array $insuranceList): bool
|
||||
{
|
||||
foreach ($insuranceList as $insurance) {
|
||||
if ($insurance->id === $targetInsurance->id || (string) $insurance->id === (string) $targetInsurance->id) {
|
||||
if ($insurance->id === $targetInsurance->id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -282,14 +280,14 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
* This is used to distinguish between a new user selection and a form resubmission
|
||||
* with the existing insurance selection (e.g., when user adds rentals that change travel price).
|
||||
*
|
||||
* @param string|int $selectedInsuranceId The insurance ID from form submission
|
||||
* @param string $selectedInsuranceId The insurance ID from form submission
|
||||
* @param Insurance $currentInsurance The currently assigned insurance from DTO
|
||||
*
|
||||
* @return bool True if they represent the same insurance
|
||||
*/
|
||||
private function isSameInsurance(string|int $selectedInsuranceId, Insurance $currentInsurance): bool
|
||||
private function isSameInsurance(string $selectedInsuranceId, Insurance $currentInsurance): bool
|
||||
{
|
||||
return (string) $currentInsurance->id === (string) $selectedInsuranceId;
|
||||
return $currentInsurance->id === $selectedInsuranceId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,10 +79,9 @@ class ParticipantSkiPassFieldHandler extends AbstractParticipantFieldHandler
|
||||
* selection. If the skipass is no longer appropriate for the participant's
|
||||
* age or exceeds the travel date range, it is automatically cleared.
|
||||
*
|
||||
* @param array<string, mixed> $submittedData The submitted participant form data
|
||||
* @param string $mode The booking mode (BookingDto::MODE_CREATE or MODE_EDIT)
|
||||
* @param BookingDto $bookingDto The booking DTO to update (create or edit)
|
||||
* @param int $participantIndex The index of the participant being processed
|
||||
* @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
|
||||
{
|
||||
|
||||
@@ -68,9 +68,6 @@ class ParticipantTransportationInboundFieldHandler extends AbstractParticipantFi
|
||||
|
||||
// Update participant with validated selection
|
||||
$participant->transportationInbound = $validSelection;
|
||||
|
||||
// Backward compatibility: also update deprecated property
|
||||
$participant->transportationServiceFro = $validSelection;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,9 +68,6 @@ class ParticipantTransportationOutboundFieldHandler extends AbstractParticipantF
|
||||
|
||||
// Update participant with validated selection
|
||||
$participant->transportationOutbound = $validSelection;
|
||||
|
||||
// Backward compatibility: also update deprecated property
|
||||
$participant->transportationServiceTo = $validSelection;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user