86 lines
3.4 KiB
PHP
86 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Form\Service\Condition;
|
|
|
|
use App\Form\Model\BookingDto;
|
|
use App\Form\Service\Contract\FieldConditionInterface;
|
|
|
|
/**
|
|
* Condition that determines if the first participant's personal data should be read-only.
|
|
*
|
|
* It fires only where participant[0] IS the booking's applicant, which
|
|
* BookingDto::isFirstParticipantApplicant() decides: the booking-level choice in create mode,
|
|
* and anmelder vs. participant[0] person id in edit mode. Internal agency bookings answer
|
|
* false there, which preserves the behaviour this class used to spell out itself.
|
|
*
|
|
* Business Rules:
|
|
* - CREATE mode (anonymous user): First participant data is editable (user must fill it in)
|
|
* - CREATE mode (logged-in, participant[0] is the applicant): data is prepopulated, read-only
|
|
* - CREATE mode (applicant does not travel, or internal agency): participant[0] is an ordinary
|
|
* traveller, data is editable
|
|
* - EDIT mode (participant[0] is the applicant): always read-only
|
|
* - EDIT mode (split booking, or internal agency): participant[0] ≠ applicant, editable here
|
|
* (PersonalDataMutabilityCondition still applies separately)
|
|
*
|
|
* Non-first participants are never affected by this condition - they return false here
|
|
* but may still be read-only via PersonalDataMutabilityCondition in edit mode.
|
|
*/
|
|
class FirstParticipantReadOnlyCondition implements FieldConditionInterface
|
|
{
|
|
/**
|
|
* Evaluates if personal data fields should be shown as static text for the first participant.
|
|
*
|
|
* @param BookingDto $bookingDto The booking data
|
|
* @param int $participantIndex The index of the participant being evaluated
|
|
* @param array<string, mixed> $formData Current form data (unused)
|
|
*
|
|
* @return bool True if fields should be shown as static text (read-only)
|
|
*/
|
|
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
|
{
|
|
// This condition only applies to the first participant.
|
|
// Non-first participants: return false here, but may still be read-only via PersonalDataMutabilityCondition
|
|
if (0 !== $participantIndex) {
|
|
return false;
|
|
}
|
|
|
|
// participant[0] is a traveller in their own right: nothing to protect here.
|
|
if (false === $bookingDto->isFirstParticipantApplicant()) {
|
|
return false;
|
|
}
|
|
|
|
if (BookingDto::MODE_CREATE === $bookingDto->getMode()) {
|
|
// Anonymous user (no personId) = must fill in data = editable
|
|
return null !== $bookingDto->getParticipant($participantIndex)?->personId;
|
|
}
|
|
|
|
// EDIT mode: participant[0] is the applicant, whose record is owned by the account.
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Returns field names that this condition depends on.
|
|
*
|
|
* This condition is based on the applicant split and personId, which are set during
|
|
* initialization and don't change during form interaction, so no field dependencies.
|
|
*
|
|
* @return string[] Empty array - no field dependencies
|
|
*/
|
|
public function getDependentFields(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Returns a human-readable description of this condition.
|
|
*
|
|
* @return string Description of the first participant read-only logic
|
|
*/
|
|
public function getDescription(): string
|
|
{
|
|
return 'First participant personal data is read-only when they are also the applicant';
|
|
}
|
|
}
|