77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?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,
|
|
]);
|
|
}
|
|
}
|