Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 82 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
MesurementGenerator | |
0.00% |
0 / 82 |
|
0.00% |
0 / 12 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
initializeExtract | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
12 | |||
collectivityHeaders | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
initializeCollectivity | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
mesurementGeneralInformationsHeaders | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
initializeMesurementGeneralInformations | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
mesurementApplicationHeaders | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
initializeMesurementApplication | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
mesurementProofHeaders | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
initializeProof | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
mesurementHistoricHeaders | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
initializeMesurementHistoric | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
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 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace App\Domain\Reporting\Generator\Csv; |
25 | |
26 | use App\Domain\Registry\Dictionary\MesurementPriorityDictionary; |
27 | use App\Domain\Registry\Dictionary\MesurementStatusDictionary; |
28 | use App\Domain\User\Repository\Collectivity; |
29 | use App\Infrastructure\ORM\Registry\Repository\Mesurement; |
30 | use Symfony\Component\Security\Core\Security; |
31 | use Symfony\Contracts\Translation\TranslatorInterface; |
32 | |
33 | class MesurementGenerator extends AbstractGenerator |
34 | { |
35 | /** |
36 | * @var TranslatorInterface |
37 | */ |
38 | private $translator; |
39 | |
40 | /** |
41 | * @var Collectivity |
42 | */ |
43 | private $collectivityRepository; |
44 | |
45 | /** |
46 | * @var Mesurement |
47 | */ |
48 | private $mesurementRepository; |
49 | |
50 | /** |
51 | * @var Security |
52 | */ |
53 | private $security; |
54 | |
55 | /** |
56 | * @var string |
57 | */ |
58 | private $yes; |
59 | |
60 | /** |
61 | * @var string |
62 | */ |
63 | private $no; |
64 | |
65 | public function __construct( |
66 | TranslatorInterface $translatorInterface, |
67 | Collectivity $collectivityRepository, |
68 | Mesurement $mesurementRepository, |
69 | Security $security, |
70 | ) { |
71 | $this->translator = $translatorInterface; |
72 | $this->collectivityRepository = $collectivityRepository; |
73 | $this->mesurementRepository = $mesurementRepository; |
74 | $this->security = $security; |
75 | } |
76 | |
77 | public function initializeExtract(): array |
78 | { |
79 | $this->yes = $this->translator->trans('global.label.yes'); |
80 | $this->no = $this->translator->trans('global.label.no'); |
81 | |
82 | $headers = array_merge( |
83 | ['Nom'], |
84 | $this->collectivityHeaders(), |
85 | $this->mesurementGeneralInformationsHeaders(), |
86 | $this->mesurementApplicationHeaders(), |
87 | $this->mesurementProofHeaders(), |
88 | $this->mesurementHistoricHeaders(), |
89 | ); |
90 | $data = [$headers]; |
91 | |
92 | $user = null; |
93 | if (!$this->security->isGranted('ROLE_ADMIN')) { |
94 | $user = $this->security->getUser(); |
95 | } |
96 | |
97 | /** @var \App\Domain\Registry\Model\Mesurement $mesurement */ |
98 | foreach ($this->mesurementRepository->findAllByActiveCollectivity(true, $user) as $mesurement) { |
99 | $extract = array_merge( |
100 | [$mesurement->getName()], |
101 | $this->initializeCollectivity($mesurement->getCollectivity()), |
102 | $this->initializeMesurementGeneralInformations($mesurement), |
103 | $this->initializeMesurementApplication($mesurement), |
104 | $this->initializeProof($mesurement), |
105 | $this->initializeMesurementHistoric($mesurement), |
106 | ); |
107 | array_push($data, $extract); |
108 | } |
109 | |
110 | return $data; |
111 | } |
112 | |
113 | private function collectivityHeaders(): array |
114 | { |
115 | $collectivityTrans = $this->translator->trans('global.label.organization'); |
116 | |
117 | return [ |
118 | $collectivityTrans . ' - ' . $this->translator->trans('user.organization.label.name'), |
119 | $collectivityTrans . ' - ' . $this->translator->trans('user.organization.label.siren'), |
120 | $collectivityTrans . ' - ' . $this->translator->trans('global.label.address.insee'), |
121 | ]; |
122 | } |
123 | |
124 | private function initializeCollectivity(\App\Domain\User\Model\Collectivity $collectivity) |
125 | { |
126 | return [ |
127 | $collectivity->getName(), |
128 | $collectivity->getSiren(), |
129 | $collectivity->getAddress()->getInsee(), |
130 | ]; |
131 | } |
132 | |
133 | private function mesurementGeneralInformationsHeaders() |
134 | { |
135 | return [ |
136 | $this->translator->trans('registry.mesurement.label.description'), |
137 | $this->translator->trans('registry.mesurement.label.manager'), |
138 | $this->translator->trans('registry.mesurement.label.priority'), |
139 | $this->translator->trans('registry.mesurement.label.cost'), |
140 | $this->translator->trans('registry.mesurement.label.charge'), |
141 | ]; |
142 | } |
143 | |
144 | private function initializeMesurementGeneralInformations(\App\Domain\Registry\Model\Mesurement $mesurement): array |
145 | { |
146 | return [ |
147 | $mesurement->getDescription(), |
148 | $mesurement->getManager(), |
149 | !\is_null($mesurement->getPriority()) ? MesurementPriorityDictionary::getPriorities()[$mesurement->getPriority()] : null, |
150 | $mesurement->getCost(), |
151 | $mesurement->getCharge(), |
152 | ]; |
153 | } |
154 | |
155 | private function mesurementApplicationHeaders() |
156 | { |
157 | $applicationTrans = $this->translator->trans('registry.mesurement.tab.application'); |
158 | |
159 | return [ |
160 | $applicationTrans . ' - ' . $this->translator->trans('registry.mesurement.label.status'), |
161 | $applicationTrans . ' - ' . $this->translator->trans('registry.mesurement.label.planification_date'), |
162 | $applicationTrans . ' - ' . $this->translator->trans('registry.mesurement.label.comment'), |
163 | ]; |
164 | } |
165 | |
166 | private function initializeMesurementApplication(\App\Domain\Registry\Model\Mesurement $mesurement): array |
167 | { |
168 | return [ |
169 | !\is_null($mesurement->getStatus()) ? MesurementStatusDictionary::getStatus()[$mesurement->getStatus()] : null, |
170 | $this->getDate($mesurement->getPlanificationDate(), GeneratorInterface::DATE_FORMAT), |
171 | $mesurement->getComment(), |
172 | ]; |
173 | } |
174 | |
175 | private function mesurementProofHeaders() |
176 | { |
177 | return [ |
178 | $this->translator->trans('global.label.linked_proof'), |
179 | ]; |
180 | } |
181 | |
182 | private function initializeProof(\App\Domain\Registry\Model\Mesurement $mesurement): array |
183 | { |
184 | return [ |
185 | implode(' - ', \iterable_to_array($mesurement->getProofs())), |
186 | ]; |
187 | } |
188 | |
189 | private function mesurementHistoricHeaders() |
190 | { |
191 | $historicTrans = $this->translator->trans('global.tab.history'); |
192 | |
193 | return [ |
194 | $historicTrans . ' - ' . $this->translator->trans('global.label.created_by'), |
195 | $historicTrans . ' - ' . $this->translator->trans('global.label.created_at'), |
196 | $historicTrans . ' - ' . $this->translator->trans('global.label.updated_at'), |
197 | ]; |
198 | } |
199 | |
200 | private function initializeMesurementHistoric(\App\Domain\Registry\Model\Mesurement $mesurement): array |
201 | { |
202 | return [ |
203 | strval($mesurement->getCreator()), |
204 | $this->getDate($mesurement->getCreatedAt()), |
205 | $this->getDate($mesurement->getUpdatedAt()), |
206 | ]; |
207 | } |
208 | } |