feat: add a booking event history for admins
This commit is contained in:
1 parent
d68b6b156c
commit
0ab39d810b
18 files changed
+1578
-6
No files matched your search
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin\BookingEvent;
|
||||
|
||||
use App\Form\Admin\BookingEventFilter;
|
||||
use App\Form\Admin\BookingEventFilterType;
|
||||
use App\Repository\BookingEventRepository;
|
||||
use App\Security\Role;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/**
|
||||
* The event history: who booked, moved or freed what, and for whom.
|
||||
*
|
||||
* Administrators only, under /admin, although supervisors can free bookings themselves: the
|
||||
* history names who did what to whom across the whole staff, which is more than a supervisor
|
||||
* needs to do their part.
|
||||
*
|
||||
* Read-only. The rows are written by BookingEventRecorder and removed after a year by
|
||||
* app:booking-events:prune.
|
||||
*/
|
||||
#[IsGranted(Role::ADMIN)]
|
||||
final class IndexController extends AbstractController
|
||||
{
|
||||
private const PER_PAGE = 50;
|
||||
|
||||
/**
|
||||
* The columns a header may sort by. Spelled out because the field name comes from the query
|
||||
* string and the paginator would otherwise accept any path into the entity.
|
||||
*/
|
||||
private const SORTABLE = [
|
||||
'e.occurredAt',
|
||||
'e.type',
|
||||
'e.resourceLabel',
|
||||
'e.date',
|
||||
'e.holderName',
|
||||
'e.actorName',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly BookingEventRepository $events,
|
||||
private readonly PaginatorInterface $paginator,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/history', name: 'app_admin_booking_event', methods: ['GET'])]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$filter = new BookingEventFilter();
|
||||
$form = $this->createForm(BookingEventFilterType::class, $filter);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$this->events->createFilteredQueryBuilder($filter),
|
||||
$request->query->getInt('page', 1),
|
||||
self::PER_PAGE,
|
||||
[
|
||||
'defaultSortFieldName' => 'e.occurredAt',
|
||||
'defaultSortDirection' => 'desc',
|
||||
'sortFieldAllowList' => self::SORTABLE,
|
||||
],
|
||||
);
|
||||
|
||||
return $this->render('admin/booking_events.html.twig', [
|
||||
'form' => $form,
|
||||
'filter' => $filter,
|
||||
'pagination' => $pagination,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user