Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 229 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ContractorGenerator | |
0.00% |
0 / 229 |
|
0.00% |
0 / 3 |
1640 | |
0.00% |
0 / 1 |
addGlobalOverview | |
0.00% |
0 / 70 |
|
0.00% |
0 / 1 |
552 | |||
addSyntheticView | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
42 | |||
addDetailedView | |
0.00% |
0 / 137 |
|
0.00% |
0 / 1 |
132 |
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\Word; |
25 | |
26 | use App\Domain\Registry\Model\Contractor; |
27 | use App\Domain\User\Dictionary\ContactCivilityDictionary; |
28 | use PhpOffice\PhpWord\Element\Section; |
29 | |
30 | class ContractorGenerator extends AbstractGenerator implements ImpressionGeneratorInterface |
31 | { |
32 | /** |
33 | * Global overview : data to display for contractors in overview report. |
34 | * |
35 | * @param Contractor[] $data |
36 | */ |
37 | public function addGlobalOverview(Section $section, array $data): void |
38 | { |
39 | if ($this->collectivity) { |
40 | $collectivity = $this->collectivity; |
41 | } else { |
42 | $collectivity = $this->userProvider->getAuthenticatedUser()->getCollectivity(); |
43 | } |
44 | |
45 | $overviews = [ |
46 | 'Nom', |
47 | 'Référent', |
48 | 'Clauses contractuelles vérifiées', |
49 | 'Adopte les éléments de sécurité nécessaires', |
50 | 'Tient à jour un registre des traitements', |
51 | 'Les données restent dans l\'Union européenne', |
52 | ]; |
53 | $nbContractors = \count($data); |
54 | $nbVerifiedContractualClauses = 0; |
55 | $nbAdoptedSecurityFeatures = 0; |
56 | $nbMaintainsTreatmentRegister = 0; |
57 | $nbSendingDataOutsideEu = 0; |
58 | |
59 | foreach ($data as $contractor) { |
60 | // Verified contractual clauses |
61 | if ($contractor->isContractualClausesVerified()) { |
62 | ++$nbVerifiedContractualClauses; |
63 | } |
64 | // Adopted security features |
65 | if ($contractor->isAdoptedSecurityFeatures()) { |
66 | ++$nbAdoptedSecurityFeatures; |
67 | } |
68 | // Maintains treatment register |
69 | if ($contractor->isMaintainsTreatmentRegister()) { |
70 | ++$nbMaintainsTreatmentRegister; |
71 | } |
72 | // Sending data outside EU |
73 | if (!$contractor->isSendingDataOutsideEu()) { |
74 | ++$nbSendingDataOutsideEu; |
75 | } |
76 | } |
77 | |
78 | $section->addTitle('Registre des sous-traitants', 2); |
79 | |
80 | if (empty($data)) { |
81 | $section->addText('Il n’y a aucun sous-traitant identifié.'); |
82 | |
83 | return; |
84 | } |
85 | |
86 | $section->addText("Un recensement des sous-traitants gérants des données à caractère personnel de {$collectivity} a été effectué."); |
87 | $section->addText('Il y a ' . (1 == $nbContractors ? ' un sous-traitant identifié.' : "{$nbContractors} sous-traitants identifiés.")); |
88 | $section->addListItem( |
89 | 0 == $nbVerifiedContractualClauses ? 'Aucune clause contractuelle n’a été vérifiée ;' : |
90 | (1 == $nbVerifiedContractualClauses ? '1 clause contractuelle a été vérifiée ;' : |
91 | "{$nbVerifiedContractualClauses} clauses contractuelles vérifiées ;") |
92 | ); |
93 | $section->addListItem( |
94 | 0 == $nbAdoptedSecurityFeatures ? 'Aucun sous-traitant n’a adopté les éléments de sécurité nécessaires ;' : |
95 | (1 == $nbAdoptedSecurityFeatures ? '1 sous-traitant a adopté les éléments de sécurité nécessaires ;' : |
96 | "{$nbAdoptedSecurityFeatures} sous-traitants ont adopté les éléments de sécurité nécessaires ;") |
97 | ); |
98 | $section->addListItem( |
99 | 0 == $nbMaintainsTreatmentRegister ? 'Aucun sous-traitant ne tient à jour un registre des traitements ;' : |
100 | (1 == $nbMaintainsTreatmentRegister ? '1 sous-traitant tient à jour un registre des traitements ;' : |
101 | "{$nbMaintainsTreatmentRegister} sous-traitants tiennent à jour un registre des traitements ;") |
102 | ); |
103 | $section->addListItem( |
104 | 0 == $nbSendingDataOutsideEu ? "Aucun sous-traitant n'envoie des données hors Union européenne." : |
105 | (1 == $nbSendingDataOutsideEu ? '1 sous-traitant envoie des données hors Union européenne.' : |
106 | "{$nbSendingDataOutsideEu} sous-traitants envoient des données hors Union européenne.") |
107 | ); |
108 | |
109 | $ContractorsListTable = $section->addTable($this->tableStyle); |
110 | $ContractorsListTable->addRow(null, ['tblHeader' => true, 'cantsplit' => true]); |
111 | foreach ($overviews as $overviewRow) { |
112 | $cell = $ContractorsListTable->addCell(1500, $this->cellHeadStyle); |
113 | $cell->addText($overviewRow, $this->textHeadStyle); |
114 | } |
115 | |
116 | // Make a loop to get all data. Make all data processing in one loop to avoid several loops |
117 | foreach ($data as $contractor) { |
118 | $ContractorsListTable->addRow(null, ['exactHeight' => true, 'cantsplit' => true]); |
119 | $cell = $ContractorsListTable->addCell(1500); |
120 | $cell->addText($contractor->getName()); |
121 | $cell = $ContractorsListTable->addCell(1500); |
122 | $cell->addText($contractor->getReferent() ?? $this->parameterBag->get('APP_DEFAULT_REFERENT')); |
123 | $cell = $ContractorsListTable->addCell(1500); |
124 | $cell->addText($contractor->isContractualClausesVerified() ? 'Oui' : 'Non'); |
125 | $cell = $ContractorsListTable->addCell(1500); |
126 | $cell->addText($contractor->isAdoptedSecurityFeatures() ? 'Oui' : 'Non'); |
127 | $cell = $ContractorsListTable->addCell(1500); |
128 | $cell->addText($contractor->isMaintainsTreatmentRegister() ? 'Oui' : 'Non'); |
129 | $cell = $ContractorsListTable->addCell(1500); |
130 | $cell->addText($contractor->isSendingDataOutsideEu() ? 'Oui' : 'Non'); |
131 | } |
132 | } |
133 | |
134 | public function addSyntheticView(Section $section, array $data): void |
135 | { |
136 | $section->addTitle('Liste des sous-traitants', 1); |
137 | |
138 | // Table data |
139 | // Add header |
140 | $tableData = [ |
141 | [ |
142 | 'Nom', |
143 | 'Référent', |
144 | 'Clauses contractuelles vérifiées', |
145 | 'Adopte les éléments de sécurité nécessaires', |
146 | 'Tient à jour un registre des traitements', |
147 | 'Les données restent dans l\'Union européenne', |
148 | ], |
149 | ]; |
150 | // Add content |
151 | foreach ($data as $contractor) { |
152 | $tableData[] = [ |
153 | $contractor->getName(), |
154 | $contractor->getReferent() ?? $this->parameterBag->get('APP_DEFAULT_REFERENT'), |
155 | $contractor->isContractualClausesVerified() ? 'Oui' : 'Non', |
156 | $contractor->isAdoptedSecurityFeatures() ? 'Oui' : 'Non', |
157 | $contractor->isMaintainsTreatmentRegister() ? 'Oui' : 'Non', |
158 | $contractor->isSendingDataOutsideEu() ? 'Oui' : 'Non', |
159 | ]; |
160 | } |
161 | |
162 | $this->addTable($section, $tableData, true, self::TABLE_ORIENTATION_VERTICAL); |
163 | $section->addPageBreak(); |
164 | } |
165 | |
166 | public function addDetailedView(Section $section, array $data): void |
167 | { |
168 | $section->addTitle('Détail des sous-traitants', 1); |
169 | |
170 | /** @var Contractor $contractor */ |
171 | foreach ($data as $key => $contractor) { |
172 | if (0 !== $key) { |
173 | $section->addPageBreak(); |
174 | } |
175 | $section->addTitle($contractor->getName(), 2); |
176 | |
177 | $generalInformationsData = [ |
178 | [ |
179 | 'Nom', |
180 | $contractor->getName(), |
181 | ], |
182 | ]; |
183 | |
184 | // Ajouter les services si le module est actif |
185 | if ($contractor->getCollectivity()->getIsServicesEnabled()) { |
186 | $generalInformationsData[] = [ |
187 | 'Service', |
188 | $contractor->getService(), |
189 | ]; |
190 | } |
191 | |
192 | $generalInformationsData = array_merge($generalInformationsData, [ |
193 | [ |
194 | 'Agent référent', |
195 | $contractor->getReferent() ?? $this->parameterBag->get('APP_DEFAULT_REFERENT'), |
196 | ], |
197 | [ |
198 | 'Clauses contractuelles vérifiées', |
199 | $contractor->isContractualClausesVerified() ? 'Oui' : 'Non', |
200 | ], |
201 | [ |
202 | 'Adopte les éléments de sécurité nécessaires', |
203 | $contractor->isAdoptedSecurityFeatures() ? 'Oui' : 'Non', |
204 | ], |
205 | [ |
206 | 'Tient à jour un registre des traitements', |
207 | $contractor->isMaintainsTreatmentRegister() ? 'Oui' : 'Non', |
208 | ], |
209 | [ |
210 | 'Les données restent dans l\'Union européenne', |
211 | $contractor->isSendingDataOutsideEu() ? 'Oui' : 'Non', |
212 | ], |
213 | [ |
214 | 'Autres informations', |
215 | $contractor->getOtherInformations(), |
216 | ], |
217 | ]); |
218 | |
219 | $addressData = [ |
220 | [ |
221 | 'Prénom', |
222 | $contractor->getLegalManager()->getFirstName(), |
223 | ], |
224 | [ |
225 | 'Nom', |
226 | $contractor->getLegalManager()->getLastName(), |
227 | ], |
228 | [ |
229 | 'Adresse', |
230 | $contractor->getAddress()->getLineOne(), |
231 | ], |
232 | [ |
233 | 'Complément d\'adresse', |
234 | $contractor->getAddress()->getLineTwo(), |
235 | ], |
236 | [ |
237 | 'Code postal', |
238 | $contractor->getAddress()->getZipCode(), |
239 | ], |
240 | [ |
241 | 'Ville', |
242 | $contractor->getAddress()->getCity(), |
243 | ], |
244 | [ |
245 | 'Pays', |
246 | $contractor->getAddress()->getCountry(), |
247 | ], |
248 | [ |
249 | 'Email', |
250 | $contractor->getAddress()->getMail(), |
251 | ], |
252 | [ |
253 | 'Téléphone', |
254 | $contractor->getAddress()->getPhoneNumber(), |
255 | ], |
256 | ]; |
257 | |
258 | $dpoData = [ |
259 | [ |
260 | 'Le sous-traitant a désigné un DPD', |
261 | $contractor->isHasDpo() ? 'Oui' : 'Non', |
262 | ], |
263 | ]; |
264 | |
265 | if ($contractor->isHasDpo()) { |
266 | $dpoData = array_merge($dpoData, [ |
267 | [ |
268 | 'Civilité', |
269 | !\is_null($contractor->getDpo()->getCivility()) ? ContactCivilityDictionary::getCivilities()[$contractor->getDpo()->getCivility()] : '', |
270 | ], |
271 | [ |
272 | 'Prénom', |
273 | $contractor->getDpo()->getFirstName(), |
274 | ], |
275 | [ |
276 | 'Nom', |
277 | $contractor->getDpo()->getLastName(), |
278 | ], |
279 | [ |
280 | 'Fonction', |
281 | $contractor->getDpo()->getJob(), |
282 | ], |
283 | [ |
284 | 'Email', |
285 | $contractor->getDpo()->getMail(), |
286 | ], |
287 | [ |
288 | 'Téléphone', |
289 | $contractor->getDpo()->getPhoneNumber(), |
290 | ], |
291 | ]); |
292 | } |
293 | |
294 | $historyData = [ |
295 | [ |
296 | 'Date de création', |
297 | $this->getDate($contractor->getCreatedAt()), |
298 | ], |
299 | [ |
300 | 'Date de modification', |
301 | $this->getDate($contractor->getUpdatedAt()), |
302 | ], |
303 | [ |
304 | 'Modifié par', |
305 | $contractor->getUpdatedBy(), |
306 | ], |
307 | ]; |
308 | |
309 | $section->addTitle('Informations générales', 3); |
310 | $this->addTable($section, $generalInformationsData, false, self::TABLE_ORIENTATION_VERTICAL); |
311 | |
312 | $section->addTitle('Coordonnées', 3); |
313 | $this->addTable($section, $addressData, false, self::TABLE_ORIENTATION_VERTICAL); |
314 | |
315 | $section->addTitle('Délégué à la protection des données', 3); |
316 | $this->addTable($section, $dpoData, false, self::TABLE_ORIENTATION_VERTICAL); |
317 | |
318 | $section->addTitle('Éléments associés', 3); |
319 | $this->addLinkedData($section, $contractor); |
320 | |
321 | $section->addTitle('Historique', 3); |
322 | $this->addTable($section, $historyData, false, self::TABLE_ORIENTATION_VERTICAL); |
323 | } |
324 | } |
325 | } |