feat: assignable managers for accommodation bookings
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Admin\AccommodationBooking;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\User;
|
||||
use App\Form\Admin\Groups\AccommodationBookingCreateType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Service\AccommodationBookingService;
|
||||
@@ -31,6 +32,14 @@ class CreateController extends AbstractController
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
|
||||
// Whoever creates a booking in the backoffice looks after it until someone else is
|
||||
// assigned in the edit form. The route is behind ROLE_GROUPS_MANAGER, so the creator
|
||||
// is always eligible as Betreuer.
|
||||
$user = $this->getUser();
|
||||
if ($user instanceof User) {
|
||||
$booking->setManagedBy($user);
|
||||
}
|
||||
|
||||
$form = $this->createForm(AccommodationBookingCreateType::class, $booking, [
|
||||
'hx_post' => $request->getRequestUri(),
|
||||
]);
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Form\Admin\Groups\AccommodationBookingType;
|
||||
use App\Repository\Groups\AdditionalServiceRepository;
|
||||
use App\Repository\Groups\BoardServiceRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -28,6 +29,7 @@ class EditController extends AbstractController
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly BoardServiceRepository $boardServiceRepo,
|
||||
private readonly AdditionalServiceRepository $additionalServiceRepo,
|
||||
private readonly UserRepository $userRepo,
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
) {
|
||||
}
|
||||
@@ -69,12 +71,26 @@ class EditController extends AbstractController
|
||||
));
|
||||
}
|
||||
|
||||
// ROLE_ADMIN inherits ROLE_GROUPS_ADMIN, so this single check covers both.
|
||||
$assignableManagers = [];
|
||||
if ($this->isGranted('ROLE_GROUPS_ADMIN')) {
|
||||
$assignableManagers = $this->userRepo->findGroupsStaff();
|
||||
|
||||
// A user assigned earlier may have lost the role since — keep them in the choices
|
||||
// so the field can render the current value instead of failing to transform it.
|
||||
$currentManager = $booking->getManagedBy();
|
||||
if (null !== $currentManager && !in_array($currentManager, $assignableManagers, true)) {
|
||||
$assignableManagers[] = $currentManager;
|
||||
}
|
||||
}
|
||||
|
||||
$form = $this->createForm(AccommodationBookingType::class, $booking, [
|
||||
'max_adolescent_age' => $accommodation?->getMaxAdolescentAge() ?? 0,
|
||||
'board_services' => $boardServices,
|
||||
'additional_services' => $additionalServices,
|
||||
'current_board_service' => $currentBoardService,
|
||||
'current_additional_services' => $currentAdditionalServices,
|
||||
'assignable_managers' => $assignableManagers,
|
||||
]);
|
||||
$previousStatus = $booking->getStatus();
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@ class IndexController extends AbstractController
|
||||
$qb = $this
|
||||
->bookingRepository
|
||||
->createQueryBuilder('booking')
|
||||
->select('booking', 'managed_by')
|
||||
->leftJoin('booking.accommodation', 'accommodation')
|
||||
->leftJoin('booking.managedBy', 'managed_by')
|
||||
->addSelect('accommodation')
|
||||
->where('booking.dateTo >= :today')
|
||||
->setParameter('today', $today)
|
||||
|
||||
Reference in New Issue
Block a user