diff --git a/assets/images/icons.svg b/assets/images/icons.svg index 77b452d..7d41ec2 100644 --- a/assets/images/icons.svg +++ b/assets/images/icons.svg @@ -14,6 +14,9 @@ + + + diff --git a/src/Controller/Admin/Log/IndexController.php b/src/Controller/Admin/Log/IndexController.php new file mode 100644 index 0000000..a7801e3 --- /dev/null +++ b/src/Controller/Admin/Log/IndexController.php @@ -0,0 +1,58 @@ +logRepository + ->createQueryBuilder('log') + ; + + $pagination = $this->paginator->paginate( + $qb, + $request->query->getInt('page', 1), + 10, + [ + 'defaultSortFieldName' => 'log.timestamp', + 'defaultSortDirection' => 'DESC', + ] + ); + + $entries = []; + foreach ($pagination as $entry) { + /** @var Log $entry */ + $extra = $entry->getExtra(); + $entries[] = [ + 'timestamp' => $entry->getTimestamp(), + 'message' => $entry->getMessage(), + 'user' => $extra['user'] ? $extra['user']['username'] ?? $extra['user']['email'] : '-', + 'context' => json_encode($entry->getContext(), JSON_UNESCAPED_UNICODE), + ]; + } + + return $this->render('admin/log/index.html.twig', [ + 'pagination' => $pagination, + 'entries' => $entries, + ]); + } +} \ No newline at end of file diff --git a/src/Entity/Log.php b/src/Entity/Log.php new file mode 100644 index 0000000..6da35bb --- /dev/null +++ b/src/Entity/Log.php @@ -0,0 +1,110 @@ +id; + } + + public function getMessage(): ?string + { + return $this->message; + } + + public function setMessage(string $message): static + { + $this->message = $message; + + return $this; + } + + public function getTimestamp(): ?\DateTimeImmutable + { + return $this->timestamp; + } + + public function setTimestamp(\DateTimeImmutable $timestamp): static + { + $this->timestamp = $timestamp; + + return $this; + } + + public function getLevel(): ?string + { + return $this->level; + } + + public function setLevel(string $level): static + { + $this->level = $level; + + return $this; + } + + public function getChannel(): ?string + { + return $this->channel; + } + + public function setChannel(string $channel): static + { + $this->channel = $channel; + + return $this; + } + + public function getContext(): array + { + return $this->context; + } + + public function setContext(array $context): static + { + $this->context = $context; + + return $this; + } + + public function getExtra(): array + { + return $this->extra; + } + + public function setExtra(array $extra): static + { + $this->extra = $extra; + + return $this; + } +} diff --git a/src/Menu/AdminMenuBuilder.php b/src/Menu/AdminMenuBuilder.php index eaef6b4..9de5f5c 100644 --- a/src/Menu/AdminMenuBuilder.php +++ b/src/Menu/AdminMenuBuilder.php @@ -101,6 +101,11 @@ class AdminMenuBuilder extends AbstractMenuBuilder ], ], ], + [ + 'route' => 'app_admin_log_index', + 'title' => 'Logs', + 'icon' => 'list', + ], ]; } diff --git a/src/Repository/LogRepository.php b/src/Repository/LogRepository.php new file mode 100644 index 0000000..01be999 --- /dev/null +++ b/src/Repository/LogRepository.php @@ -0,0 +1,23 @@ + + * + * @method Log|null find($id, $lockMode = null, $lockVersion = null) + * @method Log|null findOneBy(array $criteria, array $orderBy = null) + * @method Log[] findAll() + * @method Log[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class LogRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Log::class); + } +} diff --git a/templates/admin/log/index.html.twig b/templates/admin/log/index.html.twig new file mode 100644 index 0000000..a80a431 --- /dev/null +++ b/templates/admin/log/index.html.twig @@ -0,0 +1,54 @@ +{% extends 'admin/layout.html.twig' %} + +{% block title %}Logs{% endblock %} + +{% block content %} +

+ Logs +

+
+
+ + + + + + + + + + + {% for entry in entries %} + + + + + + + {% else %} + + + + {% endfor %} + +
+ {{ knp_pagination_sortable(pagination, 'Datum', 'log.timestamp') }} + + Benutzer + + Meldung +
+ {{ entry.timestamp|date('d.m.Y H:i') }} + + {{ entry.user }} + + {{ entry.message }} + + {{ entry.context }} +
+ Keine Daten... +
+ {{ knp_pagination_render(pagination) }} +
+
+{% endblock %} \ No newline at end of file