57 lines
1.7 KiB
PHP
57 lines
1.7 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 pickup location selection for the outbound bus journey.
|
|
*
|
|
* Pickup is only processed when outbound transportation is bus type.
|
|
* Automatically clears pickup when outbound changes to self-organized (PKW).
|
|
*/
|
|
class ParticipantPickupFieldHandler extends AbstractParticipantFieldHandler
|
|
{
|
|
public function getFieldName(): string
|
|
{
|
|
return 'pickup';
|
|
}
|
|
|
|
public function getDependencies(): array
|
|
{
|
|
return ['transportationOutbound', 'transportationInbound'];
|
|
}
|
|
|
|
public function shouldProcess(array $submittedData, string $mode, int $participantIndex): bool
|
|
{
|
|
return true; // Always process to handle clearing pickup
|
|
}
|
|
|
|
public function processField(array $submittedData, BookingDto $bookingDto, int $participantIndex): void
|
|
{
|
|
$participant = $this->getParticipant($bookingDto, $participantIndex);
|
|
if (null === $participant) {
|
|
return;
|
|
}
|
|
|
|
// Pickup applies only to outbound bus journey - clear when outbound is not bus
|
|
$hasOutboundBus = null !== $participant->transportationOutbound
|
|
&& DirectionMapper::SUBTYPE_BUS_API === $participant->transportationOutbound->subType;
|
|
|
|
if (false === $hasOutboundBus) {
|
|
$participant->pickup = null;
|
|
|
|
return;
|
|
}
|
|
|
|
$selectedPickup = $this->getFieldValue($submittedData, $this->getFieldName());
|
|
|
|
// Validate pickup selection against available outbound pickups
|
|
$participant->pickup = $this->findItemById($selectedPickup, $bookingDto->travel->pickups);
|
|
}
|
|
}
|