X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FNotificationsController.php;fp=src%2FWallabag%2FCoreBundle%2FController%2FNotificationsController.php;h=17e576cdaa12a2f22b0572bd7ef51bdf16e7abf1;hb=378aaefbbf60698c7b8faafc20f6b8cb22357e31;hp=0000000000000000000000000000000000000000;hpb=b5d7eb148c4cd62ff187b08765f0c13c7d330fcf;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/NotificationsController.php b/src/Wallabag/CoreBundle/Controller/NotificationsController.php new file mode 100644 index 00000000..17e576cd --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/NotificationsController.php @@ -0,0 +1,96 @@ +getDoctrine()->getRepository('WallabagCoreBundle:Notification')->getBuilderForNotificationsByUser($this->getUser()->getId()); + $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); + + $notifications = new Pagerfanta($pagerAdapter); + $notifications->setMaxPerPage($this->getParameter('wallabag_core.notifications_nb')); + + try { + $notifications->setCurrentPage($page); + } catch (OutOfRangeCurrentPageException $e) { + if ($page > 1) { + return $this->redirect($this->generateUrl('notifications-all', ['page' => $notifications->getNbPages()]), 302); + } + } + + return $this->render('WallabagCoreBundle:Notification:notifications.html.twig', [ + 'notifications' => $notifications, + 'currentPage' => $page, + ]); + } + + /** + * @Route("/notifications/readall", name="notification-archive-all") + * + * @param Request $request + * + * @return Response + */ + public function markAllNotificationsAsReadAction(Request $request) + { + $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->markAllAsReadForUser($this->getUser()->getId()); + + return $this->redirectToRoute('notifications-all'); + } + + /** + * @Route("/notifications/read/{notification}", name="notification-archive") + * + * @param Notification $notification + * + * @return Response + */ + public function markNotificationsAsReadAction(Notification $notification) + { + $em = $this->getDoctrine()->getManager(); + + $notification->setRead(true); + + $em->persist($notification); + $em->flush(); + + return $this->redirectToRoute('notifications-all'); + } + + /** + * @Route("/notifications/read/{notification}/redirect", name="notification-archive-redirect", requirements={"notification" = "\d+"}) + * + * @param Request $request + * @param Notification $notification + */ + public function markNotificationAsReadAndRedirectAction(Request $request, Notification $notification) + { + $em = $this->getDoctrine()->getManager(); + + $notification->setRead(true); + + $em->persist($notification); + $em->flush(); + + $redirection = $request->get('redirection'); + $this->redirect($redirection); + } +}