From 054505d85369dec02ebcdfcc669c62211dbdc418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 15 Jan 2026 11:02:27 +0100 Subject: [PATCH] feat: match modes for room selection condition to detect MBZ* addresses #869btdcyh --- .../Condition/RoomSelectionCondition.php | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/Form/Service/Condition/RoomSelectionCondition.php b/src/Form/Service/Condition/RoomSelectionCondition.php index cb21b78..3631c47 100644 --- a/src/Form/Service/Condition/RoomSelectionCondition.php +++ b/src/Form/Service/Condition/RoomSelectionCondition.php @@ -17,16 +17,22 @@ use App\Form\Service\Contract\FieldConditionInterface; */ class RoomSelectionCondition implements FieldConditionInterface { + private const MATCH_MODE_EXACT = 'exact'; + private const MATCH_MODE_PREFIX = 'prefix'; + private array $requiredRoomCodes; + private string $matchMode; /** * Creates a new room selection condition for specified room codes. * * @param array $requiredRoomCodes Room codes that should trigger this condition + * @param string $matchMode Match mode: 'prefix' (default) or 'exact' */ - public function __construct(array $requiredRoomCodes) + public function __construct(array $requiredRoomCodes, string $matchMode = self::MATCH_MODE_PREFIX) { $this->requiredRoomCodes = array_map('strtolower', $requiredRoomCodes); + $this->matchMode = $matchMode; } /** @@ -48,7 +54,7 @@ class RoomSelectionCondition implements FieldConditionInterface $selectedRoomId = $formData['participants'][$participantIndex]['assignedRoomId']; if (true === is_numeric($selectedRoomId)) { $room = $this->findRoomById((int) $selectedRoomId, $bookingDto); - if (null !== $room && in_array(strtolower($room->code ?? ''), $this->requiredRoomCodes, true)) { + if (null !== $room && $this->matchesRoomCode($room->code ?? '')) { return true; } } @@ -58,7 +64,7 @@ class RoomSelectionCondition implements FieldConditionInterface $participant = $bookingDto->getParticipant($participantIndex); if (null !== $participant && null !== $participant->assignedRoomId) { $room = $this->findRoomById($participant->assignedRoomId, $bookingDto); - if (null !== $room && in_array(strtolower($room->code ?? ''), $this->requiredRoomCodes, true)) { + if (null !== $room && $this->matchesRoomCode($room->code ?? '')) { return true; } } @@ -87,8 +93,9 @@ class RoomSelectionCondition implements FieldConditionInterface public function getDescription(): string { $codes = implode(', ', $this->requiredRoomCodes); + $matchType = self::MATCH_MODE_PREFIX === $this->matchMode ? 'starting with' : 'matching'; - return "Field visible when room with code(s) [{$codes}] is selected"; + return "Field visible when room with code(s) {$matchType} [{$codes}] is selected"; } /** @@ -109,4 +116,28 @@ class RoomSelectionCondition implements FieldConditionInterface return null; } + + /** + * Checks if a room code matches any of the required codes based on match mode. + * + * @param string $roomCode The room code to check + * + * @return bool True if the room code matches, false otherwise + */ + private function matchesRoomCode(string $roomCode): bool + { + $roomCode = strtolower($roomCode); + + if (self::MATCH_MODE_PREFIX === $this->matchMode) { + foreach ($this->requiredRoomCodes as $code) { + if (str_starts_with($roomCode, $code)) { + return true; + } + } + + return false; + } + + return in_array($roomCode, $this->requiredRoomCodes, true); + } }