Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 150 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MaturityGenerator | |
0.00% |
0 / 150 |
|
0.00% |
0 / 3 |
1122 | |
0.00% |
0 / 1 |
addContextView | |
0.00% |
0 / 53 |
|
0.00% |
0 / 1 |
90 | |||
addSyntheticView | |
0.00% |
0 / 64 |
|
0.00% |
0 / 1 |
210 | |||
addDetailedView | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
110 |
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\Maturity\Model\Answer; |
27 | use App\Domain\Maturity\Model\OptionalAnswer; |
28 | use App\Domain\Maturity\Model\Survey; |
29 | use App\Domain\Registry\Model\Mesurement; |
30 | use PhpOffice\PhpWord\Element\Section; |
31 | use PhpOffice\PhpWord\Shared\Converter; |
32 | |
33 | class MaturityGenerator extends AbstractGenerator implements ImpressionGeneratorInterface |
34 | { |
35 | public function addContextView(Section $section, array $data): void |
36 | { |
37 | if (isset($data['bilanReport']) && $data['bilanReport']) { |
38 | $section->addTitle('Évaluation de la mise en conformité', 2); |
39 | if (!isset($data['new'])) { |
40 | $section->addText('Aucun indice de maturité à l\'heure actuelle.'); |
41 | |
42 | return; |
43 | } |
44 | |
45 | $section->addTitle($data['new']->getReferentiel()->getName(), 3); |
46 | |
47 | if (null !== $data['new']->getReferentiel()->getDescription()) { |
48 | $section->addText($data['new']->getReferentiel()->getDescription()); |
49 | } |
50 | |
51 | $section->addText('Score de l\'indice de maturité : ' . round($data['new']->getScore() / 10, 1)); |
52 | |
53 | if (isset($data['old'])) { |
54 | $section->addText('Score de l\'indice de maturité précédent : ' . round($data['old']->getScore() / 10, 1)); |
55 | } |
56 | } else { |
57 | if (!isset($data['new'])) { |
58 | $section->addText('Aucun indice de maturité à l\'heure actuelle.'); |
59 | |
60 | return; |
61 | } |
62 | |
63 | $section->addTitle('Contexte', 1); |
64 | |
65 | $table = $section->addTable([ |
66 | 'borderColor' => '006699', |
67 | 'borderSize' => 6, |
68 | 'cellMargin' => 100, |
69 | ]); |
70 | |
71 | $cellStyle = ['bgColor' => '3c8dbc']; |
72 | $textStyle = ['bold' => true, 'color' => 'ffffff']; |
73 | $table->addRow(); |
74 | $cell = $table->addCell(3000, $cellStyle); |
75 | $cell->addText('Référentiel', $textStyle); |
76 | $cell = $table->addCell(7000); |
77 | $cell->addText($data['new']->getReferentiel()->getName()); |
78 | $table->addRow(); |
79 | $cell = $table->addCell(3000, $cellStyle); |
80 | $cell->addText('Description', $textStyle); |
81 | $cell = $table->addCell(7000); |
82 | $cell->addText($data['new']->getReferentiel()->getDescription()); |
83 | $table->addRow(); |
84 | $cell = $table->addCell(3000, $cellStyle); |
85 | $cell->addText('Date de l\'indice de maturité', $textStyle); |
86 | $cell = $table->addCell(7000); |
87 | $cell->addText($data['new']->getCreatedAt()->format('d/m/Y')); |
88 | $table->addRow(); |
89 | $cell = $table->addCell(3000, $cellStyle); |
90 | $cell->addText('Score de l\'indice de maturité', $textStyle); |
91 | $cell = $table->addCell(7000); |
92 | $cell->addText(round($data['new']->getScore() / 10, 1)); |
93 | |
94 | if (isset($data['old'])) { |
95 | $table->addRow(); |
96 | $cell = $table->addCell(3000, $cellStyle); |
97 | $cell->addText('Date de l\'indice de maturité précédent', $textStyle); |
98 | $cell = $table->addCell(7000); |
99 | $cell->addText(isset($data['old']) ? $data['old']->getCreatedAt()->format('d/m/Y') : 'Aucun'); |
100 | $table->addRow(); |
101 | $cell = $table->addCell(3000, $cellStyle); |
102 | $cell->addText('Score de l\'indice de maturité précédent', $textStyle); |
103 | $cell = $table->addCell(7000); |
104 | $cell->addText(round($data['old']->getScore() / 10, 1)); |
105 | } |
106 | } |
107 | } |
108 | |
109 | public function addSyntheticView(Section $section, array $data): void |
110 | { |
111 | if (!isset($data['new'])) { |
112 | return; |
113 | } |
114 | |
115 | $maturityList = []; |
116 | $domainsName = []; |
117 | if (isset($data['old'])) { |
118 | foreach ($data['old']->getMaturity() as $maturity) { |
119 | $maturityList[$maturity->getDomain()->getPosition()]['old'] = $maturity->getScore(); |
120 | if (!isset($domainsName[$maturity->getDomain()->getPosition()])) { |
121 | $domainsName[$maturity->getDomain()->getPosition()] = $maturity->getDomain()->getName(); |
122 | } |
123 | } |
124 | } |
125 | foreach ($data['new']->getMaturity() as $maturity) { |
126 | $maturityList[$maturity->getDomain()->getPosition()]['new'] = $maturity->getScore(); |
127 | if (!isset($domainsName[$maturity->getDomain()->getPosition()])) { |
128 | $domainsName[$maturity->getDomain()->getPosition()] = $maturity->getDomain()->getName(); |
129 | } |
130 | } |
131 | \ksort($maturityList); |
132 | \ksort($domainsName); |
133 | |
134 | $serie1 = []; |
135 | $serie2 = []; |
136 | |
137 | // Table header |
138 | $tableData = [ |
139 | [ |
140 | '', |
141 | ], |
142 | ]; |
143 | if (isset($data['old'])) { |
144 | $tableData[0][] = $this->getDate($data['old']->getCreatedAt(), 'd/m/Y'); |
145 | } |
146 | $tableData[0][] = $this->getDate($data['new']->getCreatedAt(), 'd/m/Y'); |
147 | // Table data + radar data |
148 | foreach ($maturityList as $position => $score) { |
149 | $row = []; |
150 | $row[] = $domainsName[$position]; |
151 | if (isset($score['old'])) { |
152 | $row[] = $score['old'] / 10; // Display comma with 1 digit precision |
153 | $serie2[] = $score['old'] / 10; |
154 | } |
155 | if (isset($score['new'])) { |
156 | $row[] = $score['new'] / 10; // Display comma with 1 digit precision |
157 | $serie1[] = $score['new'] / 10; |
158 | $tableData[] = $row; |
159 | } |
160 | } |
161 | // Display |
162 | if (!(isset($data['bilanReport']) && $data['bilanReport'])) { |
163 | $section->addTitle('Vue d\'ensemble', 1); |
164 | } |
165 | |
166 | $this->addTable($section, $tableData, true, self::TABLE_ORIENTATION_HORIZONTAL); |
167 | |
168 | $section->addTextBreak(2); |
169 | |
170 | $chart = $section->addChart( |
171 | 'radar', |
172 | $domainsName, |
173 | $serie1, |
174 | [ |
175 | 'height' => Converter::cmToEmu(11), |
176 | 'width' => Converter::cmToEmu(15), |
177 | 'showLegend' => true, |
178 | 'legendPosition' => 'tr', |
179 | 'showAxisLabels' => true, |
180 | 'categoryAxisTitle' => 'tt', |
181 | 'minX' => 0, |
182 | 'maxX' => 5, |
183 | 'minY' => 0, |
184 | 'maxY' => 5, |
185 | 'dataLabelOptions' => [ |
186 | 'showVal' => false, |
187 | 'showCatName' => false, |
188 | ], |
189 | ], |
190 | $this->getDate($data['new']->getCreatedAt(), 'd/m/Y') |
191 | ); |
192 | |
193 | if (!empty($serie2)) { |
194 | $chart->addSeries(\array_keys($maturityList), $serie2, $this->getDate($data['old']->getCreatedAt(), 'd/m/Y')); |
195 | } |
196 | |
197 | $section->addPageBreak(); |
198 | } |
199 | |
200 | public function addDetailedView(Section $section, array $data): void |
201 | { |
202 | $section->addTitle('Détail', 1); |
203 | |
204 | // Order data |
205 | $ordered = []; |
206 | $descriptions = []; |
207 | /** |
208 | * @var Survey $survey |
209 | */ |
210 | $survey = $data['new']; |
211 | foreach ($survey->getAnswerSurveys() as $answerSurvey) { |
212 | $answer = $answerSurvey->getAnswer(); |
213 | $ordered[$answer->getQuestion()->getDomain()->getName()][$answer->getQuestion()->getName()] = $answer; |
214 | $descriptions[$answer->getQuestion()->getDomain()->getName()] = $answer->getQuestion()->getDomain()->getDescription(); |
215 | } |
216 | foreach ($survey->getOptionalAnswers() as $optionalAnswer) { |
217 | $ordered[$optionalAnswer->getQuestion()->getDomain()->getName()][$optionalAnswer->getQuestion()->getName()] = $optionalAnswer; |
218 | $descriptions[$optionalAnswer->getQuestion()->getDomain()->getName()] = $optionalAnswer->getQuestion()->getDomain()->getDescription(); |
219 | } |
220 | |
221 | \ksort($ordered); |
222 | // Table Body |
223 | foreach ($ordered as $domainName => $questions) { |
224 | $section->addTitle($domainName, 3); |
225 | $section->addText($descriptions[$domainName]); |
226 | $parsedData = [['', 'Réponse', 'Préconisation', 'Actions de protection']]; |
227 | \ksort($questions); |
228 | foreach ($questions as $questionName => $answer) { |
229 | $table = []; |
230 | $table[] = $questionName; |
231 | /* |
232 | * @var string $newOld |
233 | * @var Answer|OptionalAnswer $answer |
234 | */ |
235 | $table[1] = is_a($answer, Answer::class) ? $answer->getName() : $answer->getQuestion()->getOptionReason(); |
236 | $table[2] = is_a($answer, Answer::class) ? $answer->getRecommendation() : ''; |
237 | $mesurements = ''; |
238 | if ($survey->getAnswerSurveys()) { |
239 | foreach ($survey->getAnswerSurveys() as $answerSurvey) { |
240 | if ($answerSurvey->getAnswer()->getId() === $answer->getId()) { |
241 | $mesurements = join(', ', $answerSurvey->getMesurements()->map(function (Mesurement $mesurement) { |
242 | return $mesurement->getName(); |
243 | })->toArray()); |
244 | } |
245 | } |
246 | } |
247 | $table[3] = $mesurements; |
248 | |
249 | \ksort($table); |
250 | $parsedData[] = $table; |
251 | } |
252 | |
253 | $this->addTable($section, $parsedData, true, self::TABLE_ORIENTATION_VERTICAL); |
254 | } |
255 | } |
256 | } |