wip: implement transportation, pickups and parking

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 81b8237570
commit fe624cfd1c
15 changed files with 1497 additions and 190 deletions
@@ -4,8 +4,6 @@ declare(strict_types=1);
namespace App\Form\Service;
use App\BusProNet\Constants;
use App\BusProNet\Model\Service;
use App\BusProNet\Utility\DirectionMapper;
use App\Form\Model\BookingDtoInterface;
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
@@ -13,9 +11,9 @@ use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
/**
* Handles parking service selection for self-organized transportation.
*
* Parking is only available when at least one direction uses
* self-organized (PKW) transportation. Automatically clears parking
* when both transportation directions are bus-only.
* 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.
*/
class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
{
@@ -53,28 +51,23 @@ class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
return;
}
// Check if parking is applicable (at least one PKW direction)
// Check if parking is applicable (outbound transportation is PKW)
if (!$this->isParkingApplicable($participant)) {
$participant->parking = null; // Clear parking for bus-only transport
$participant->parking = false; // Clear parking when outbound is not PKW
return;
}
$selectedParking = $this->getFieldValue($submittedData, $this->getFieldName());
$parkingSelected = $this->getFieldValue($submittedData, $this->getFieldName());
// Get available parking services (subtype PAR)
$availableParkingServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_PARKING, true);
$validSelection = null;
if (null !== $selectedParking) {
$validSelection = $this->findValidParkingService($selectedParking, $availableParkingServices);
}
$participant->parking = $validSelection;
// Store boolean value directly (true if checkbox checked, false otherwise)
$participant->parking = (bool) $parkingSelected;
}
/**
* Checks if parking is applicable based on transportation selections.
* Checks if parking is applicable based on outbound transportation selection.
*
* Parking is only needed when arriving by car at the destination.
*
* @param object $participant The participant DTO
*
@@ -82,34 +75,6 @@ class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
*/
private function isParkingApplicable(object $participant): bool
{
$outboundIsPkw = DirectionMapper::SUBTYPE_CAR_API === $participant->transportationOutbound?->subType;
$inboundIsPkw = DirectionMapper::SUBTYPE_CAR_API === $participant->transportationInbound?->subType;
return $outboundIsPkw || $inboundIsPkw;
}
/**
* Finds a valid parking service from available parking services.
*
* @param mixed $selectedServiceId The submitted service ID
* @param array<int, Service> $availableServices Array of available parking services
*
* @return Service|null The valid service object, or null if invalid
*/
private function findValidParkingService(mixed $selectedServiceId, array $availableServices): ?Service
{
if (null === $selectedServiceId || false === is_string($selectedServiceId) && false === is_int($selectedServiceId)) {
return null;
}
$serviceId = (int) $selectedServiceId;
foreach ($availableServices as $service) {
if ($service->id === $serviceId) {
return $service;
}
}
return null;
return DirectionMapper::SUBTYPE_CAR_API === $participant->transportationOutbound?->subType;
}
}