aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/NotificationsController.php
blob: 0717ff475fca34c4f1bd9351e7e872c9eda496db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace Wallabag\CoreBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Wallabag\CoreBundle\Entity\Notification;

class NotificationsController extends Controller
{
    /**
     * @param Request $request
     *
     * @Route("/notifications", name="notifications-all")
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function getAllNotificationsAction(Request $request)
    {
        $notifications = $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->findByUser($this->getUser());

        return $this->render('WallabagCoreBundle:Notification:notifications.html.twig', ['notifications' => $notifications]);
    }

    /**
     * @Route("/notifications/readall", name="notification-archive-all")
     *
     * @param Request $request
     * @return Response
     */
    public function markAllNotificationsAsReadAction(Request $request)
    {
        $this->getDoctrine()->getRepository('WallabagCoreBundle:Notification')->markAllAsReadForUser($this->getUser()->getId());

        return $this->redirectToRoute('notifications-all');
    }

    /**
     * @Route("/notifications/read/{notification}", name="notification-archive")
     *
     * @param Notification $notification
     * @return Response
     */
    public function markNotificationsAsReadAction(Notification $notification)
    {
        $em = $this->getDoctrine()->getManager();

        $notification->setRead(true);

        $em->persist($notification);
        $em->flush();

        return $this->redirectToRoute('notifications-all');
    }
}