feat: automatically assign rooms only for unique room type selection

This commit is contained in:
Björn Fromme
2025-10-20 15:29:33 +02:00
parent 8c75d0070d
commit cc1d1e5746
6 changed files with 302 additions and 14 deletions
@@ -254,6 +254,10 @@ class Step2Controller extends AbstractController
/**
* Automatically assigns participants to rooms if they don't have room assignments yet.
*
* Note: Auto-assignment only occurs when exactly one room type is selected.
* With multiple room types, users must manually select rooms to avoid UX issues
* with having to unselect preassigned rooms in individual participant forms.
*/
private function autoAssignRoomsIfNeeded(BookingDto $bookingCreateDto): void
{
@@ -270,5 +274,4 @@ class Step2Controller extends AbstractController
$this->roomAssignmentService->assignParticipantsToRooms($bookingCreateDto);
}
}
}
@@ -103,6 +103,9 @@ class ParticipantCardDataService
/**
* Calculate and format individual participant price.
*
* Returns a dash (-) when the price is zero and no room is assigned,
* indicating incomplete configuration rather than a zero-cost booking.
*/
private function getFormattedPrice(BookingDto $bookingDto, int $index): string
{
@@ -110,6 +113,12 @@ class ParticipantCardDataService
$price = $prices[$index] ?? 0.0;
// Display dash when price is zero and no room assigned (incomplete configuration)
$participant = $bookingDto->participants[$index] ?? null;
if (0.0 === $price && (null === $participant || null === $participant->assignedRoomId)) {
return '-';
}
return number_format($price, 2, ',', '.').' €';
}
}
+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();