Files
myep/src/Form/Service/ParticipantTransportationOutboundFieldHandler.php
T

62 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Form\Service;
use App\BusProNet\Utility\DirectionMapper;
use App\Form\Model\BookingDto;
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
/**
* Handles processing of outbound transportation service selection.
*
* This handler manages outbound (HIN) transportation options including bus and
* self-organized (PKW) services with pricing and availability validation.
* It processes the transportationOutbound field from form submissions and updates
* the participant DTO with validated selections.
*/
class ParticipantTransportationOutboundFieldHandler extends AbstractParticipantFieldHandler
{
public function getFieldName(): string
{
return 'transportationOutbound';
}
/**
* Determines if this handler should process the field based on submitted data.
*
* For transportation selection fields, we always need to process to handle cases
* where the selection is cleared (field not present in data). This ensures the
* participant DTO is updated with null when no transportation is selected.
*
* @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 Always returns true for transportation selection fields
*/
public function shouldProcess(array $submittedData, string $mode, int $participantIndex): bool
{
return true; // Always process to handle deselection cases
}
public function processField(array $submittedData, BookingDto $bookingDto, int $participantIndex): void
{
$participant = $this->getParticipant($bookingDto, $participantIndex);
if (null === $participant) {
return;
}
$selectedTransportation = $this->getFieldValue($submittedData, $this->getFieldName());
// Get all outbound transportation services (availability filtering happens at form level)
$services = $bookingDto->travel->getTransportationServicesByDirection(
DirectionMapper::OUTBOUND_TRAVEL
);
// Validate and update participant with selection
$participant->transportationOutbound = $this->findItemById($selectedTransportation, $services);
}
}