3 namespace Wallabag\CoreBundle\Controller
;
5 use Pagerfanta\Adapter\DoctrineORMAdapter
;
6 use Pagerfanta\Exception\OutOfRangeCurrentPageException
;
7 use Pagerfanta\Pagerfanta
;
8 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
9 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
10 use Symfony\Component\HttpFoundation\Request
;
11 use Symfony\Component\HttpFoundation\Response
;
12 use Wallabag\CoreBundle\Entity\Notification
;
14 class NotificationsController
extends Controller
17 * @Route("/notifications/{page}", name="notifications-all", defaults={"page" = "1"})
23 public function getAllNotificationsAction($page = 1)
25 $qb = $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->getBuilderForNotificationsByUser($this->getUser()->getId());
26 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
28 $notifications = new Pagerfanta($pagerAdapter);
29 $notifications->setMaxPerPage($this->getParameter('wallabag_core.notifications_nb'));
32 $notifications->setCurrentPage($page);
33 } catch (OutOfRangeCurrentPageException
$e) {
35 return $this->redirect($this->generateUrl('notifications-all', ['page' => $notifications->getNbPages()]), 302);
39 return $this->render('WallabagCoreBundle:Notification:notifications.html.twig', [
40 'notifications' => $notifications,
41 'currentPage' => $page,
47 * @Route("/notifications/readall", name="notification-archive-all")
49 * @param Request $request
53 public function markAllNotificationsAsReadAction(Request
$request)
55 $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->markAllAsReadForUser($this->getUser()->getId());
57 return $this->redirectToRoute('notifications-all');
61 * @Route("/notifications/read/{notification}", name="notification-archive")
63 * @param Notification $notification
67 public function markNotificationsAsReadAction(Notification
$notification)
69 $em = $this->getDoctrine()->getManager();
71 $notification->setRead(true);
73 $em->persist($notification);
76 return $this->redirectToRoute('notifications-all');
80 * @Route("/notifications/read/{notification}/redirect", name="notification-archive-redirect", requirements={"notification" = "\d+"})
82 * @param Request $request
83 * @param Notification $notification
85 public function markNotificationAsReadAndRedirectAction(Request
$request, Notification
$notification)
87 $em = $this->getDoctrine()->getManager();
89 $notification->setRead(true);
91 $em->persist($notification);
94 $redirection = $request->get('redirection');
95 $this->redirect($redirection);