feat: extensible participant status determination for booking creation

Adds a rule-based system to determine participant status in CREATE
payloads. Participants selecting a 'Begleitperson' service now receive
status 'O' (Option), all others default to 'F' (Final).

- Add ParticipantStatusRuleInterface for defining status rules
- Add ParticipantStatusRuleRegistry for priority-based rule evaluation
- Add ChaperonServiceStatusRule for Begleitperson detection
- Integrate status evaluation into BookingPayloadBuilder
This commit is contained in:
Björn Fromme
2026-01-21 10:16:57 +01:00
parent 512b63b88b
commit 2aeed762fd
10 changed files with 525 additions and 4 deletions
@@ -6,6 +6,7 @@ namespace App\BusProNet\DataProcessor;
use App\BusProNet\Constants;
use App\BusProNet\Model\Booking;
use App\BusProNet\Service\ParticipantStatusRuleRegistry;
use App\Form\Model\BookingDto;
/**
@@ -18,6 +19,7 @@ class BookingPayloadBuilder
{
public function __construct(
private readonly ServiceMappingCollector $mappingCollector,
private readonly ParticipantStatusRuleRegistry $statusRuleRegistry,
) {
}
@@ -275,6 +277,7 @@ class BookingPayloadBuilder
foreach ($bookingDto->participants as $index => $participant) {
$participantData = [
'@id' => $index + 1,
'status' => $this->statusRuleRegistry->evaluateStatus($participant),
'name' => $participant->lastName,
'vorname' => $participant->firstName,
'geschlecht' => $participant->gender ?? '',
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace App\BusProNet\Service\Contract;
use App\Form\Model\ParticipantDto;
/**
* Defines the contract for participant status evaluation rules.
*
* Status rules are evaluated in priority order to determine the appropriate
* status code for a participant during booking creation. The first rule that
* matches (evaluate returns true) determines the participant's status.
*/
interface ParticipantStatusRuleInterface
{
/**
* Evaluates whether this rule applies to the given participant.
*
* @param ParticipantDto $participant The participant to evaluate
*
* @return bool True if this rule applies, false otherwise
*/
public function evaluate(ParticipantDto $participant): bool;
/**
* Returns the status code to assign when this rule matches.
*
* @return string The status code (e.g., 'O' for Option, 'F' for Final)
*/
public function getStatus(): string;
/**
* Returns the priority of this rule.
*
* Higher priority rules are evaluated first. Rules with the same priority
* are evaluated in registration order.
*
* @return int The priority value (higher = evaluated first)
*/
public function getPriority(): int;
/**
* Returns a human-readable description of this rule.
*
* Used for debugging and logging purposes.
*
* @return string Description of what this rule checks
*/
public function getDescription(): string;
}
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace App\BusProNet\Service;
use App\BusProNet\Service\Contract\ParticipantStatusRuleInterface;
use App\Form\Model\ParticipantDto;
/**
* Registry for participant status evaluation rules.
*
* Manages a collection of status rules and evaluates them in priority order
* to determine the appropriate status code for a participant during booking
* creation. Returns a default status of 'F' (Final) when no rules match.
*/
class ParticipantStatusRuleRegistry
{
private const DEFAULT_STATUS = 'F';
/**
* @var ParticipantStatusRuleInterface[]
*/
private array $sortedRules;
/**
* @param ParticipantStatusRuleInterface[] $rules The rules to register
*/
public function __construct(array $rules)
{
$this->sortedRules = $this->sortRulesByPriority($rules);
}
/**
* Evaluates all rules to determine the participant's status.
*
* Rules are evaluated in priority order (highest first). The first rule
* that matches determines the status. Returns 'F' if no rules match.
*
* @param ParticipantDto $participant The participant to evaluate
*
* @return string The determined status code
*/
public function evaluateStatus(ParticipantDto $participant): string
{
foreach ($this->sortedRules as $rule) {
if (true === $rule->evaluate($participant)) {
return $rule->getStatus();
}
}
return self::DEFAULT_STATUS;
}
/**
* Sorts rules by priority in descending order.
*
* @param ParticipantStatusRuleInterface[] $rules The rules to sort
*
* @return ParticipantStatusRuleInterface[] The sorted rules
*/
private function sortRulesByPriority(array $rules): array
{
usort($rules, static fn (
ParticipantStatusRuleInterface $a,
ParticipantStatusRuleInterface $b,
): int => $b->getPriority() <=> $a->getPriority());
return $rules;
}
}
@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace App\BusProNet\Service\StatusRule;
use App\BusProNet\Model\Service;
use App\BusProNet\Service\Contract\ParticipantStatusRuleInterface;
use App\Form\Model\ParticipantDto;
/**
* Status rule for participants with chaperon (Begleitperson) services.
*
* Assigns 'Option' status to participants who have selected any service
* containing 'Begleitperson' in its label. This applies to accompanying
* persons whose booking confirmation may depend on the main participant.
*/
class ChaperonServiceStatusRule implements ParticipantStatusRuleInterface
{
private const STATUS = 'O';
private const PRIORITY = 100;
private const SEARCH_TERM = 'begleitperson';
/**
* @see ParticipantStatusRuleInterface::evaluate()
*/
public function evaluate(ParticipantDto $participant): bool
{
// Check array services
$arrayServices = [
$participant->additionalServices,
$participant->courses,
$participant->board,
$participant->rentals,
];
foreach ($arrayServices as $services) {
foreach ($services as $service) {
if ($service instanceof Service && true === $this->containsSearchTerm($service->label)) {
return true;
}
}
}
// Check single service properties
$singleServices = [
$participant->skiPass,
$participant->veg,
];
foreach ($singleServices as $service) {
if ($service instanceof Service && true === $this->containsSearchTerm($service->label)) {
return true;
}
}
return false;
}
/**
* @see ParticipantStatusRuleInterface::getStatus()
*/
public function getStatus(): string
{
return self::STATUS;
}
/**
* @see ParticipantStatusRuleInterface::getPriority()
*/
public function getPriority(): int
{
return self::PRIORITY;
}
/**
* @see ParticipantStatusRuleInterface::getDescription()
*/
public function getDescription(): string
{
return 'Assigns Option status when a Begleitperson service is selected';
}
/**
* Checks if the label contains the search term (case-insensitive).
*/
private function containsSearchTerm(?string $label): bool
{
if (null === $label) {
return false;
}
return false !== stripos($label, self::SEARCH_TERM);
}
}
@@ -75,7 +75,7 @@ class Step3Controller extends AbstractController
return $this->handleApiError(
'Booking inquiry failed',
['message' => $inquiryResponse->message],
$inquiryResponse->message ?? 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.',
$inquiryResponse->message ?? 'Ein Fehler ist aufgetreten. Bitte versuche es erneut.',
$bookingCreateDto,
$form
);
@@ -285,9 +285,9 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
}
$priceLabel = (null === $service->price || 0.0 === $service->price)
? 'inkl.'
: number_format($service->price, 2, ',', '.') . ' €';
: number_format($service->price, 2, ',', '.').' €';
return $service->label . ' (' . $priceLabel . ')';
return $service->label.' ('.$priceLabel.')';
},
'choice_attr' => function (?Service $service) use ($bookingDto, $participantIndex) {
if (null === $service) {