feat: hide parking from participants under 18

This commit is contained in:
Björn Fromme
2026-03-16 12:00:55 +01:00
parent 094d6858d1
commit ea162972fa
4 changed files with 300 additions and 19 deletions
@@ -8,14 +8,15 @@ use App\BusProNet\Constants;
use App\BusProNet\Model\Service;
use App\BusProNet\Utility\DirectionMapper;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
/**
* Handles parking service selection for self-organized transportation.
*
* Parking is only available when outbound transportation is PKW (car).
* This is because parking is needed at the destination for those arriving by car.
* Automatically clears parking when outbound transportation is not PKW.
* Parking is only available when outbound transportation is PKW (car) AND
* participant is at least 18 years old (minimum driving age in Germany).
* Automatically clears parking when conditions are not met.
*/
class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
{
@@ -24,9 +25,11 @@ class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
return 'parking';
}
private const MINIMUM_DRIVING_AGE = 18;
public function getDependencies(): array
{
return ['transportationOutbound', 'transportationInbound'];
return ['transportationOutbound', 'transportationInbound', 'dateOfBirth'];
}
/**
@@ -54,10 +57,10 @@ class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
return;
}
// Check if parking is applicable (outbound transportation is PKW)
if (!$this->isParkingApplicable($participant)) {
$participant->parking = false; // Clear parking when outbound is not PKW
$participant->parkingService = null; // Clear parking service object
// Check if parking is applicable (outbound transportation is PKW AND participant is 18+)
if (false === $this->isParkingApplicable($participant)) {
$participant->parking = false;
$participant->parkingService = null;
return;
}
@@ -77,17 +80,30 @@ class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
}
/**
* Checks if parking is applicable based on outbound transportation selection.
* Checks if parking is applicable based on outbound transportation and age.
*
* Parking is only needed when arriving by car at the destination.
* Parking is only applicable when:
* 1. Outbound transportation is PKW (arriving by car at destination)
* 2. Participant is at least 18 years old (minimum driving age in Germany)
*
* @param object $participant The participant DTO
* @param ParticipantDto $participant The participant DTO
*
* @return bool True if parking is applicable, false otherwise
*/
private function isParkingApplicable(object $participant): bool
private function isParkingApplicable(ParticipantDto $participant): bool
{
return DirectionMapper::SUBTYPE_CAR_API === $participant->transportationOutbound?->subType;
// Must have PKW outbound transportation
if (DirectionMapper::SUBTYPE_CAR_API !== $participant->transportationOutbound?->subType) {
return false;
}
// Must be at least minimum driving age
$age = $participant->getAge();
if (null === $age || $age < self::MINIMUM_DRIVING_AGE) {
return false;
}
return true;
}
/**