Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
NotificationUserController
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 6
240
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getDomain
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getModel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getModelClass
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFormType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 unsubscribe
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
110
1<?php
2
3/**
4 * This file is part of the MADIS - RGPD Management application.
5 *
6 * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22declare(strict_types=1);
23
24namespace App\Domain\Notification\Controller;
25
26use App\Application\Controller\CRUDController;
27use App\Application\Symfony\Security\UserProvider;
28use App\Domain\Notification\Model;
29use App\Infrastructure\ORM\Notification\Repository\NotificationUser;
30use Doctrine\ORM\EntityManagerInterface;
31use Knp\Snappy\Pdf;
32use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
33use Symfony\Contracts\Translation\TranslatorInterface;
34
35class NotificationUserController extends CRUDController
36{
37    public function __construct(
38        EntityManagerInterface $entityManager,
39        TranslatorInterface $translator,
40        NotificationUser $repository,
41        AuthorizationCheckerInterface $authorizationChecker,
42        UserProvider $userProvider,
43        Pdf $pdf,
44    ) {
45        parent::__construct($entityManager, $translator, $repository, $pdf, $userProvider, $authorizationChecker);
46        $this->repository = $repository;
47    }
48
49    protected function getDomain(): string
50    {
51        return 'notification';
52    }
53
54    protected function getModel(): string
55    {
56        return 'notification_user';
57    }
58
59    protected function getModelClass(): string
60    {
61        return Model\NotificationUser::class;
62    }
63
64    protected function getFormType(): string
65    {
66        return '';
67    }
68
69    public function unsubscribe($id, $notif_id)
70    {
71        $notifUser = $this->repository->findOneById($id);
72
73        if ($notifUser && $notifUser->getNotification() && $notifUser->getNotification()->getId() === $notif_id) {
74            $notifUser->setActive(false);
75            $this->entityManager->flush();
76
77            $user = $notifUser->getUser();
78            // on desactive les notifs pour un utilisateur
79            if ($user) {
80                $notifsForUser = $this->entityManager->getRepository(Model\NotificationUser::class)->findBy(['user_id' => $user->getId()]);
81                if ($notifsForUser) {
82                    foreach ($notifsForUser as $notifForUser) {
83                        $notifForUser->setActive(false);
84                        $this->entityManager->flush();
85                    }
86                }
87            }
88
89            // on desactive les notifs si une adresse mail à plusieurs notifs
90            $mail = $notifUser->getMail();
91            if ($mail) {
92                $notifsForMail = $this->entityManager->getRepository(Model\NotificationUser::class)->findBy(['mail' => $mail]);
93                if ($notifsForMail) {
94                    foreach ($notifsForMail as $notifForMail) {
95                        $notifForMail->setActive(false);
96                        $this->entityManager->flush();
97                    }
98                }
99            }
100        }
101
102        return $this->redirectToRoute('login');
103    }
104}