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,
46 * @Route("/notifications/readall", name="notification-archive-all")
48 * @param Request $request
52 public function markAllNotificationsAsReadAction(Request
$request)
54 $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->markAllAsReadForUser($this->getUser()->getId());
56 return $this->redirectToRoute('notifications-all');
60 * @Route("/notifications/read/{notification}", name="notification-archive")
62 * @param Notification $notification
66 public function markNotificationsAsReadAction(Notification
$notification)
68 $em = $this->getDoctrine()->getManager();
70 $notification->setRead(true);
72 $em->persist($notification);
75 return $this->redirectToRoute('notifications-all');
79 * @Route("/notifications/read/{notification}/redirect", name="notification-archive-redirect", requirements={"notification" = "\d+"})
81 * @param Request $request
82 * @param Notification $notification
84 public function markNotificationAsReadAndRedirectAction(Request
$request, Notification
$notification)
86 $em = $this->getDoctrine()->getManager();
88 $notification->setRead(true);
90 $em->persist($notification);
93 $redirection = $request->get('redirection');
94 $this->redirect($redirection);