diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-06-15 09:43:48 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-06-23 09:42:20 +0200 |
commit | e0f9010ec2a558f6cf7d16fb96a2c4cdb34e3f37 (patch) | |
tree | 904f42fa442188bf456b9773295fb9582634ba6c /src/Wallabag/CoreBundle/Controller/NotificationsController.php | |
parent | 29714661b1df78871ceaf0e079f11041a8641d4b (diff) | |
download | wallabag-e0f9010ec2a558f6cf7d16fb96a2c4cdb34e3f37.tar.gz wallabag-e0f9010ec2a558f6cf7d16fb96a2c4cdb34e3f37.tar.zst wallabag-e0f9010ec2a558f6cf7d16fb96a2c4cdb34e3f37.zip |
Notifications
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/NotificationsController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/NotificationsController.php | 96 |
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 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
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; | ||
13 | |||
14 | class 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 | } | ||