wip: prepare transportation services
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Utility;
|
||||
|
||||
/**
|
||||
* Handles direction mapping between BusProNet's inconsistent direction codes.
|
||||
*
|
||||
* BusProNet uses different direction codes in different contexts:
|
||||
* - Travel data: 'HIN' (outbound), 'RUECK' (inbound)
|
||||
* - Booking data: 'H' (outbound), 'R' (inbound)
|
||||
*
|
||||
* This utility provides consistent mapping between formats and enables
|
||||
* clean English naming for internal application use.
|
||||
*/
|
||||
final class DirectionMapper
|
||||
{
|
||||
// Travel data format (full German words)
|
||||
public const OUTBOUND_TRAVEL = 'HIN';
|
||||
public const INBOUND_TRAVEL = 'RUECK';
|
||||
|
||||
// Booking data format (single letter abbreviations)
|
||||
public const OUTBOUND_BOOKING = 'H';
|
||||
public const INBOUND_BOOKING = 'R';
|
||||
|
||||
/**
|
||||
* Maps travel direction code to booking direction code.
|
||||
*
|
||||
* @param string $travelDirection The travel direction code ('HIN' or 'RUECK')
|
||||
*
|
||||
* @return string The booking direction code ('H' or 'R')
|
||||
*
|
||||
* @throws \InvalidArgumentException When direction code is not recognized
|
||||
*/
|
||||
public static function travelToBooking(string $travelDirection): string
|
||||
{
|
||||
return match ($travelDirection) {
|
||||
self::OUTBOUND_TRAVEL => self::OUTBOUND_BOOKING,
|
||||
self::INBOUND_TRAVEL => self::INBOUND_BOOKING,
|
||||
default => throw new \InvalidArgumentException("Unknown travel direction: $travelDirection"),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps booking direction code to travel direction code.
|
||||
*
|
||||
* @param string $bookingDirection The booking direction code ('H' or 'R')
|
||||
*
|
||||
* @return string The travel direction code ('HIN' or 'RUECK')
|
||||
*
|
||||
* @throws \InvalidArgumentException When direction code is not recognized
|
||||
*/
|
||||
public static function bookingToTravel(string $bookingDirection): string
|
||||
{
|
||||
return match ($bookingDirection) {
|
||||
self::OUTBOUND_BOOKING => self::OUTBOUND_TRAVEL,
|
||||
self::INBOUND_BOOKING => self::INBOUND_TRAVEL,
|
||||
default => throw new \InvalidArgumentException("Unknown booking direction: $bookingDirection"),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all outbound direction codes.
|
||||
*
|
||||
* @return string[] Array of outbound direction codes in all formats
|
||||
*/
|
||||
public static function getOutboundCodes(): array
|
||||
{
|
||||
return [self::OUTBOUND_TRAVEL, self::OUTBOUND_BOOKING];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all inbound direction codes.
|
||||
*
|
||||
* @return string[] Array of inbound direction codes in all formats
|
||||
*/
|
||||
public static function getInboundCodes(): array
|
||||
{
|
||||
return [self::INBOUND_TRAVEL, self::INBOUND_BOOKING];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a direction code is outbound.
|
||||
*
|
||||
* @param string $direction The direction code to check
|
||||
*
|
||||
* @return bool True if the direction is outbound, false otherwise
|
||||
*/
|
||||
public static function isOutbound(string $direction): bool
|
||||
{
|
||||
return in_array($direction, self::getOutboundCodes(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a direction code is inbound.
|
||||
*
|
||||
* @param string $direction The direction code to check
|
||||
*
|
||||
* @return bool True if the direction is inbound, false otherwise
|
||||
*/
|
||||
public static function isInbound(string $direction): bool
|
||||
{
|
||||
return in_array($direction, self::getInboundCodes(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that a direction code is recognized.
|
||||
*
|
||||
* @param string $direction The direction code to validate
|
||||
*
|
||||
* @return bool True if the direction is valid, false otherwise
|
||||
*/
|
||||
public static function isValid(string $direction): bool
|
||||
{
|
||||
return self::isOutbound($direction) || self::isInbound($direction);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class BookingEditDto implements BookingDtoInterface
|
||||
@@ -34,24 +35,37 @@ class BookingEditDto implements BookingDtoInterface
|
||||
|
||||
$participantData->courses = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_COURSES);
|
||||
|
||||
|
||||
// Skipass is single selection - take first item from array or null
|
||||
$skipasses = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_SKI_PASS);
|
||||
$participantData->skiPass = !empty($skipasses) ? $skipasses[0] : null;
|
||||
|
||||
|
||||
$participantData->additionalServices = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_ADDITIONAL);
|
||||
$participantData->board = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_BOARD);
|
||||
$participantData->rentals = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_RENTALS);
|
||||
// Different keys for direction used in booking data (H <=> HIN, R <=> RUECK)!
|
||||
$participantData->transportationServiceTo = $booking
|
||||
->getTransportationServiceForParticipantAndDirection($index, 'H');
|
||||
$participantData->transportationServiceFro = $booking
|
||||
->getTransportationServiceForParticipantAndDirection($index, 'R');
|
||||
$participantData->pickup = $booking->getPickupForParticipant($index);
|
||||
// Transportation services using improved direction mapping
|
||||
// Direction mapping handles BusProNet's inconsistent codes (H <=> HIN, R <=> RUECK)
|
||||
$outboundTransportation = $booking
|
||||
->getTransportationServiceForParticipantAndDirection($index, DirectionMapper::OUTBOUND_BOOKING);
|
||||
$inboundTransportation = $booking
|
||||
->getTransportationServiceForParticipantAndDirection($index, DirectionMapper::INBOUND_BOOKING);
|
||||
|
||||
// Set new improved property names
|
||||
$participantData->transportationOutbound = $outboundTransportation;
|
||||
$participantData->transportationInbound = $inboundTransportation;
|
||||
|
||||
// Backward compatibility: also set deprecated properties
|
||||
$participantData->transportationServiceTo = $outboundTransportation;
|
||||
$participantData->transportationServiceFro = $inboundTransportation;
|
||||
|
||||
// Pickup handling (currently only supports outbound pickup)
|
||||
$pickupOutbound = $booking->getPickupForParticipant($index);
|
||||
$participantData->pickupOutbound = $pickupOutbound;
|
||||
$participantData->pickup = $pickupOutbound; // Backward compatibility
|
||||
|
||||
$instance->participants[$index] = $participantData;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,19 @@ class ParticipantDto
|
||||
public ?Service $skiPass = null;
|
||||
public array $board = [];
|
||||
public array $rentals = [];
|
||||
|
||||
// Transportation services with improved naming (outbound/inbound)
|
||||
public ?Service $transportationOutbound = null;
|
||||
public ?Service $transportationInbound = null;
|
||||
|
||||
// Pickup locations for each direction
|
||||
public ?Pickup $pickupOutbound = null;
|
||||
public ?Pickup $pickupInbound = null;
|
||||
|
||||
// Parking service for self-organized transportation
|
||||
public ?Service $parking = null;
|
||||
|
||||
// Deprecated properties for backward compatibility - will be removed in future version
|
||||
public ?Service $transportationServiceTo = null;
|
||||
public ?Service $transportationServiceFro = null;
|
||||
public ?Pickup $pickup = null;
|
||||
|
||||
Reference in New Issue
Block a user