From 780f3cb5dc3d6931d6f2403776c49cd5937936a9 Mon Sep 17 00:00:00 2001 From: YvanSv <yvan.savergne@gmail.com> Date: Wed, 3 Apr 2024 16:07:03 +0200 Subject: [PATCH] suppression des notifications --- src/Controller/NotificationsController.php | 13 +++++++++++++ templates/notifications/index.html.twig | 1 + 2 files changed, 14 insertions(+) diff --git a/src/Controller/NotificationsController.php b/src/Controller/NotificationsController.php index 5c25cf70..bc8e7a41 100644 --- a/src/Controller/NotificationsController.php +++ b/src/Controller/NotificationsController.php @@ -26,4 +26,17 @@ class NotificationsController extends AbstractController 'notifs' => $notifs ]); } + + #[Route('/notificationsSupprimer/{id}', name: 'app_notifications_supprimer')] + public function supprimer($id): Response + { + $entityManager = $this->doctrine->getManager(); + $notif = $entityManager->getRepository(Notification::class)->find($id); + if ($notif) + $entityManager->remove($notif); + $entityManager->flush(); + + $notifs = $entityManager->getRepository(Notification::class)->findBy(['user_id' => $this->getUser()]); + return $this->redirectToRoute('app_notifications'); + } } diff --git a/templates/notifications/index.html.twig b/templates/notifications/index.html.twig index 00328b7c..923156b1 100644 --- a/templates/notifications/index.html.twig +++ b/templates/notifications/index.html.twig @@ -21,6 +21,7 @@ <td>{{ notif.date|date('d/m/y') }}</td> <td>{{ notif.type }}</td> <td>{{ notif.description }}</td> + <td><a href="{{ path('app_notifications_supprimer', {'id': notif.id}) }}"><button>Supprimer</button></a> </tr> {% endfor %} {% else %} -- GitLab