feat: automatically assign rooms only for unique room type selection

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent 513c889926
commit 6cc5886073
6 changed files with 302 additions and 14 deletions
+31
View File
@@ -14,6 +14,30 @@ use App\Form\Model\BookingDto;
*/
class RoomAssignmentService
{
/**
* Determines if automatic room assignment should be performed.
*
* Auto-assignment is only performed when exactly one room type is selected to avoid
* UX issues with individual participant forms. With multiple room types, users should
* manually select rooms to avoid having to unselect preassigned rooms.
*
* @param BookingDto $dto The booking DTO containing room selections
*
* @return bool True if auto-assignment should proceed, false otherwise
*/
public function shouldAutoAssignRooms(BookingDto $dto): bool
{
$selectedRoomTypeCount = 0;
foreach ($dto->roomSelections as $roomSelection) {
if (null !== $roomSelection->quantity && $roomSelection->quantity > 0) {
++$selectedRoomTypeCount;
}
}
return 1 === $selectedRoomTypeCount;
}
/**
* Automatically assigns participants to rooms based on selected room quantities and capacities.
*
@@ -26,10 +50,17 @@ class RoomAssignmentService
* - 2x "Doppelzimmer" (capacity 2) = participants 0-1 → room A, participants 2-3 → room A
* - 1x "3-Bett-Zimmer" (capacity 3) = participants 4-6 → room B
*
* Note: Only performs assignment if shouldAutoAssignRooms() returns true.
*
* @param BookingDto $dto The booking DTO containing room selections and participants
*/
public function assignParticipantsToRooms(BookingDto $dto): void
{
// Skip auto-assignment if multiple room types selected
if (false === $this->shouldAutoAssignRooms($dto)) {
return;
}
$participantIndex = 0;
$selectedRooms = $dto->getSelectedRooms();
$availableRooms = $dto->travel->getAvailableRooms();