74 lines
2.8 KiB
PHP
74 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Form\Service;
|
|
|
|
use App\Form\Model\BookingDto;
|
|
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
|
|
|
/**
|
|
* Handles bulk insurance booking checkbox for the applicant (first participant).
|
|
*
|
|
* This handler only manages the checkbox state - it does NOT assign insurance to
|
|
* dependent participants. The actual bulk insurance assignment happens in the
|
|
* BookingDataProcessor during API submission, keeping the form layer clean and
|
|
* avoiding cross-participant modifications in field handlers.
|
|
*
|
|
* The checkbox state is used by:
|
|
* - Templates: To display "wie Anmelder" for dependent participants
|
|
* - Processors: To apply applicant's insurance to all participants before API submission
|
|
*/
|
|
class ParticipantBulkInsuranceFieldHandler extends AbstractParticipantFieldHandler
|
|
{
|
|
public function getFieldName(): string
|
|
{
|
|
return 'bulkInsuranceBooking';
|
|
}
|
|
|
|
public function getDependencies(): array
|
|
{
|
|
// No dependencies - just manages checkbox state
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Determines if this handler should process the field.
|
|
*
|
|
* Only process for the applicant (index 0). Dependent participants don't have
|
|
* the bulkInsuranceBooking checkbox - their insurance is controlled by the handler.
|
|
*
|
|
* @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 True if this is the applicant, false otherwise
|
|
*/
|
|
public function shouldProcess(array $submittedData, string $mode, int $participantIndex): bool
|
|
{
|
|
return 0 === $participantIndex; // Only process for applicant
|
|
}
|
|
|
|
/**
|
|
* Processes the bulk insurance booking checkbox for the applicant.
|
|
*
|
|
* This handler ONLY stores the checkbox state. The actual insurance assignment
|
|
* to dependent participants is handled by BookingDataProcessor during API submission.
|
|
*
|
|
* @param array<string, mixed> $submittedData The submitted participant form data
|
|
* @param BookingDto $bookingDto The booking DTO to update
|
|
* @param int $participantIndex The index of the participant (must be 0)
|
|
*/
|
|
public function processField(array $submittedData, BookingDto $bookingDto, int $participantIndex): void
|
|
{
|
|
$participant = $this->getParticipant($bookingDto, $participantIndex);
|
|
if (null === $participant) {
|
|
return;
|
|
}
|
|
|
|
// Get checkbox value from submitted data and store it
|
|
$bulkInsuranceBooking = $this->getFieldValue($submittedData, $this->getFieldName());
|
|
$participant->bulkInsuranceBooking = (bool) $bulkInsuranceBooking;
|
|
}
|
|
}
|