feat: move scope of enforced 'option' status to full booking

addresses #869chtfeq
This commit is contained in:
Björn Fromme committed 2026-03-19 16:15:07 +01:00
1 parent 45d05786da
commit df8566e1b5
19 files changed
+388 -329

No files matched your search

@@ -6,7 +6,6 @@ namespace App\BusProNet\DataProcessor;
use App\BusProNet\Constants;
use App\BusProNet\Model\Booking;
use App\BusProNet\Service\ParticipantStatusRuleRegistry;
use App\Form\Model\BookingDto;
/**
@@ -17,9 +16,10 @@ use App\Form\Model\BookingDto;
*/
class BookingPayloadBuilder
{
private const DEFAULT_PARTICIPANT_STATUS = 'F';
public function __construct(
private readonly ServiceMappingCollector $mappingCollector,
private readonly ParticipantStatusRuleRegistry $statusRuleRegistry,
) {
}
@@ -302,7 +302,7 @@ class BookingPayloadBuilder
foreach ($bookingDto->participants as $index => $participant) {
$participantData = [
'@id' => $index + 1,
'status' => $this->statusRuleRegistry->evaluateStatus($participant),
'status' => self::DEFAULT_PARTICIPANT_STATUS,
'name' => $participant->lastName,
'vorname' => $participant->firstName,
'geschlecht' => $participant->gender ?? '',
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace App\BusProNet\Service;
use App\BusProNet\Service\Contract\BookingStatusRuleInterface;
use App\Form\Model\BookingDto;
/**
* Registry for booking status evaluation rules.
*
* Evaluates registered rules in priority order and returns the first matching
* status. Falls back to 'F' when no rule applies.
*/
class BookingStatusRuleRegistry
{
private const DEFAULT_STATUS = 'F';
/**
* @var BookingStatusRuleInterface[]
*/
private array $sortedRules;
/**
* @param BookingStatusRuleInterface[] $rules
*/
public function __construct(array $rules)
{
$this->sortedRules = $this->sortRulesByPriority($rules);
}
public function evaluateStatus(BookingDto $bookingDto): string
{
foreach ($this->sortedRules as $rule) {
if (true === $rule->evaluate($bookingDto)) {
return $rule->getStatus();
}
}
return self::DEFAULT_STATUS;
}
/**
* @param BookingStatusRuleInterface[] $rules
*
* @return BookingStatusRuleInterface[]
*/
private function sortRulesByPriority(array $rules): array
{
usort($rules, static fn (
BookingStatusRuleInterface $a,
BookingStatusRuleInterface $b,
): int => $b->getPriority() <=> $a->getPriority());
return $rules;
}
}
@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\BusProNet\Service\Contract;
use App\Form\Model\BookingDto;
/**
* Defines the contract for booking status evaluation rules.
*
* Rules are evaluated in priority order. The first matching rule determines
* the enforced booking status.
*/
interface BookingStatusRuleInterface
{
/**
* Evaluates whether this rule applies to the given booking.
*/
public function evaluate(BookingDto $bookingDto): bool;
/**
* Returns the status code to assign when this rule matches.
*/
public function getStatus(): string;
/**
* Returns the rule priority (higher values evaluated first).
*/
public function getPriority(): int;
/**
* Returns a human-readable rule description.
*/
public function getDescription(): string;
}
@@ -1,52 +0,0 @@
<?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;
}
@@ -1,71 +0,0 @@
<?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;
}
}
@@ -5,26 +5,37 @@ declare(strict_types=1);
namespace App\BusProNet\Service\StatusRule;
use App\BusProNet\Model\Service;
use App\BusProNet\Service\Contract\ParticipantStatusRuleInterface;
use App\BusProNet\Service\Contract\BookingStatusRuleInterface;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
/**
* Status rule for participants with chaperon (Begleitperson) services.
* Status rule for bookings 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.
* Assigns 'Option' status to bookings where any participant has selected any
* service containing 'Begleitperson' in its label.
*/
class ChaperonServiceStatusRule implements ParticipantStatusRuleInterface
class ChaperonServiceStatusRule implements BookingStatusRuleInterface
{
private const STATUS = 'O';
private const PRIORITY = 100;
private const SEARCH_TERM = 'begleitperson';
/**
* @see ParticipantStatusRuleInterface::evaluate()
* @see BookingStatusRuleInterface::evaluate()
*/
public function evaluate(ParticipantDto $participant): bool
public function evaluate(BookingDto $bookingDto): bool
{
foreach ($bookingDto->participants as $participant) {
if (true === $this->participantHasChaperonService($participant)) {
return true;
}
}
return false;
}
private function participantHasChaperonService(ParticipantDto $participant): bool
{
// Check array services
$arrayServices = [
@@ -58,7 +69,7 @@ class ChaperonServiceStatusRule implements ParticipantStatusRuleInterface
}
/**
* @see ParticipantStatusRuleInterface::getStatus()
* @see BookingStatusRuleInterface::getStatus()
*/
public function getStatus(): string
{
@@ -66,7 +77,7 @@ class ChaperonServiceStatusRule implements ParticipantStatusRuleInterface
}
/**
* @see ParticipantStatusRuleInterface::getPriority()
* @see BookingStatusRuleInterface::getPriority()
*/
public function getPriority(): int
{
@@ -74,7 +85,7 @@ class ChaperonServiceStatusRule implements ParticipantStatusRuleInterface
}
/**
* @see ParticipantStatusRuleInterface::getDescription()
* @see BookingStatusRuleInterface::getDescription()
*/
public function getDescription(): string
{