Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
22.22% |
6 / 27 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
LogJournalExtension | |
22.22% |
6 / 27 |
|
66.67% |
2 / 3 |
106.22 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getFunctions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getLogJournalLink | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
156 |
1 | <?php |
2 | |
3 | namespace App\Domain\Reporting\Twig\Extension; |
4 | |
5 | use App\Domain\Reporting\Dictionary\LogJournalSubjectDictionary; |
6 | use App\Domain\Reporting\Generator\LogJournalLinkGenerator; |
7 | use App\Domain\Reporting\Model\LogJournal; |
8 | use App\Domain\User\Model\User; |
9 | use Symfony\Component\Routing\RouterInterface; |
10 | use Symfony\Component\Security\Core\Security; |
11 | use Twig\Extension\AbstractExtension; |
12 | use Twig\TwigFunction; |
13 | |
14 | class LogJournalExtension extends AbstractExtension |
15 | { |
16 | /** |
17 | * @var LogJournalLinkGenerator |
18 | */ |
19 | private $logJournalLinkGenerator; |
20 | |
21 | /** |
22 | * @var Security |
23 | */ |
24 | private $security; |
25 | |
26 | /** |
27 | * @var RouterInterface |
28 | */ |
29 | private $router; |
30 | |
31 | public function __construct( |
32 | LogJournalLinkGenerator $logJournalLinkGenerator, |
33 | Security $security, |
34 | RouterInterface $router, |
35 | ) { |
36 | $this->logJournalLinkGenerator = $logJournalLinkGenerator; |
37 | $this->security = $security; |
38 | $this->router = $router; |
39 | } |
40 | |
41 | /** |
42 | * @return array|TwigFunction[] |
43 | */ |
44 | public function getFunctions() |
45 | { |
46 | return [ |
47 | new TwigFunction('getLogJournalLink', [$this, 'getLogJournalLink']), |
48 | ]; |
49 | } |
50 | |
51 | public function getLogJournalLink(LogJournal $logJournal): ?string |
52 | { |
53 | if (LogJournalSubjectDictionary::ADMIN_DUPLICATION === $logJournal->getSubjectType()) { |
54 | return null; |
55 | } |
56 | |
57 | /** @var User $user */ |
58 | $user = $this->security->getUser(); |
59 | $link = $this->logJournalLinkGenerator->getLink($logJournal); |
60 | switch ($logJournal->getSubjectType()) { |
61 | case LogJournalSubjectDictionary::USER_EMAIL: |
62 | case LogJournalSubjectDictionary::USER_LASTNAME: |
63 | case LogJournalSubjectDictionary::USER_FIRSTNAME: |
64 | case LogJournalSubjectDictionary::USER_USER: |
65 | case LogJournalSubjectDictionary::USER_PASSWORD: |
66 | case LogJournalSubjectDictionary::USER_COLLECTIVITY: |
67 | return null; |
68 | break; |
69 | case LogJournalSubjectDictionary::REGISTRY_CONFORMITE_TRAITEMENT: |
70 | if (!$user->getCollectivity()->isHasModuleConformiteTraitement()) { |
71 | return null; |
72 | } |
73 | break; |
74 | case LogJournalSubjectDictionary::REGISTRY_CONFORMITE_ORGANISATION_EVALUATION: |
75 | if (!$user->getCollectivity()->isHasModuleConformiteOrganisation()) { |
76 | return null; |
77 | } |
78 | break; |
79 | } |
80 | |
81 | return $link; |
82 | } |
83 | } |