wip: booking process
This commit is contained in:
@@ -13,8 +13,8 @@ use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\BusProNet\Traits\ApiClientTrait;
|
||||
use App\BusProNet\XmlParser\ApiResponseParser;
|
||||
use App\Form\Model\BookingData;
|
||||
use App\Form\Model\RegistrationData;
|
||||
use App\Form\Model\BookingEditDto;
|
||||
use App\Form\Model\RegistrationDto;
|
||||
use League\Flysystem\FilesystemException;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -65,7 +65,7 @@ class ApiClient
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
*/
|
||||
public function register(RegistrationData $registrationData): Notification
|
||||
public function register(RegistrationDto $registrationData): Notification
|
||||
{
|
||||
$data = [
|
||||
'user' => $this->config['bpn_username'],
|
||||
@@ -184,7 +184,7 @@ class ApiClient
|
||||
/**
|
||||
* @throws ApiClientException
|
||||
*/
|
||||
public function updateBooking(BookingData $formData, bool $debug = false): Notification|BookingUpdate
|
||||
public function updateBooking(BookingEditDto $formData, bool $debug = false): Notification|BookingUpdate
|
||||
{
|
||||
$payload = (new BookingDataProcessor())->createUpdateRequestPayload($formData);
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet;
|
||||
|
||||
final class Constants
|
||||
{
|
||||
public const SOURCE_TRAVEL = 'travel';
|
||||
public const SOURCE_BOOKING = 'booking';
|
||||
|
||||
public const CATEGORY_ADDITIONAL = 'additional';
|
||||
public const CATEGORY_TRANSPORTATION = 'transportation';
|
||||
|
||||
public const TOKEN_COURSES = 'KUR';
|
||||
public const TOKEN_SKI_PASS = 'SPA';
|
||||
public const TOKEN_ADDITIONAL = 'SON';
|
||||
public const TOKEN_BOARD = 'VPF';
|
||||
public const TOKEN_RENTALS = ['VER', 'VE2', 'VE3', 'VE4', 'VE5', 'VE6', 'VE7', 'VE8'];
|
||||
|
||||
public const STATUS_AVAILABLE = 'Frei';
|
||||
public const STATUS_BLOCKED = 'Buchungsstop';
|
||||
public const STATUS_ON_REQUEST = 'Anfrage';
|
||||
}
|
||||
@@ -3,19 +3,26 @@
|
||||
namespace App\BusProNet\DataProcessor;
|
||||
|
||||
use App\BusProNet\Model\Communication;
|
||||
use App\Form\Model\BookingData;
|
||||
use App\Form\Model\BookingEditDto;
|
||||
|
||||
class BookingDataProcessor
|
||||
{
|
||||
public function createUpdateRequestPayload(?BookingData $formData): array
|
||||
public function createUpdateRequestPayload(?BookingEditDto $formData): array
|
||||
{
|
||||
$bookingData = $formData->booking;
|
||||
$travelData = $formData->travel;
|
||||
|
||||
// Reset mappings
|
||||
foreach ([...$bookingData->additionalServices, ...$bookingData->transportationServices, ...$bookingData->pickupsTo, ...$bookingData->pickupsFro] as $service) {
|
||||
$servicesToReset = [
|
||||
...$bookingData->additionalServices,
|
||||
...$bookingData->transportationServices,
|
||||
...$bookingData->pickupsTo,
|
||||
...$bookingData->pickupsFro,
|
||||
];
|
||||
foreach ($servicesToReset as $service) {
|
||||
$service->mapping = [];
|
||||
}
|
||||
|
||||
// Update mappings, add services and pickups
|
||||
foreach ($formData->participants as $participant) {
|
||||
// skip canceled participants
|
||||
|
||||
@@ -1,25 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Represents a physical address with street, postal code, city, and country information.
|
||||
*
|
||||
* This class handles address data for users and participants in the booking system.
|
||||
* It provides validation constraints for required fields and methods to convert
|
||||
* address data to API payload format.
|
||||
*/
|
||||
class Address
|
||||
{
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
public ?string $street = '';
|
||||
public string $street = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
public ?string $postCode = '';
|
||||
public string $postCode = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
public ?string $city = '';
|
||||
public string $city = '';
|
||||
|
||||
public ?string $district = '';
|
||||
public string $district = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
public ?string $country = '';
|
||||
public string $country = '';
|
||||
|
||||
/**
|
||||
* Converts the address to API payload format.
|
||||
*
|
||||
* Transforms the address object into an array structure suitable
|
||||
* for API communication with the BusProNet system.
|
||||
*
|
||||
* @return array<string, string> The payload array for API transmission
|
||||
*/
|
||||
public function toPayload(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents service availability with status and pricing information.
|
||||
*
|
||||
* This class handles availability data including service identification,
|
||||
* status, available quantity, and pricing. It implements JsonSerializable
|
||||
* for API response formatting.
|
||||
*/
|
||||
class Availability implements \JsonSerializable
|
||||
{
|
||||
public ?int $serviceId = null;
|
||||
@@ -9,6 +18,14 @@ class Availability implements \JsonSerializable
|
||||
public ?int $available = null;
|
||||
public ?float $price = null;
|
||||
|
||||
/**
|
||||
* Serializes the availability data to JSON format.
|
||||
*
|
||||
* Converts the availability object to an array structure suitable
|
||||
* for JSON serialization in API responses.
|
||||
*
|
||||
* @return array<string, mixed> The serialized availability data
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents a bank account with payment information.
|
||||
*
|
||||
* This class handles bank account data including IBAN, BIC, bank name,
|
||||
* and account holder information for payment processing.
|
||||
*/
|
||||
class BankAccount
|
||||
{
|
||||
public ?string $iban = null;
|
||||
|
||||
@@ -1,18 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents base data with item collection and retrieval functionality.
|
||||
*
|
||||
* This class provides a container for generic data items with methods
|
||||
* to access the entire collection or individual items by key.
|
||||
*/
|
||||
class BaseData
|
||||
{
|
||||
public function __construct(private readonly array $items)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all items in the base data collection.
|
||||
*
|
||||
* @return array The complete items array
|
||||
*/
|
||||
public function getItems(): array
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a specific item by its key.
|
||||
*
|
||||
* @param string $key The key to search for
|
||||
*
|
||||
* @return mixed The item value or null if not found
|
||||
*/
|
||||
public function getItemByKey(string $key): mixed
|
||||
{
|
||||
return $this->items[$key] ?? null;
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents a booking with participants, services, and pricing information.
|
||||
*
|
||||
* This class handles complete booking data including participant information,
|
||||
* selected services, transportation details, accommodation, and pricing calculations.
|
||||
* It provides methods to retrieve participant-specific data and calculate costs.
|
||||
*/
|
||||
class Booking
|
||||
{
|
||||
public ?int $id = null;
|
||||
@@ -12,7 +21,7 @@ class Booking
|
||||
public ?int $participantCount = null;
|
||||
public ?float $price = null;
|
||||
public ?\DateTimeImmutable $bookingDate = null;
|
||||
public ?string $travel = null;
|
||||
public ?string $travelName = null;
|
||||
public ?int $travelId = null;
|
||||
public ?string $travelCode = null;
|
||||
public ?\DateTimeImmutable $travelDate = null;
|
||||
@@ -37,6 +46,14 @@ class Booking
|
||||
public ?float $totalPrice = null;
|
||||
public ?string $travelInfoUrl = null;
|
||||
|
||||
/**
|
||||
* Calculates the remaining balance for the booking.
|
||||
*
|
||||
* Returns the difference between the total price and any payments made.
|
||||
* If no payment has been made, returns the full price.
|
||||
*
|
||||
* @return float The remaining balance amount
|
||||
*/
|
||||
public function getBalance(): float
|
||||
{
|
||||
if (null === $this->payment) {
|
||||
@@ -46,6 +63,16 @@ class Booking
|
||||
return $this->price - $this->payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves additional services filtered by group.
|
||||
*
|
||||
* Filters the additional services array based on the provided group(s).
|
||||
* Supports both single group strings and arrays of groups.
|
||||
*
|
||||
* @param mixed $group The service group(s) to filter by
|
||||
*
|
||||
* @return array<Service> The filtered services array
|
||||
*/
|
||||
public function getAdditionalServicesByGroup(mixed $group): array
|
||||
{
|
||||
$group = (array) $group;
|
||||
@@ -55,6 +82,17 @@ class Booking
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves additional services for a specific participant by group.
|
||||
*
|
||||
* Filters additional services by group and participant index mapping.
|
||||
* Returns services that are assigned to the specified participant.
|
||||
*
|
||||
* @param int $participantIndex The participant index to filter by
|
||||
* @param mixed $group The service group(s) to filter by
|
||||
*
|
||||
* @return array<Service> The filtered services for the participant
|
||||
*/
|
||||
public function getAdditionalServicesForParticipantByGroup(int $participantIndex, mixed $group): array
|
||||
{
|
||||
$selectedServices = $this->getAdditionalServicesByGroup($group);
|
||||
@@ -64,6 +102,17 @@ class Booking
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves transportation service for a specific participant and direction.
|
||||
*
|
||||
* Finds the transportation service that matches the participant index
|
||||
* and travel direction (e.g., 'H' for outbound, 'R' for return).
|
||||
*
|
||||
* @param int $participantIndex The participant index to search for
|
||||
* @param string $direction The travel direction ('H' or 'R')
|
||||
*
|
||||
* @return Service|null The matching transportation service or null if not found
|
||||
*/
|
||||
public function getTransportationServiceForParticipantAndDirection(
|
||||
int $participantIndex,
|
||||
string $direction
|
||||
@@ -80,6 +129,16 @@ class Booking
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves pickup service for a specific participant.
|
||||
*
|
||||
* Finds the pickup service assigned to the specified participant
|
||||
* from the outbound pickup services.
|
||||
*
|
||||
* @param int $participantIndex The participant index to search for
|
||||
*
|
||||
* @return Pickup|null The matching pickup service or null if not found
|
||||
*/
|
||||
public function getPickupForParticipant(int $participantIndex): ?Pickup
|
||||
{
|
||||
foreach ($this->pickupsTo as $pickup) {
|
||||
@@ -91,6 +150,16 @@ class Booking
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves room assignment for a specific participant.
|
||||
*
|
||||
* Finds the room assigned to the specified participant
|
||||
* based on the room mapping configuration.
|
||||
*
|
||||
* @param int $participantIndex The participant index to search for
|
||||
*
|
||||
* @return Room|null The matching room or null if not found
|
||||
*/
|
||||
public function getRoomForParticipant(int $participantIndex): ?Room
|
||||
{
|
||||
foreach ($this->rooms as $room) {
|
||||
@@ -102,6 +171,16 @@ class Booking
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the total price for a specific participant.
|
||||
*
|
||||
* Sums up all services, surcharges, and room costs assigned to the participant.
|
||||
* Includes mandatory services that apply to all participants.
|
||||
*
|
||||
* @param int $participantIndex The participant index to calculate for
|
||||
*
|
||||
* @return float The total price for the participant
|
||||
*/
|
||||
public function getPriceForParticipant(int $participantIndex): float
|
||||
{
|
||||
$price = 0.0;
|
||||
@@ -126,6 +205,15 @@ class Booking
|
||||
return $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves surcharges for a specific participant.
|
||||
*
|
||||
* Filters surcharges based on participant index mapping.
|
||||
*
|
||||
* @param int $participantIndex The participant index to filter by
|
||||
*
|
||||
* @return array<Surcharge> The surcharges assigned to the participant
|
||||
*/
|
||||
public function getSurchargesForParticipant(int $participantIndex): array
|
||||
{
|
||||
return array_filter($this->surcharges, function (Surcharge $surcharge) use ($participantIndex) {
|
||||
@@ -133,6 +221,13 @@ class Booking
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the total price for all participants.
|
||||
*
|
||||
* Sums up the individual prices for all participants in the booking.
|
||||
*
|
||||
* @return float The calculated total price for all participants
|
||||
*/
|
||||
public function getCalculatedTotalPrice(): float
|
||||
{
|
||||
$totalPrice = 0.0;
|
||||
@@ -144,6 +239,14 @@ class Booking
|
||||
return $totalPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the booking is editable.
|
||||
*
|
||||
* A booking is editable if the travel date is in the future and
|
||||
* the status is not cancelled ('S') or unknown ('U').
|
||||
*
|
||||
* @return bool True if the booking can be edited, false otherwise
|
||||
*/
|
||||
public function isEditable(): bool
|
||||
{
|
||||
return $this->travelDate > new \DateTimeImmutable() && false === in_array($this->status, ['S', 'U']);
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents a booking update response with validation and status information.
|
||||
*
|
||||
* This class handles booking update results including validation status,
|
||||
* success indication, and status messages for API response handling.
|
||||
*/
|
||||
class BookingUpdate
|
||||
{
|
||||
public bool $valid = false;
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Represents communication information including email, phone, and newsletter preferences.
|
||||
*
|
||||
* This class handles contact information for users and participants in the booking system.
|
||||
* It provides validation constraints for required fields and methods to convert
|
||||
* communication data to API payload format.
|
||||
*/
|
||||
class Communication
|
||||
{
|
||||
public ?string $phone = '';
|
||||
public string $phone = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
public ?string $mobile = '';
|
||||
public string $mobile = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
#[Assert\Email(message: 'Bitte eine gültige Adresse angeben', mode: 'strict', groups: ['personal_data'])]
|
||||
public ?string $email = '';
|
||||
public string $email = '';
|
||||
|
||||
public bool $newsletter = false;
|
||||
|
||||
/**
|
||||
* Converts the communication data to API payload format.
|
||||
*
|
||||
* Transforms the communication object into an array structure suitable
|
||||
* for API communication with the BusProNet system.
|
||||
*
|
||||
* @return array<string, string> The payload array for API transmission
|
||||
*/
|
||||
public function toPayload(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents a country with identification and nationality information.
|
||||
*
|
||||
* This class handles country data including unique identification,
|
||||
* name, token, and associated nationality information.
|
||||
*/
|
||||
class Country
|
||||
{
|
||||
public ?int $id = null;
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents a CRM action with configuration and state information.
|
||||
*
|
||||
* This class handles CRM action data including identification, labeling,
|
||||
* mutability status, and selection state for user interface management.
|
||||
*/
|
||||
class CrmAction
|
||||
{
|
||||
public ?int $id = null;
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents CRM attributes with role and permission information.
|
||||
*
|
||||
* This class handles CRM system attributes including selection groups,
|
||||
* actions, user roles, and hotel assignments for access control.
|
||||
*/
|
||||
class CrmAttributes
|
||||
{
|
||||
public ?array $selectionGroups = null;
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
/**
|
||||
* Represents a CRM selection with configuration and state information.
|
||||
*
|
||||
* This class handles CRM selection data including identification, labeling,
|
||||
* mutability status, and selection state. It provides serialization groups
|
||||
* for API responses.
|
||||
*/
|
||||
class CrmSelection
|
||||
{
|
||||
#[Groups(['api:single'])]
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
/**
|
||||
* Represents a CRM selection group with included services mapping.
|
||||
*
|
||||
* This class handles CRM selection group data including identification,
|
||||
* labeling, and selections. It provides methods to filter mutable selections
|
||||
* and determine visibility, along with a static mapping for included services.
|
||||
*/
|
||||
class CrmSelectionGroup
|
||||
{
|
||||
/**
|
||||
* Maps BusPro IDs of CRM selection groups representing
|
||||
* included services.
|
||||
*
|
||||
* @var array|string[]
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public static array $includedServicesMapping = [
|
||||
7 => 'Skipass',
|
||||
@@ -32,6 +41,14 @@ class CrmSelectionGroup
|
||||
#[Groups(['api:single'])]
|
||||
public ?array $selections = null;
|
||||
|
||||
/**
|
||||
* Retrieves only the mutable selections from the group.
|
||||
*
|
||||
* Filters the selections array to return only items that are marked
|
||||
* as mutable for user interface management.
|
||||
*
|
||||
* @return array<CrmSelection> The mutable selections array
|
||||
*/
|
||||
public function getMutableSelections(): array
|
||||
{
|
||||
return array_filter($this->selections, function (CrmSelection $selection) {
|
||||
@@ -39,6 +56,14 @@ class CrmSelectionGroup
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the selection group should be visible.
|
||||
*
|
||||
* A group is considered visible if it contains at least one
|
||||
* mutable selection for user interaction.
|
||||
*
|
||||
* @return bool True if the group has mutable selections, false otherwise
|
||||
*/
|
||||
#[Groups(['api:single'])]
|
||||
public function isVisible(): bool
|
||||
{
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents error codes and messages for the BusProNet API.
|
||||
*
|
||||
* This class provides a static mapping of error codes to their corresponding
|
||||
* German error messages for consistent error handling across the application.
|
||||
* Error codes range from 100-999 and cover various API scenarios.
|
||||
*/
|
||||
class Error
|
||||
{
|
||||
/**
|
||||
* @var array<int, string>
|
||||
*/
|
||||
private static array $errors = [
|
||||
100 => 'Anfrageknoten fehlt',
|
||||
101 => 'Satzknoten fehlt in Anfrageknoten',
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents a file with content and metadata information.
|
||||
*
|
||||
* This class handles file data including filename, content, and MIME type
|
||||
* for document storage and retrieval operations.
|
||||
*/
|
||||
class File
|
||||
{
|
||||
public function __construct(string $filename, string $content, string $mimeType)
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
/**
|
||||
* Represents a travel guide with contact information.
|
||||
*
|
||||
* This class handles guide data including name and contact details.
|
||||
* It provides serialization groups for API responses in travel contexts.
|
||||
*/
|
||||
class Guide
|
||||
{
|
||||
#[Groups(['api:single'])]
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
/**
|
||||
* Represents a hotel with location and contact information.
|
||||
*
|
||||
* This class handles hotel data including identification, location details,
|
||||
* and contact information. It provides serialization groups for API responses
|
||||
* in travel and booking contexts.
|
||||
*/
|
||||
class Hotel
|
||||
{
|
||||
#[Groups(['api:list', 'api:single'])]
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents mutable data configuration with category and timing information.
|
||||
*
|
||||
* This class handles mutable data settings including category identification,
|
||||
* mutability status, and timing constraints for booking modifications.
|
||||
*/
|
||||
class MutableData
|
||||
{
|
||||
public const CATEGORY_PARTICIPANT_COUNT = 'participant_count';
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents a notification with code and message information.
|
||||
*
|
||||
* This class handles notification data including error codes and messages
|
||||
* for API response handling. It provides methods to determine if the
|
||||
* notification represents an error condition.
|
||||
*/
|
||||
class Notification
|
||||
{
|
||||
public function __construct(int $code, string $message)
|
||||
@@ -13,6 +22,14 @@ class Notification
|
||||
public ?int $code;
|
||||
public ?string $message;
|
||||
|
||||
/**
|
||||
* Determines if the notification represents an error.
|
||||
*
|
||||
* Returns true if the notification code is not 650 (success code).
|
||||
* Code 650 is used for successful operations in the BusProNet API.
|
||||
*
|
||||
* @return bool True if the notification is an error, false otherwise
|
||||
*/
|
||||
public function isError(): bool
|
||||
{
|
||||
return 650 !== $this->code;
|
||||
|
||||
@@ -1,31 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Represents personal data for a user including address and communication information.
|
||||
*
|
||||
* This class handles the storage and transformation of personal information
|
||||
* including name, address, communication details, and physical attributes.
|
||||
* It provides methods to convert data to API payload format and extract claims
|
||||
* for authentication purposes.
|
||||
*/
|
||||
class PersonalData
|
||||
{
|
||||
private const DEFAULT_AGE_YEARS = 18;
|
||||
|
||||
public ?int $addressId = null;
|
||||
public ?int $personId = null;
|
||||
public bool $mutable = false;
|
||||
public ?string $status = '';
|
||||
public ?string $status = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['Default', 'personal_data'])]
|
||||
public ?string $name = '';
|
||||
public string $name = '';
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['Default', 'personal_data'])]
|
||||
public ?string $firstName = '';
|
||||
public string $firstName = '';
|
||||
|
||||
public ?string $salutation = '';
|
||||
public ?string $title = '';
|
||||
public ?string $gender = '';
|
||||
public ?string $nationality = '';
|
||||
public ?string $height = '';
|
||||
public ?string $shoeSize = '';
|
||||
public ?string $weight = '';
|
||||
public string $salutation = '';
|
||||
public string $title = '';
|
||||
public string $gender = '';
|
||||
public string $nationality = '';
|
||||
public string $height = '';
|
||||
public string $shoeSize = '';
|
||||
public string $weight = '';
|
||||
public ?\DateTimeImmutable $dateOfBirth = null;
|
||||
public ?string $remarks = '';
|
||||
public string $remarks = '';
|
||||
|
||||
#[Assert\Valid(groups: ['personal_data'])]
|
||||
public Address $address;
|
||||
@@ -39,11 +51,19 @@ class PersonalData
|
||||
$this->communication = new Communication();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the personal data to API payload format.
|
||||
*
|
||||
* Transforms the personal data object into an array structure suitable
|
||||
* for API communication with the BusProNet system.
|
||||
*
|
||||
* @return array<string, mixed> The payload array for API transmission
|
||||
*/
|
||||
public function toPayload(): array
|
||||
{
|
||||
// Ensure date of birth is populated
|
||||
if (null === $dob = $this->dateOfBirth) {
|
||||
$dob = new \DateTimeImmutable('18 years ago');
|
||||
$dob = new \DateTimeImmutable(self::DEFAULT_AGE_YEARS . ' years ago');
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -56,8 +76,8 @@ class PersonalData
|
||||
'titel' => $this->title,
|
||||
'vorname' => $this->firstName,
|
||||
'name' => $this->name,
|
||||
'anschrift' => $this->address?->toPayload(),
|
||||
'kommunikation' => $this->communication?->toPayload(),
|
||||
'anschrift' => $this->address->toPayload(),
|
||||
'kommunikation' => $this->communication->toPayload(),
|
||||
'sonstiges1' => $this->height,
|
||||
'sonstiges2' => $this->weight,
|
||||
'sonstiges3' => $this->shoeSize,
|
||||
@@ -65,6 +85,14 @@ class PersonalData
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts user claims for authentication and profile information.
|
||||
*
|
||||
* Creates a structured array containing user profile information
|
||||
* suitable for JWT claims or user session data.
|
||||
*
|
||||
* @return array<string, mixed> The claims array with user profile data
|
||||
*/
|
||||
public function getClaims(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Context;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
|
||||
/**
|
||||
* Represents a pickup location with timing and pricing information.
|
||||
*
|
||||
* This class handles pickup point data including location details, scheduled times,
|
||||
* pricing, and participant mapping. It provides serialization groups for API
|
||||
* responses and booking management.
|
||||
*/
|
||||
class Pickup
|
||||
{
|
||||
#[Groups(['api:list'])]
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Context;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
|
||||
/**
|
||||
* Represents a room configuration with capacity, pricing, and availability information.
|
||||
*
|
||||
* This class handles room data including category, board options, capacity limits,
|
||||
* pricing structure, and participant mapping. It provides serialization groups
|
||||
* for different API contexts and booking management.
|
||||
*/
|
||||
class Room
|
||||
{
|
||||
#[Groups(['api:list', 'api:single'])]
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Context;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
|
||||
/**
|
||||
* Represents a service offering with pricing, availability, and configuration options.
|
||||
*
|
||||
* This class handles various types of services including transportation, additional
|
||||
* services, courses, and rentals. It provides constants for service categorization
|
||||
* and status management, along with serialization groups for API responses.
|
||||
*/
|
||||
class Service
|
||||
{
|
||||
public const SOURCE_TRAVEL = 'travel';
|
||||
public const SOURCE_BOOKING = 'booking';
|
||||
|
||||
public const CATEGORY_ADDITIONAL = 'additional';
|
||||
public const CATEGORY_TRANSPORTATION = 'transportation';
|
||||
|
||||
public const TOKEN_COURSES = 'KUR';
|
||||
public const TOKEN_SKI_PASS = 'SPA';
|
||||
public const TOKEN_ADDITIONAL = 'SON';
|
||||
public const TOKEN_BOARD = 'VPF';
|
||||
public const TOKEN_RENTALS = ['VER', 'VE2', 'VE3', 'VE4', 'VE5', 'VE6', 'VE7', 'VE8'];
|
||||
|
||||
public const STATUS_AVAILABLE = 'Frei';
|
||||
public const STATUS_BLOCKED = 'Buchungsstop';
|
||||
public const STATUS_ON_REQUEST = 'Anfrage';
|
||||
|
||||
#[Groups(['api:single', 'api:list'])]
|
||||
public ?int $id = null;
|
||||
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
/**
|
||||
* Represents a surcharge with pricing and participant mapping.
|
||||
*
|
||||
* This class handles surcharge data including label, pricing structure,
|
||||
* and participant mapping for booking calculations.
|
||||
*/
|
||||
class Surcharge
|
||||
{
|
||||
public ?string $label = null;
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\Context;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
|
||||
/**
|
||||
* Represents a travel package with services, accommodation, and pricing information.
|
||||
*
|
||||
* This class handles travel data including dates, hotel information, available services,
|
||||
* transportation options, and participant configuration. It provides methods to filter
|
||||
* and retrieve services by various criteria and manage included services.
|
||||
*/
|
||||
class Travel
|
||||
{
|
||||
#[Groups(['api:list', 'api:single'])]
|
||||
@@ -76,6 +85,17 @@ class Travel
|
||||
#[Groups(['api:single'])]
|
||||
public ?Guide $guide = null;
|
||||
|
||||
/**
|
||||
* Retrieves additional services filtered by group and availability.
|
||||
*
|
||||
* Filters additional services based on the provided group(s) and optionally
|
||||
* by availability. Services are sorted alphabetically by label.
|
||||
*
|
||||
* @param mixed $group The service group(s) to filter by
|
||||
* @param bool $availableOnly Whether to include only available services
|
||||
*
|
||||
* @return array<Service> The filtered and sorted services array
|
||||
*/
|
||||
public function getAdditionalServicesByGroup(mixed $group, bool $availableOnly = true): array
|
||||
{
|
||||
$group = (array) $group;
|
||||
@@ -91,6 +111,17 @@ class Travel
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves transportation services filtered by direction and availability.
|
||||
*
|
||||
* Filters transportation services based on travel direction and optionally
|
||||
* by availability. Services are sorted by subtype.
|
||||
*
|
||||
* @param string $direction The travel direction to filter by
|
||||
* @param bool $availableOnly Whether to include only available services
|
||||
*
|
||||
* @return array<Service> The filtered and sorted transportation services
|
||||
*/
|
||||
public function getTransportationServicesByDirection(string $direction, bool $availableOnly = true): array
|
||||
{
|
||||
$services = array_filter($this->transportationServices, function (Service $service) use ($direction, $availableOnly) {
|
||||
@@ -106,6 +137,14 @@ class Travel
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves included services from selection groups.
|
||||
*
|
||||
* Maps selection group IDs to their corresponding services based on
|
||||
* the predefined included services mapping.
|
||||
*
|
||||
* @return array The included services from selection groups
|
||||
*/
|
||||
public function getIncludedServices(): array
|
||||
{
|
||||
$services = [];
|
||||
@@ -118,4 +157,27 @@ class Travel
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves rooms filtered by their IDs.
|
||||
*
|
||||
* Filters the rooms array to return only rooms whose IDs match
|
||||
* the provided array of IDs. Returns an empty array if no matching
|
||||
* rooms are found.
|
||||
*
|
||||
* @param array<int> $ids The array of room IDs to filter by
|
||||
*
|
||||
* @return array<Room> The filtered rooms array
|
||||
*/
|
||||
public function getRoomsByIds(array $ids): array
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_filter($this->rooms, function (Room $room) use ($ids) {
|
||||
return in_array($room->id, $ids, true);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\BusProNet\XmlLoader;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\CrmSelection;
|
||||
use App\BusProNet\Model\CrmSelectionGroup;
|
||||
@@ -192,8 +193,8 @@ class TravelLoader extends AbstractLoader
|
||||
$serviceId = (int) $serviceNode->attr('idbuspro');
|
||||
|
||||
$service = new Service();
|
||||
$service->source = Service::SOURCE_TRAVEL;
|
||||
$service->category = Service::CATEGORY_ADDITIONAL;
|
||||
$service->source = Constants::SOURCE_TRAVEL;
|
||||
$service->category = Constants::CATEGORY_ADDITIONAL;
|
||||
$service->id = $serviceId;
|
||||
$service->subType = $serviceNode->attr('unterart');
|
||||
$service->mandatory = $this->stringToBool($serviceNode->attr('pflicht'));
|
||||
@@ -236,8 +237,8 @@ class TravelLoader extends AbstractLoader
|
||||
$serviceId = (int) $serviceNode->attr('idbuspro');
|
||||
|
||||
$service = new Service();
|
||||
$service->source = Service::SOURCE_TRAVEL;
|
||||
$service->category = Service::CATEGORY_TRANSPORTATION;
|
||||
$service->source = Constants::SOURCE_TRAVEL;
|
||||
$service->category = Constants::CATEGORY_TRANSPORTATION;
|
||||
$service->id = $serviceId;
|
||||
$service->subType = $serviceNode->attr('unterart');
|
||||
$service->dateFrom = $this->stringToDate($serviceNode->attr('termin'));
|
||||
@@ -311,12 +312,12 @@ class TravelLoader extends AbstractLoader
|
||||
$room->category = $roomNode->attr('kat');
|
||||
$room->boardId = (int) $roomNode->attr('idbuspro_vp');
|
||||
$room->label = $roomNode->attr('zimmertext');
|
||||
$room->minPax = (int) $roomNode->attr('MinPax');
|
||||
$room->maxPax = (int) $roomNode->attr('MaxPax');
|
||||
$room->minPax = (int) $roomNode->attr('minpax');
|
||||
$room->maxPax = (int) $roomNode->attr('maxpax');
|
||||
$room->nights = (int) $roomNode->attr('naechte');
|
||||
$room->price = $roomNode->attr('preis') ?
|
||||
$this->stringToFloat($roomNode->attr('preis')) : null;
|
||||
$room->status = $this->getStringOrNullValue($roomNode->filterXPath('//status'));
|
||||
$room->status = $roomNode->attr('status');
|
||||
$room->available = (int) $roomNode->attr('verfuegbar');
|
||||
|
||||
$rooms[$roomId] = $room;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Address;
|
||||
use App\BusProNet\Model\BankAccount;
|
||||
use App\BusProNet\Model\Booking;
|
||||
@@ -38,7 +39,7 @@ class BookingParser extends AbstractParser
|
||||
|
||||
$travelData = $node->filterXPath('//reise');
|
||||
|
||||
$booking->travel = $travelData->attr('bezeichnung');
|
||||
$booking->travelName = $travelData->attr('bezeichnung');
|
||||
$booking->travelId = $this->getIntOrNullValue($node->filterXPath('//idreise'));
|
||||
$booking->travelCode = $travelData->attr('code');
|
||||
$booking->travelDate = $this->stringToDate($travelData->attr('termin'));
|
||||
@@ -72,14 +73,14 @@ class BookingParser extends AbstractParser
|
||||
if (0 < $transportationData->count()) {
|
||||
$booking->transportationServices = $this
|
||||
->servicesParser
|
||||
->parse($transportationData, Service::CATEGORY_TRANSPORTATION, Service::SOURCE_BOOKING);
|
||||
->parse($transportationData, Constants::CATEGORY_TRANSPORTATION, Constants::SOURCE_BOOKING);
|
||||
}
|
||||
|
||||
$additionalServicesData = $node->filterXPath('//zusatzleistungen/zusatzleistung');
|
||||
if (0 < $additionalServicesData->count()) {
|
||||
$booking->additionalServices = $this
|
||||
->servicesParser
|
||||
->parse($additionalServicesData, Service::CATEGORY_ADDITIONAL, Service::SOURCE_BOOKING);
|
||||
->parse($additionalServicesData, Constants::CATEGORY_ADDITIONAL, Constants::SOURCE_BOOKING);
|
||||
}
|
||||
|
||||
$roomsData = $node->filterXPath('//ferienzielunterbringungen/ferienzielunterbringung');
|
||||
|
||||
@@ -26,7 +26,7 @@ class BookingsParser extends AbstractParser
|
||||
$booking->participantCount = $this->getIntOrNullValue($node->filterXPath('//personen'));
|
||||
$booking->price = $this->getFloatOrNullValue($node->filterXPath('//preis'));
|
||||
$booking->bookingDate = $this->getDateTimeOrNullValue($node->filterXPath('//buchungsdatum'));
|
||||
$booking->travel = $this->getStringOrNullValue($node->filterXPath('//reise'));
|
||||
$booking->travelName = $this->getStringOrNullValue($node->filterXPath('//reise'));
|
||||
$booking->travelId = $this->getIntOrNullValue($node->filterXPath('//idreise'));
|
||||
$booking->travelDate = $this->getDateOrNullValue($node->filterXPath('//reisedatum'));
|
||||
$booking->hasDocuments = $this->getBoolValue($node->filterXPath('//reisedokument'));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
@@ -30,7 +31,7 @@ class ServicesParser extends AbstractParser
|
||||
}, $this->stringToArray($node->attr('einzelpreis', ''), '/')
|
||||
);
|
||||
$service->individualPrice = array_combine($mapping, $individualPrices);
|
||||
if (Service::CATEGORY_TRANSPORTATION === $category) {
|
||||
if (Constants::CATEGORY_TRANSPORTATION === $category) {
|
||||
$service->direction = $node->attr('richtung');
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
|
||||
use App\BusProNet\XmlLoader\TravelLoader;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class CreateController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly TravelLoader $travelDataLoader)
|
||||
{}
|
||||
|
||||
#[Route('/bookings/create', name: 'app_booking_create', methods: ['POST'])]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$travelId = $request->query->getInt('travel_id');
|
||||
$hotelId = $request->query->getInt('hotel_id');
|
||||
|
||||
$roomsIdsAndQuantities = $this->getRoomsIdsAndQuantities($request);
|
||||
|
||||
$travelData = $this->travelDataLoader->loadById($travelId, $hotelId);
|
||||
|
||||
if (null === $travelData) {
|
||||
throw $this->createNotFoundException('Travel data not found');
|
||||
}
|
||||
|
||||
$participantsCount = 0;
|
||||
|
||||
$rooms = $travelData->getRoomsByIds(array_keys($roomsIdsAndQuantities));
|
||||
|
||||
foreach ($rooms as $room) {
|
||||
$roomCount = $roomsIdsAndQuantities[$room->id] ?? 0;
|
||||
$participantsCount += $room->minPax * $roomCount;
|
||||
}
|
||||
|
||||
return $this->render('booking/create.html.twig', [
|
||||
'travelData' => $travelData,
|
||||
]);
|
||||
}
|
||||
|
||||
private function getRoomsIdsAndQuantities(Request $request): array
|
||||
{
|
||||
$rooms = $request->request->all('rooms');
|
||||
|
||||
return array_map('intval', array_filter($rooms, 'strlen'));
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use App\BusProNet\XmlLoader\TravelLoader;
|
||||
use App\Controller\Traits\BookingDataTrait;
|
||||
use App\Entity\User;
|
||||
use App\Form\BookingType;
|
||||
use App\Form\Model\BookingData;
|
||||
use App\Form\Model\BookingEditDto;
|
||||
use App\Security\Crypt;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -90,7 +90,7 @@ class EditController extends AbstractController
|
||||
$this->pickupDataLoader->patchPickupsDetails($travelData);
|
||||
|
||||
// Create DTO for form
|
||||
$formData = BookingData::fromBooking($bookingData, $travelData);
|
||||
$formData = BookingEditDto::fromBooking($bookingData, $travelData);
|
||||
|
||||
$form = $this->createForm(BookingType::class, $formData, [
|
||||
'attr' => ['novalidate' => 'novalidate'],
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Controller;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\Form\Model\RegistrationData;
|
||||
use App\Form\Model\RegistrationDto;
|
||||
use App\Form\RegistrationType;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -25,7 +25,7 @@ class RegistrationController extends AbstractController
|
||||
#[IsGranted('PUBLIC_ACCESS')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$registrationData = new RegistrationData();
|
||||
$registrationData = new RegistrationDto();
|
||||
$form = $this->createForm(RegistrationType::class, $registrationData, [
|
||||
'action' => $this->generateUrl('app_registration'),
|
||||
]);
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingData;
|
||||
use App\Form\Model\BookingEditDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -16,7 +17,7 @@ final class BookingType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
/** @var BookingData $data */
|
||||
/** @var BookingEditDto $data */
|
||||
$data = $event->getData();
|
||||
$form = $event->getForm();
|
||||
|
||||
@@ -24,11 +25,11 @@ final class BookingType extends AbstractType
|
||||
$form->add('participants', CollectionType::class, [
|
||||
'entry_type' => ParticipantType::class,
|
||||
'entry_options' => [
|
||||
'selectable_courses' => $this->mergeSelectableServices($data, Service::TOKEN_COURSES),
|
||||
'selectable_ski_passes' => $this->mergeSelectableServices($data, Service::TOKEN_SKI_PASS),
|
||||
'selectable_services' => $this->mergeSelectableServices($data, Service::TOKEN_ADDITIONAL),
|
||||
'selectable_board' => $this->mergeSelectableServices($data, Service::TOKEN_BOARD),
|
||||
'selectable_rentals' => $this->mergeSelectableServices($data, Service::TOKEN_RENTALS),
|
||||
'selectable_courses' => $this->mergeSelectableServices($data, Constants::TOKEN_COURSES),
|
||||
'selectable_ski_passes' => $this->mergeSelectableServices($data, Constants::TOKEN_SKI_PASS),
|
||||
'selectable_services' => $this->mergeSelectableServices($data, Constants::TOKEN_ADDITIONAL),
|
||||
'selectable_board' => $this->mergeSelectableServices($data, Constants::TOKEN_BOARD),
|
||||
'selectable_rentals' => $this->mergeSelectableServices($data, Constants::TOKEN_RENTALS),
|
||||
'selectable_transportation_services_to' => $travelData
|
||||
->getTransportationServicesByDirection('HIN', false),
|
||||
'selectable_transportation_services_fro' => $travelData
|
||||
@@ -46,7 +47,7 @@ final class BookingType extends AbstractType
|
||||
});
|
||||
}
|
||||
|
||||
private function mergeSelectableServices(BookingData $data, mixed $subType): array
|
||||
private function mergeSelectableServices(BookingEditDto $data, mixed $subType): array
|
||||
{
|
||||
// combine selectable services from travel data with additional services
|
||||
// from booking data
|
||||
@@ -67,7 +68,7 @@ final class BookingType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => BookingData::class,
|
||||
'data_class' => BookingEditDto::class,
|
||||
'anti_xss' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class BookingData
|
||||
class BookingEditDto
|
||||
{
|
||||
public ?Booking $booking = null;
|
||||
public ?Travel $travel = null;
|
||||
@@ -25,19 +25,19 @@ class BookingData
|
||||
|
||||
foreach ($booking->participants as $index => $participant) {
|
||||
/** @var PersonalData $participant */
|
||||
$participantData = ParticipantData::fromPersonalData($participant);
|
||||
$participantData = ParticipantDto::fromPersonalData($participant);
|
||||
$participantData->index = $index;
|
||||
|
||||
$participantData->courses = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_COURSES);
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_COURSES);
|
||||
$participantData->skiPass = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_SKI_PASS);
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_SKI_PASS);
|
||||
$participantData->additionalServices = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_ADDITIONAL);
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_ADDITIONAL);
|
||||
$participantData->board = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_BOARD);
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_BOARD);
|
||||
$participantData->rentals = $booking
|
||||
->getAdditionalServicesForParticipantByGroup($index, Service::TOKEN_RENTALS);
|
||||
->getAdditionalServicesForParticipantByGroup($index, Constants::TOKEN_RENTALS);
|
||||
// Different keys for direction used in booking data (H <=> HIN, R <=> RUECK)!
|
||||
$participantData->transportationServiceTo = $booking
|
||||
->getTransportationServiceForParticipantAndDirection($index, 'H');
|
||||
@@ -9,7 +9,7 @@ use App\Validator\Constraints as AppAssert;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[AppAssert\Participant]
|
||||
class ParticipantData
|
||||
class ParticipantDto
|
||||
{
|
||||
public ?int $index = null;
|
||||
public ?int $addressId = null;
|
||||
@@ -4,7 +4,7 @@ namespace App\Form\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class RegistrationData
|
||||
class RegistrationDto
|
||||
{
|
||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
||||
public ?string $firstName = null;
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Form\CountryType;
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\ParticipantData;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
@@ -21,7 +22,7 @@ class ParticipantType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
|
||||
/** @var ParticipantData $participantData */
|
||||
/** @var ParticipantDto $participantData */
|
||||
$participantData = $event->getData();
|
||||
$participantIndex = $participantData->index;
|
||||
|
||||
@@ -166,12 +167,12 @@ class ParticipantType extends AbstractType
|
||||
}
|
||||
|
||||
// disable selection of services only available in booking data
|
||||
if (Service::SOURCE_BOOKING === $service->source) {
|
||||
if (Constants::SOURCE_BOOKING === $service->source) {
|
||||
$attributes['class'] = 'text-pink';
|
||||
}
|
||||
|
||||
// disable selection of services that are unavailable according to their status
|
||||
if (Service::STATUS_BLOCKED === $service->status) {
|
||||
if (Constants::STATUS_BLOCKED === $service->status) {
|
||||
$attributes['checked'] = false;
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['tooltip'] = 'Diese Leistung ist derzeit leider nicht buchbar';
|
||||
@@ -191,8 +192,8 @@ class ParticipantType extends AbstractType
|
||||
// remove choices only available in booking data and
|
||||
// which are not mapped to the current participant
|
||||
if (
|
||||
Service::SOURCE_TRAVEL === $service->source
|
||||
|| Service::CATEGORY_ADDITIONAL !== $service->category
|
||||
Constants::SOURCE_TRAVEL === $service->source
|
||||
|| Constants::CATEGORY_ADDITIONAL !== $service->category
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@@ -249,7 +250,7 @@ class ParticipantType extends AbstractType
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['tooltip'] = 'Diese Leistung kann nicht mehr geändert werden';
|
||||
}
|
||||
if (Service::STATUS_BLOCKED === $service->status) {
|
||||
if (Constants::STATUS_BLOCKED === $service->status) {
|
||||
$attributes['checked'] = false;
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['tooltip'] = 'Diese Leistung ist derzeit leider nicht buchbar';
|
||||
@@ -341,7 +342,7 @@ class ParticipantType extends AbstractType
|
||||
$participantIndex = $form->getData()->index;
|
||||
|
||||
return true === $service->mandatory
|
||||
|| (Service::SOURCE_BOOKING === $service->source && in_array($participantIndex, $service->mapping));
|
||||
|| (Constants::SOURCE_BOOKING === $service->source && in_array($participantIndex, $service->mapping));
|
||||
});
|
||||
|
||||
if (0 < count($mandatoryServices)) {
|
||||
@@ -364,7 +365,7 @@ class ParticipantType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => ParticipantData::class,
|
||||
'data_class' => ParticipantDto::class,
|
||||
'selectable_courses' => [],
|
||||
'selectable_ski_passes' => [],
|
||||
'selectable_services' => [],
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Form\Model\RegistrationData;
|
||||
use App\Form\Model\RegistrationDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
@@ -39,7 +39,7 @@ class RegistrationType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => RegistrationData::class,
|
||||
'data_class' => RegistrationDto::class,
|
||||
'anti_xss' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Validator\Constraints;
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Model\BookingUpdate;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Form\Model\BookingData;
|
||||
use App\Form\Model\BookingEditDto;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
@@ -17,7 +17,7 @@ class BookingValidator extends ConstraintValidator
|
||||
|
||||
public function validate(mixed $value, Constraint $constraint): void
|
||||
{
|
||||
/** @var BookingData $booking */
|
||||
/** @var BookingEditDto $booking */
|
||||
$bookingData = $value;
|
||||
|
||||
$result = $this->apiClient->updateBooking($bookingData);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use App\Form\Model\ParticipantData;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
@@ -10,7 +10,7 @@ class ParticipantValidator extends ConstraintValidator
|
||||
{
|
||||
public function validate(mixed $value, Constraint $constraint): void
|
||||
{
|
||||
/** @var ParticipantData $participant */
|
||||
/** @var ParticipantDto $participant */
|
||||
$participant = $value;
|
||||
|
||||
$this->assertBodyMeasurementsValid($participant);
|
||||
@@ -18,7 +18,7 @@ class ParticipantValidator extends ConstraintValidator
|
||||
$this->assertPickupSelected($participant);
|
||||
}
|
||||
|
||||
public function assertBodyMeasurementsValid(ParticipantData $participant): void
|
||||
public function assertBodyMeasurementsValid(ParticipantDto $participant): void
|
||||
{
|
||||
if (0 === count($participant->rentals)) {
|
||||
return;
|
||||
@@ -34,7 +34,7 @@ class ParticipantValidator extends ConstraintValidator
|
||||
}
|
||||
}
|
||||
|
||||
public function assertTransportationSelected(ParticipantData $participant): void
|
||||
public function assertTransportationSelected(ParticipantDto $participant): void
|
||||
{
|
||||
// no transportation services required for canceled participants
|
||||
if (true === $participant->isCanceled()) {
|
||||
@@ -51,7 +51,7 @@ class ParticipantValidator extends ConstraintValidator
|
||||
}
|
||||
}
|
||||
|
||||
public function assertPickupSelected(ParticipantData $participant): void
|
||||
public function assertPickupSelected(ParticipantDto $participant): void
|
||||
{
|
||||
if (
|
||||
null !== $participant->transportationServiceTo
|
||||
|
||||
Reference in New Issue
Block a user