refactor: drop edit-mode room assignment code

This commit is contained in:
fromme committed 2026-11-09 18:01:25 +01:00
1 parent d50995a21c
commit 9ce42de4c1
3 files changed
+6 -48

No files matched your search

@@ -153,7 +153,6 @@ class BookingDataProcessor
$roomSelection->price = $room->price; $roomSelection->price = $room->price;
$roomSelection->quantity = $bookingRoom->totalCount; // Actual quantity from booking XML (anzahl) $roomSelection->quantity = $bookingRoom->totalCount; // Actual quantity from booking XML (anzahl)
$roomSelection->capacity = $room->minPax ?? 1; $roomSelection->capacity = $room->minPax ?? 1;
$roomSelection->maxQuantity = $bookingRoom->totalCount + ($room->available ?? 0);
$dto->roomSelections[] = $roomSelection; $dto->roomSelections[] = $roomSelection;
} }
} }
@@ -76,7 +76,7 @@ class ParticipantAssignedRoomFieldHandler extends AbstractParticipantFieldHandle
* 6. Updates the participant's assignedRoomId property * 6. Updates the participant's assignedRoomId property
* *
* @param array<string, mixed> $submittedData The submitted participant form data * @param array<string, mixed> $submittedData The submitted participant form data
* @param BookingDto $bookingDto The booking DTO to update (create or edit) * @param BookingDto $bookingDto The booking DTO to update
* @param int $participantIndex The index of the participant being processed * @param int $participantIndex The index of the participant being processed
*/ */
public function processField(array $submittedData, BookingDto $bookingDto, int $participantIndex): void public function processField(array $submittedData, BookingDto $bookingDto, int $participantIndex): void
@@ -133,15 +133,8 @@ class ParticipantAssignedRoomFieldHandler extends AbstractParticipantFieldHandle
return false; return false;
} }
// Calculate total capacity for this room type // Calculate total capacity for this room type from the step 1 selection
// In edit mode, use maxQuantity which includes available rooms beyond the booked count. $totalCapacity = ($roomSelection->quantity ?? 0) * $roomSelection->capacity;
// In create mode, use quantity which is the user's room selection from step 1.
if (BookingDto::MODE_EDIT === $bookingDto->getMode()) {
$effectiveQuantity = $roomSelection->maxQuantity;
} else {
$effectiveQuantity = $roomSelection->quantity ?? 0;
}
$totalCapacity = $effectiveQuantity * $roomSelection->capacity;
// Count current occupancy (excluding current participant) // Count current occupancy (excluding current participant)
$occupancy = 0; $occupancy = 0;
@@ -193,12 +186,7 @@ class ParticipantAssignedRoomFieldHandler extends AbstractParticipantFieldHandle
return; // Shouldn't happen return; // Shouldn't happen
} }
if (BookingDto::MODE_EDIT === $bookingDto->getMode()) { $totalCapacity = ($roomSelection->quantity ?? 0) * $roomSelection->capacity;
$effectiveQuantity = $roomSelection->maxQuantity;
} else {
$effectiveQuantity = $roomSelection->quantity ?? 0;
}
$totalCapacity = $effectiveQuantity * $roomSelection->capacity;
$currentOccupancy = count($participantsWithRoom); $currentOccupancy = count($participantsWithRoom);
$spacesNeeded = ($currentOccupancy + 1) - $totalCapacity; $spacesNeeded = ($currentOccupancy + 1) - $totalCapacity;
@@ -8,7 +8,6 @@ use App\BusProNet\Constants;
use App\BusProNet\Model\Booking; use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Insurance; use App\BusProNet\Model\Insurance;
use App\BusProNet\Model\Pickup; use App\BusProNet\Model\Pickup;
use App\BusProNet\Model\Room;
use App\BusProNet\Model\Service; use App\BusProNet\Model\Service;
use App\BusProNet\Utility\DirectionMapper; use App\BusProNet\Utility\DirectionMapper;
use App\Form\Model\BookingDto; use App\Form\Model\BookingDto;
@@ -86,21 +85,18 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
*/ */
protected function registerFieldOptionProviders(): void protected function registerFieldOptionProviders(): void
{ {
// Room assignment field provider (available for both create and edit workflows) // Room assignment field provider (create only: edit mode renders the room as static text)
// Returns empty array when no room choices available // Returns empty array when no room choices available
$this->fieldOptionProviders['assignedRoomId'] = function (BookingDto $bookingDto, int $participantIndex, array $options = []): array { $this->fieldOptionProviders['assignedRoomId'] = function (BookingDto $bookingDto, int $participantIndex, array $options = []): array {
$choices = []; $choices = [];
if (BookingDto::MODE_CREATE === $bookingDto->getMode()) { if (BookingDto::MODE_CREATE === $bookingDto->getMode()) {
// Create context: use selected rooms from step 1, filtered by participant age // Use selected rooms from step 1, filtered by participant age
$choices = $this->filterRoomsByParticipantAge( $choices = $this->filterRoomsByParticipantAge(
$bookingDto->getSelectedRooms(), $bookingDto->getSelectedRooms(),
$bookingDto, $bookingDto,
$participantIndex $participantIndex
); );
} elseif (BookingDto::MODE_EDIT === $bookingDto->getMode()) {
// Edit context: convert booked rooms to RoomSelectionDto for consistent handling
$choices = $this->convertBookedRoomsToSelectionDtos($bookingDto->booking->rooms);
} }
if (true === empty($choices)) { if (true === empty($choices)) {
@@ -782,31 +778,6 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
}); });
} }
/**
* Converts booked Room objects to RoomSelectionDto for consistent form handling.
*
* In edit mode, we need to convert Room entities to RoomSelectionDto objects
* so the form can use the same choice_value and choice_label configuration
* as create mode, enabling consistent price display in the template.
*
* @param Room[] $bookedRooms Rooms from existing booking
*
* @return RoomSelectionDto[] Array of room selection DTOs
*/
private function convertBookedRoomsToSelectionDtos(array $bookedRooms): array
{
$selections = [];
foreach ($bookedRooms as $room) {
$selection = new RoomSelectionDto();
$selection->id = $room->id;
$selection->label = $room->label;
$selection->price = $room->price;
$selections[] = $selection;
}
return $selections;
}
/** /**
* Filters rental services by selected skipass duration. * Filters rental services by selected skipass duration.
* *