wip: bulk insurance refactoring
This commit is contained in:
@@ -8,6 +8,7 @@ use App\BusProNet\Model\Insurance;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
use App\Service\InsuranceMatchingService;
|
||||
use App\Service\InsuranceTypeFilterService;
|
||||
|
||||
/**
|
||||
* Handles processing of the insurance field for booking participants.
|
||||
@@ -35,6 +36,7 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
{
|
||||
public function __construct(
|
||||
private readonly InsuranceMatchingService $insuranceMatchingService,
|
||||
private readonly InsuranceTypeFilterService $insuranceTypeFilterService,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -94,7 +96,7 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
public function shouldProcess(array $submittedData, string $mode, int $participantIndex): bool
|
||||
{
|
||||
// In edit mode, insurance data is not available from API - skip processing entirely
|
||||
if ($mode === BookingDto::MODE_EDIT) {
|
||||
if (BookingDto::MODE_EDIT === $mode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -118,7 +120,7 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
* participant data and automatically reassigns to the correct price tier if needed.
|
||||
*
|
||||
* @param array<string, mixed> $submittedData The submitted participant form data
|
||||
* @param BookingDto $bookingDto The booking DTO to update (create or edit)
|
||||
* @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
|
||||
@@ -132,9 +134,8 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
$currentInsurance = $participant->insurance;
|
||||
$availableInsurances = $bookingDto->travel->insurances ?? [];
|
||||
|
||||
// Exclude complementary insurances from reassignment logic
|
||||
// They are only available as part of packages and cannot be directly selected
|
||||
$availableInsurances = array_filter($availableInsurances, fn ($insurance) => !$insurance->complementary);
|
||||
// Exclude complementary insurances (only available as part of packages)
|
||||
$availableInsurances = $this->insuranceTypeFilterService->filterNonComplementary($availableInsurances);
|
||||
|
||||
// Determine if this is a new user selection or just form resubmission
|
||||
$isNewSelection = null !== $selectedInsuranceId
|
||||
@@ -214,7 +215,7 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
* Currently no field state modifications are needed for insurance selection.
|
||||
*
|
||||
* @param array<string, mixed> $submittedData The submitted participant form data
|
||||
* @param BookingDto $bookingDto The booking DTO (potentially modified by processing)
|
||||
* @param BookingDto $bookingDto The booking DTO (potentially modified by processing)
|
||||
* @param int $participantIndex The participant index being processed
|
||||
*
|
||||
* @return array<string, array<string, mixed>> Empty array - no field state modifications
|
||||
@@ -239,8 +240,8 @@ class ParticipantInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
||||
/**
|
||||
* Finds an insurance by ID from the available insurances array.
|
||||
*
|
||||
* @param array<Insurance> $insurances Array of available insurances
|
||||
* @param string $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
|
||||
*/
|
||||
@@ -280,8 +281,8 @@ 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 $selectedInsuranceId The insurance ID from form submission
|
||||
* @param Insurance $currentInsurance The currently assigned insurance from DTO
|
||||
* @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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user