]>
Commit | Line | Data |
---|---|---|
e0f9010e TC |
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 | ]); | |
f256145f | 43 | |
e0f9010e TC |
44 | } |
45 | ||
46 | /** | |
47 | * @Route("/notifications/readall", name="notification-archive-all") | |
48 | * | |
49 | * @param Request $request | |
50 | * | |
51 | * @return Response | |
52 | */ | |
53 | public function markAllNotificationsAsReadAction(Request $request) | |
54 | { | |
55 | $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->markAllAsReadForUser($this->getUser()->getId()); | |
56 | ||
57 | return $this->redirectToRoute('notifications-all'); | |
58 | } | |
59 | ||
60 | /** | |
61 | * @Route("/notifications/read/{notification}", name="notification-archive") | |
62 | * | |
63 | * @param Notification $notification | |
64 | * | |
65 | * @return Response | |
66 | */ | |
67 | public function markNotificationsAsReadAction(Notification $notification) | |
68 | { | |
69 | $em = $this->getDoctrine()->getManager(); | |
70 | ||
71 | $notification->setRead(true); | |
72 | ||
73 | $em->persist($notification); | |
74 | $em->flush(); | |
75 | ||
76 | return $this->redirectToRoute('notifications-all'); | |
77 | } | |
78 | ||
79 | /** | |
80 | * @Route("/notifications/read/{notification}/redirect", name="notification-archive-redirect", requirements={"notification" = "\d+"}) | |
81 | * | |
82 | * @param Request $request | |
83 | * @param Notification $notification | |
84 | */ | |
85 | public function markNotificationAsReadAndRedirectAction(Request $request, Notification $notification) | |
86 | { | |
87 | $em = $this->getDoctrine()->getManager(); | |
88 | ||
89 | $notification->setRead(true); | |
90 | ||
91 | $em->persist($notification); | |
92 | $em->flush(); | |
93 | ||
94 | $redirection = $request->get('redirection'); | |
95 | $this->redirect($redirection); | |
96 | } | |
97 | } |