wip: improved booking summary
This commit is contained in:
@@ -17,6 +17,9 @@ use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
*/
|
||||
class Room
|
||||
{
|
||||
public const SELECTION_TYPE_BY_PAX = 'by_pax';
|
||||
public const SELECTION_TYPE_BY_ROOM = 'by_room';
|
||||
|
||||
#[Groups(['api:list', 'api:single'])]
|
||||
public ?int $id = null;
|
||||
|
||||
@@ -72,4 +75,17 @@ class Room
|
||||
|
||||
#[Groups(['booking'])]
|
||||
public array $individualPrice = [];
|
||||
|
||||
/**
|
||||
* Determines the selection type of the room based on its label.
|
||||
*
|
||||
* @return string Either self::SELECTION_TYPE_BY_PAX or self::SELECTION_TYPE_BY_ROOM
|
||||
*/
|
||||
public function getSelectionType(): string
|
||||
{
|
||||
if (1 === preg_match('/bett/i', $this->label)) {
|
||||
return self::SELECTION_TYPE_BY_PAX;
|
||||
}
|
||||
return self::SELECTION_TYPE_BY_ROOM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,12 +188,16 @@ class Travel
|
||||
* greater than zero and have an available status. This ensures only
|
||||
* bookable rooms are returned for selection.
|
||||
*
|
||||
* @return array<Room> The filtered array of available rooms
|
||||
* @return array<int, Room> The filtered array of available rooms, indexed by room ID
|
||||
*/
|
||||
public function getAvailableRooms(): array
|
||||
{
|
||||
return array_filter($this->rooms, function (Room $room) {
|
||||
return $room->available > 0 && Constants::STATUS_AVAILABLE === $room->status;
|
||||
});
|
||||
$result = [];
|
||||
foreach ($this->rooms as $room) {
|
||||
if ($room->available > 0 && Constants::STATUS_AVAILABLE === $room->status) {
|
||||
$result[$room->id] = $room;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ class CreateStep1Controller extends AbstractController
|
||||
|
||||
public function __construct(
|
||||
private readonly BookingService $bookingService,
|
||||
) {
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,11 +52,17 @@ class CreateStep1Controller extends AbstractController
|
||||
return $this->redirectToRoute('app_booking_create_step_2');
|
||||
}
|
||||
|
||||
$availableRooms = $bookingCreateDto->travel->getAvailableRooms();
|
||||
$groupedRooms = $this->bookingService->groupRoomsBySelectionType($availableRooms);
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($summary['selectedRooms'], $availableRooms);
|
||||
|
||||
return $this->render('booking/create_step_1.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'roomSummary' => $summary['selectedRooms'],
|
||||
'participantCount' => $summary['participantCount'],
|
||||
'form' => $form->createView(),
|
||||
'groupedRooms' => $groupedRooms,
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -76,10 +83,14 @@ class CreateStep1Controller extends AbstractController
|
||||
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto);
|
||||
$availableRooms = $bookingCreateDto->travel->getAvailableRooms();
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($summary['selectedRooms'], $availableRooms);
|
||||
|
||||
return $this->render('booking/_room_summary.html.twig', [
|
||||
return $this->render('booking/_summary.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'roomSummary' => $summary['selectedRooms'],
|
||||
'participantCount' => $summary['participantCount'],
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,12 +64,15 @@ class CreateStep2Controller extends AbstractController
|
||||
}
|
||||
|
||||
$roomAssignmentCounts = $this->bookingService->getRoomAssignmentCounts($bookingCreateDto);
|
||||
$availableRooms = $bookingCreateDto->travel->getAvailableRooms();
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($bookingCreateDto->getSelectedRooms(), $availableRooms);
|
||||
|
||||
return $this->render('booking/create_step_2.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'participantsCount' => $participantsCount,
|
||||
'assignmentCounts' => $roomAssignmentCounts,
|
||||
'form' => $form->createView(),
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -93,6 +96,8 @@ class CreateStep2Controller extends AbstractController
|
||||
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
$roomAssignmentCounts = $this->bookingService->getRoomAssignmentCounts($bookingCreateDto);
|
||||
$availableRooms = $bookingCreateDto->travel->getAvailableRooms();
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($bookingCreateDto->getSelectedRooms(), $availableRooms);
|
||||
|
||||
// The DTO is now updated with the latest selection.
|
||||
// We can now render the blocks with the fresh data.
|
||||
@@ -104,6 +109,7 @@ class CreateStep2Controller extends AbstractController
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'participantsCount' => $participantsCount,
|
||||
'assignmentCounts' => $roomAssignmentCounts,
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,4 @@ class RoomSelectionDto
|
||||
public int $maxQuantity = 100;
|
||||
|
||||
public int $minPax = 0;
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
if (1 === preg_match('/bett/i', $this->roomLabel)) {
|
||||
return 'by_pax';
|
||||
}
|
||||
|
||||
return 'by_room';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,4 +137,51 @@ class BookingService
|
||||
'participantCount' => $participantCount,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups available rooms by selection type ('by_pax' or 'by_room').
|
||||
*
|
||||
* @param array<int, Room> $rooms Rooms indexed by room ID
|
||||
* @return array{by_pax: array<int, Room>, by_room: array<int, Room>}
|
||||
*/
|
||||
public function groupRoomsBySelectionType(array $rooms): array
|
||||
{
|
||||
$groups = [
|
||||
'by_pax' => [],
|
||||
'by_room' => [],
|
||||
];
|
||||
foreach ($rooms as $room) {
|
||||
if (stripos($room->label, 'bett') !== false) {
|
||||
$groups['by_pax'][$room->id] = $room;
|
||||
} else {
|
||||
$groups['by_room'][$room->id] = $room;
|
||||
}
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups roomSelections by selection type ('by_pax' or 'by_room'), using Room::getSelectionType().
|
||||
*
|
||||
* @param array $roomSelections Array of selected RoomSelectionDto
|
||||
* @param array<int, Room> $roomsById Rooms indexed by room ID
|
||||
* @return array{by_pax: array, by_room: array}
|
||||
*/
|
||||
public function groupRoomSelectionsByType(array $roomSelections, array $roomsById): array
|
||||
{
|
||||
$groups = [
|
||||
'by_pax' => [],
|
||||
'by_room' => [],
|
||||
];
|
||||
foreach ($roomSelections as $roomSelection) {
|
||||
$room = $roomsById[$roomSelection->roomId] ?? null;
|
||||
if ($room) {
|
||||
$type = $room->getSelectionType();
|
||||
$groups[$type][] = $roomSelection;
|
||||
}
|
||||
}
|
||||
|
||||
return $groups;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user