aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/NotificationsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/NotificationsController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/NotificationsController.php96
1 files changed, 96 insertions, 0 deletions
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 @@
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Pagerfanta\Adapter\DoctrineORMAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Pagerfanta\Pagerfanta;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10use Symfony\Component\HttpFoundation\Request;
11use Symfony\Component\HttpFoundation\Response;
12use Wallabag\CoreBundle\Entity\Notification;
13
14class NotificationsController extends Controller
15{
16 /**
17 * @Route("/notifications/{page}", name="notifications-all", defaults={"page" = "1"})
18 *
19 * @param int $page
20 *
21 * @return Response
22 */
23 public function getAllNotificationsAction($page = 1)
24 {
25 $qb = $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->getBuilderForNotificationsByUser($this->getUser()->getId());
26 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
27
28 $notifications = new Pagerfanta($pagerAdapter);
29 $notifications->setMaxPerPage($this->getParameter('wallabag_core.notifications_nb'));
30
31 try {
32 $notifications->setCurrentPage($page);
33 } catch (OutOfRangeCurrentPageException $e) {
34 if ($page > 1) {
35 return $this->redirect($this->generateUrl('notifications-all', ['page' => $notifications->getNbPages()]), 302);
36 }
37 }
38
39 return $this->render('WallabagCoreBundle:Notification:notifications.html.twig', [
40 'notifications' => $notifications,
41 'currentPage' => $page,
42 ]);
43 }
44
45 /**
46 * @Route("/notifications/readall", name="notification-archive-all")
47 *
48 * @param Request $request
49 *
50 * @return Response
51 */
52 public function markAllNotificationsAsReadAction(Request $request)
53 {
54 $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->markAllAsReadForUser($this->getUser()->getId());
55
56 return $this->redirectToRoute('notifications-all');
57 }
58
59 /**
60 * @Route("/notifications/read/{notification}", name="notification-archive")
61 *
62 * @param Notification $notification
63 *
64 * @return Response
65 */
66 public function markNotificationsAsReadAction(Notification $notification)
67 {
68 $em = $this->getDoctrine()->getManager();
69
70 $notification->setRead(true);
71
72 $em->persist($notification);
73 $em->flush();
74
75 return $this->redirectToRoute('notifications-all');
76 }
77
78 /**
79 * @Route("/notifications/read/{notification}/redirect", name="notification-archive-redirect", requirements={"notification" = "\d+"})
80 *
81 * @param Request $request
82 * @param Notification $notification
83 */
84 public function markNotificationAsReadAndRedirectAction(Request $request, Notification $notification)
85 {
86 $em = $this->getDoctrine()->getManager();
87
88 $notification->setRead(true);
89
90 $em->persist($notification);
91 $em->flush();
92
93 $redirection = $request->get('redirection');
94 $this->redirect($redirection);
95 }
96}