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. * * Assignment algorithm: * - Iterates through selected rooms in order * - For each room quantity, assigns minPax participants to that room ID * - Ensures sequential assignment (participant 0, 1, 2, etc.) * * Example: * - 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(); foreach ($selectedRooms as $roomSelection) { $room = $availableRooms[$roomSelection->roomId] ?? null; if (null === $room) { continue; // Skip if room not found } $capacityPerRoom = $room->minPax ?? 1; // Assign participants for each room quantity for ($i = 0; $i < $roomSelection->quantity; ++$i) { // Assign participants according to room capacity for ($j = 0; $j < $capacityPerRoom; ++$j) { if (isset($dto->participants[$participantIndex])) { $dto->participants[$participantIndex]->assignedRoomId = $room->id; ++$participantIndex; } } } } } }