Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
18.18% covered (danger)
18.18%
6 / 33
25.00% covered (danger)
25.00%
1 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserGenerator
18.18% covered (danger)
18.18%
6 / 33
25.00% covered (danger)
25.00%
1 / 4
43.05
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 addSyntheticView
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addDetailedView
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 Userlist
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
30
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\Word;
25
26use App\Application\Symfony\Security\UserProvider;
27use App\Domain\User\Model\User;
28use Doctrine\ORM\EntityManagerInterface;
29use PhpOffice\PhpWord\Element\Section;
30use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
31use Symfony\Contracts\Translation\TranslatorInterface;
32
33class UserGenerator extends AbstractGenerator implements ImpressionGeneratorInterface
34{
35    protected TranslatorInterface $translator;
36    private $entityManager;
37
38    public function __construct(
39        EntityManagerInterface $entityManager,
40        UserProvider $userProvider,
41        ParameterBagInterface $parameterBag,
42        TranslatorInterface $translator,
43    ) {
44        parent::__construct(
45            $userProvider,
46            $parameterBag,
47        );
48
49        $this->translator    = $translator;
50        $this->entityManager = $entityManager;
51    }
52
53    public function addSyntheticView(Section $section, array $data, bool $forOverviewReport = false): void
54    {
55    }
56
57    public function addDetailedView(Section $section, array $data): void
58    {
59    }
60
61    public function Userlist(Section $section)
62    {
63        if ($this->collectivity) {
64            $collectivity = $this->collectivity;
65        } else {
66            $collectivity = $this->userProvider->getAuthenticatedUser()->getCollectivity();
67        }
68
69        $users = $this->entityManager->getRepository(User::class)->findBy(['collectivity' => $collectivity]);
70
71        $section->addTitle('Liste des utilisateurs', 2);
72        $userAnnexListTable = $section->addTable($this->tableStyle);
73        $userAnnexListTable->addRow(null, ['tblHeader' => true, 'cantsplit' => true]);
74        $cell = $userAnnexListTable->addCell(1500, $this->cellHeadStyle);
75        $cell->addText('Prénom', $this->textHeadStyle);
76        $cell = $userAnnexListTable->addCell(1500, $this->cellHeadStyle);
77        $cell->addText('Nom', $this->textHeadStyle);
78        $cell = $userAnnexListTable->addCell(3000, $this->cellHeadStyle);
79        $cell->addText('Email', $this->textHeadStyle);
80        $cell = $userAnnexListTable->addCell(1000, $this->cellHeadStyle);
81        $cell->addText('Actif', $this->textHeadStyle);
82
83        foreach ($users as $item) {
84            $userAnnexListTable->addRow(400, ['exactHeight' => true, 'cantsplit' => true]);
85            $cell = $userAnnexListTable->addCell(1500);
86            $cell->addText($item->getFirstName());
87            $cell = $userAnnexListTable->addCell(1500);
88            $cell->addText($item->getLastName());
89            $cell = $userAnnexListTable->addCell(3000);
90            $cell->addText($item->getEmail());
91            $cell = $userAnnexListTable->addCell(1000, ['bgColor' => $item->IsEnabled() ? 'bce292' : 'ffa7a7']);
92            $cell->addText($item->IsEnabled() ? 'Actif' : 'Inactif', ['bold' => true]);
93        }
94    }
95}