Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
74.07% covered (warning)
74.07%
20 / 27
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
LogJournalLinkGenerator
74.07% covered (warning)
74.07%
20 / 27
50.00% covered (danger)
50.00%
1 / 2
20.46
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLink
72.00% covered (warning)
72.00%
18 / 25
0.00% covered (danger)
0.00%
0 / 1
19.94
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\Reporting\Generator;
25
26use App\Domain\Reporting\Dictionary\LogJournalSubjectDictionary;
27use App\Domain\Reporting\Model\LogJournal;
28use App\Domain\User\Model\Service;
29use Doctrine\ORM\EntityManagerInterface;
30use Symfony\Component\Routing\RouterInterface;
31
32class LogJournalLinkGenerator
33{
34    public const DELETE_LABEL = 'Supprimé';
35
36    /**
37     * @var RouterInterface
38     */
39    private $router;
40
41    /**
42     * @var EntityManagerInterface
43     */
44    protected $entityManager;
45
46    public function __construct(RouterInterface $router, EntityManagerInterface $entityManager)
47    {
48        $this->router        = $router;
49        $this->entityManager = $entityManager;
50    }
51
52    public function getLink(LogJournal $log)
53    {
54        if ($log->isDeleted()) {
55            return self::DELETE_LABEL;
56        }
57
58        $id = $log->getSubjectId();
59
60        switch ($log->getSubjectType()) {
61            case LogJournalSubjectDictionary::USER_USER:
62            case LogJournalSubjectDictionary::USER_EMAIL:
63            case LogJournalSubjectDictionary::USER_PASSWORD:
64            case LogJournalSubjectDictionary::USER_FIRSTNAME:
65            case LogJournalSubjectDictionary::USER_LASTNAME:
66                return $this->router->generate('user_user_edit', ['id' => $id]);
67            case LogJournalSubjectDictionary::REGISTRY_CONFORMITE_TRAITEMENT:
68            case LogJournalSubjectDictionary::REGISTRY_PROOF:
69            case LogJournalSubjectDictionary::MATURITY_SURVEY:
70                return $this->router->generate($log->getSubjectType() . '_edit', ['id' => $id]);
71            case LogJournalSubjectDictionary::REGISTRY_CONFORMITE_ORGANISATION_EVALUATION:
72                return $this->router->generate('registry_conformite_organisation_edit', ['id' => $id]);
73            case LogJournalSubjectDictionary::USER_SERVICE:
74                $service = $this
75                ->entityManager
76                ->getRepository(Service::class)
77                ->findOneBy(['id' => $id]);
78                if (null === $service) {
79                    return null;
80                }
81
82                return $this->router->generate('user_collectivity_show', ['id' => $service->getCollectivity()->getId()]);
83            default:
84                return $log->getSubjectType() ? $this->router->generate($log->getSubjectType() . '_show', ['id' => $id]) : '';
85        }
86    }
87}