feat: special treatment of participants with age 0-2 (babies)
This commit is contained in:
@@ -78,7 +78,8 @@ class ParticipantDto
|
||||
public array $courses = [];
|
||||
public array $additionalServices = [];
|
||||
|
||||
#[Assert\NotNull(message: 'Bitte auswählen', groups: ['strict_required'])]
|
||||
// Note: Ski pass validation is conditional - see ParticipantEditDto::validateSkiPassRequired()
|
||||
// Babies (0-2 years) are exempt from ski pass requirement
|
||||
public ?Service $skiPass = null;
|
||||
|
||||
public array $board = [];
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\Validator\Constraints as AppAssert;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
@@ -27,6 +28,39 @@ class ParticipantEditDto
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that ski pass is selected when required.
|
||||
*
|
||||
* Ski pass is required for all participants in create mode, EXCEPT for babies
|
||||
* (participants aged 0-2 years at travel date). Babies don't qualify for any
|
||||
* ski pass and the field is hidden for them.
|
||||
*
|
||||
* In edit mode, this validation is skipped as the ski pass is readonly.
|
||||
*
|
||||
* This validation only runs when strict_required group is active.
|
||||
*/
|
||||
#[Assert\Callback(groups: ['strict_required'])]
|
||||
public function validateSkiPassRequired(ExecutionContextInterface $context): void
|
||||
{
|
||||
// Skip validation in edit mode - ski pass is readonly
|
||||
if (BookingDto::MODE_EDIT === $this->bookingContext->getMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Baby age exemption: skip validation for participants at or under BABY_MAX_AGE
|
||||
$age = $this->participant->getAge($this->bookingContext->travel->dateFrom);
|
||||
if (null !== $age && $age <= Constants::BABY_MAX_AGE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ski pass is required for non-baby participants
|
||||
if (null === $this->participant->skiPass) {
|
||||
$context->buildViolation('Bitte auswählen')
|
||||
->atPath('participant.skiPass')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that insurance is selected when required.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user