remork watchdogs filter and logic

This commit is contained in:
Xbird
2022-09-15 17:30:31 +02:00
parent 2c76f0fd89
commit 95462fafba
3 changed files with 44 additions and 36 deletions

View File

@@ -679,48 +679,45 @@ class AdminController extends AbstractController
}
#[Route('/watchdog', name: 'watchdog')]
#[Route('/watchdog/view/{type}/{id}/{action}', name: 'watchdog_view')]
#[Route('/watchdog/{type}', name: 'watchdog_type')]
#[Route('/watchdog/{type}/{action}', name: 'watchdog_type_action')]
#[Route('/watchdog/{type?*}/{id?*}/{action?*}', name: 'watchdog')]
public function watchdog(
PaginatorInterface $paginator,
Request $Request,
EntityManagerInterface $EntityManagerInterface,
string $type = null,
string $action = null,
int $id = null
string $id = null
): Response {
$qb = $EntityManagerInterface->createQueryBuilder();
$qbButtons = $EntityManagerInterface->createQueryBuilder();
$qbButtonsAction = $EntityManagerInterface->createQueryBuilder();
$qb->select('l')
->from('Gedmo\Loggable\Entity\LogEntry', 'l')
->orderBy('l.loggedAt', 'DESC');
$qbButtons->select('DISTINCT l.objectClass')
->from('Gedmo\Loggable\Entity\LogEntry', 'l')
->orderBy('l.loggedAt', 'DESC');
if (null != $type) {
$qb->where('l.objectClass = :type');
$qb->setParameter('type', 'App\Entity\\' . $type);
$qbButtonsAction = $EntityManagerInterface->createQueryBuilder();
$qbButtonsAction->select('DISTINCT l.action')
->from('Gedmo\Loggable\Entity\LogEntry', 'l')
->orderBy('l.loggedAt', 'DESC');
->orderBy('l.objectClass', 'ASC');
$qbButtonsAction->select('DISTINCT l.action')
->from('Gedmo\Loggable\Entity\LogEntry', 'l')
->orderBy('l.action', 'ASC');
if (null != $action) {
$qb->andWhere('l.action = :action');
$qb->setParameter('action', $action);
}
if (null != $type && '*' != $type) {
$qb->where('l.objectClass = :type');
$qb->setParameter('type', 'App\Entity\\' . $type);
}
if (null != $id) {
if (null != $action && '*' != $action) {
$qb->andWhere('l.action = :action');
$qb->setParameter('action', $action);
}
if (null != $id && '*' != $id) {
$qb->andWhere('l.objectId = :id');
$qb->setParameter('id', $id);
}
@@ -732,11 +729,13 @@ class AdminController extends AbstractController
return $this->render('admin/watchdog.html.twig', [
'controller_name' => 'AdminController',
'pagination' => $pagination,
'buttonsType' => $qbButtons->getQuery()->getResult(),
'type' => $type,
'buttonsAction' => (($type != null) ? $qbButtonsAction->getQuery()->getResult() : null),
'action' => $action,
'id' => $id,
'buttonsType' => $qbButtons->getQuery()->getResult(),
'buttonsAction' => $qbButtonsAction->getQuery()->getResult(),
'pagination' => $pagination,
]);
}