Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
9.80% |
30 / 306 |
|
8.70% |
2 / 23 |
CRAP | |
0.00% |
0 / 1 |
AnalyseImpactController | |
9.80% |
30 / 306 |
|
8.70% |
2 / 23 |
6717.32 | |
0.00% |
0 / 1 |
__construct | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
3.01 | |||
getDomain | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getModel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getModelClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFormType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
listAction | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
listDataTables | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
30 | |||
getLabelAndKeysArray | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
12 | |||
generateActionCell | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
72 | |||
generateAvisLabel | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
30 | |||
formPrePersistData | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
createAnalyseAction | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
42 | |||
editAction | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
72 | |||
modelesDatatablesAction | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
evaluationAction | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getModeleResults | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
getCorrespondingLabelFromkeyForModeles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
getLabelAndKeysArrayForModeles | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
printAction | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
182 | |||
validationAction | |
86.96% |
20 / 23 |
|
0.00% |
0 / 1 |
11.27 | |||
apiDeleteFile | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
deleteConfirmationAction | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
deleteAction | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace App\Domain\AIPD\Controller; |
6 | |
7 | use App\Application\Controller\CRUDController; |
8 | use App\Application\Symfony\Security\UserProvider; |
9 | use App\Application\Traits\ServersideDatatablesTrait; |
10 | use App\Domain\AIPD\Dictionary\ReponseAvisDictionary; |
11 | use App\Domain\AIPD\Form\Flow\AnalyseImpactFlow; |
12 | use App\Domain\AIPD\Form\Type\AnalyseAvisType; |
13 | use App\Domain\AIPD\Form\Type\AnalyseImpactType; |
14 | use App\Domain\AIPD\Model\AnalyseAvis; |
15 | use App\Domain\AIPD\Model\AnalyseImpact; |
16 | use App\Domain\AIPD\Model\AnalyseScenarioMenace; |
17 | use App\Domain\AIPD\Model\CriterePrincipeFondamental; |
18 | use App\Domain\AIPD\Repository; |
19 | use App\Domain\Documentation\Model\Category; |
20 | use App\Domain\User\Dictionary\UserRoleDictionary; |
21 | use App\Domain\User\Model\Collectivity; |
22 | use App\Domain\User\Model\User; |
23 | use Doctrine\ORM\EntityManagerInterface; |
24 | use Doctrine\ORM\Tools\Pagination\Paginator; |
25 | use Doctrine\Persistence\ManagerRegistry; |
26 | use Gaufrette\Filesystem; |
27 | use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse; |
28 | use Knp\Snappy\Pdf; |
29 | use Ramsey\Uuid\Uuid; |
30 | use Symfony\Component\Form\Form; |
31 | use Symfony\Component\HttpFoundation\JsonResponse; |
32 | use Symfony\Component\HttpFoundation\Request; |
33 | use Symfony\Component\HttpFoundation\RequestStack; |
34 | use Symfony\Component\HttpFoundation\Response; |
35 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
36 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
37 | use Symfony\Component\Routing\RouterInterface; |
38 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
39 | use Symfony\Component\String\Slugger\AsciiSlugger; |
40 | use Symfony\Contracts\Translation\TranslatorInterface; |
41 | |
42 | /** |
43 | * @property Repository\AnalyseImpact $repository |
44 | */ |
45 | class AnalyseImpactController extends CRUDController |
46 | { |
47 | use ServersideDatatablesTrait; |
48 | |
49 | private RouterInterface $router; |
50 | private RequestStack $requestStack; |
51 | private $modeleRepository; |
52 | private AnalyseImpactFlow $analyseFlow; |
53 | private Filesystem $fichierFilesystem; |
54 | |
55 | public function __construct( |
56 | EntityManagerInterface $entityManager, |
57 | TranslatorInterface $translator, |
58 | Repository\AnalyseImpact $repository, |
59 | Pdf $pdf, |
60 | UserProvider $userProvider, |
61 | AuthorizationCheckerInterface $authorizationChecker, |
62 | RouterInterface $router, |
63 | RequestStack $requestStack, |
64 | Repository\ModeleAnalyse $modeleRepository, |
65 | AnalyseImpactFlow $analyseFlow, |
66 | Filesystem $fichierFilesystem, |
67 | ) { |
68 | parent::__construct($entityManager, $translator, $repository, $pdf, $userProvider, $authorizationChecker); |
69 | $this->router = $router; |
70 | $this->requestStack = $requestStack; |
71 | $this->modeleRepository = $modeleRepository; |
72 | $this->analyseFlow = $analyseFlow; |
73 | $this->fichierFilesystem = $fichierFilesystem; |
74 | // Deny access to single collectivity users if conformite traitement module is disabled |
75 | // Fixes https://gitlab.adullact.net/soluris/madis/-/issues/949 |
76 | $user = $userProvider->getAuthenticatedUser(); |
77 | if ($user && !$user->hasModuleConformiteTraitement()) { |
78 | throw new AccessDeniedHttpException('Ce module est désactivé sur votre structure'); |
79 | } |
80 | } |
81 | |
82 | protected function getDomain(): string |
83 | { |
84 | return 'aipd'; |
85 | } |
86 | |
87 | protected function getModel(): string |
88 | { |
89 | return 'analyse_impact'; |
90 | } |
91 | |
92 | protected function getModelClass(): string |
93 | { |
94 | return AnalyseImpact::class; |
95 | } |
96 | |
97 | protected function getFormType(): string |
98 | { |
99 | return AnalyseImpactType::class; |
100 | } |
101 | |
102 | public function listAction(): Response |
103 | { |
104 | $category = $this->entityManager->getRepository(Category::class)->findOneBy([ |
105 | 'name' => 'AIPD', |
106 | ]); |
107 | |
108 | return $this->render($this->getTemplatingBasePath('list'), [ |
109 | 'totalItem' => $this->repository->count(), |
110 | 'category' => $category, |
111 | 'route' => $this->router->generate('aipd_analyse_impact_datatables'), |
112 | ]); |
113 | } |
114 | |
115 | public function listDataTables(Request $request): JsonResponse |
116 | { |
117 | $request = $this->requestStack->getMasterRequest(); |
118 | $user = $this->userProvider->getAuthenticatedUser(); |
119 | $criteria = []; |
120 | |
121 | if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) { |
122 | $criteria['collectivity'] = $user->getCollectivity(); |
123 | } |
124 | |
125 | if (\in_array(UserRoleDictionary::ROLE_REFERENT, $user->getRoles())) { |
126 | $criteria['collectivity'] = $user->getCollectivitesReferees(); |
127 | } |
128 | |
129 | $analyses = $this->getResults($request, $criteria); |
130 | $response = $this->getBaseDataTablesResponse($request, $analyses); |
131 | |
132 | /** @var AnalyseImpact $analyse */ |
133 | foreach ($analyses as $analyse) { |
134 | $response['data'][] = [ |
135 | 'traitement' => '<a href="' . $this->router->generate('registry_treatment_show', ['id' => $analyse->getConformiteTraitement()->getTraitement()->getId()]) . '">' . $analyse->getConformiteTraitement()->getTraitement()->getName() . '</a>', |
136 | 'dateDeCreation' => $analyse->getCreatedAt()->format('d/m/Y'), |
137 | 'dateDeValidation' => null === $analyse->getDateValidation() ? '' : $analyse->getDateValidation()->format('d/m/Y'), |
138 | 'modele' => $analyse->getModeleAnalyse(), |
139 | 'collectivite' => $analyse->getConformiteTraitement()->getTraitement()->getCollectivity()->getShortName(), |
140 | 'service' => $analyse->getConformiteTraitement()->getTraitement()->getService() . '', |
141 | 'avisReferent' => $this->generateAvisLabel($analyse->getAvisReferent()), |
142 | 'avisDpd' => $this->generateAvisLabel($analyse->getAvisDpd()), |
143 | 'avisRepresentant' => $this->generateAvisLabel($analyse->getAvisRepresentant()), |
144 | 'avisResponsable' => $this->generateAvisLabel($analyse->getAvisResponsable()), |
145 | 'actions' => $this->generateActionCell($analyse), |
146 | ]; |
147 | } |
148 | |
149 | return new JsonResponse($response); |
150 | } |
151 | |
152 | protected function getLabelAndKeysArray(): array |
153 | { |
154 | if ($this->isGranted('ROLE_REFERENT')) { |
155 | return [ |
156 | 'traitement', |
157 | 'dateDeCreation', |
158 | 'dateDeValidation', |
159 | 'modele', |
160 | 'collectivite', |
161 | 'service', |
162 | 'avisReferent', |
163 | 'avisDpd', |
164 | 'avisRepresentant', |
165 | 'avisResponsable', |
166 | 'actions', |
167 | ]; |
168 | } elseif ($this->userProvider->getAuthenticatedUser()->hasServices()) { |
169 | return [ |
170 | 'traitement', |
171 | 'dateDeCreation', |
172 | 'dateDeValidation', |
173 | 'modele', |
174 | 'service', |
175 | 'avisReferent', |
176 | 'avisDpd', |
177 | 'avisRepresentant', |
178 | 'avisResponsable', |
179 | 'actions', |
180 | ]; |
181 | } |
182 | |
183 | return [ |
184 | 'traitement', |
185 | 'dateDeCreation', |
186 | 'dateDeValidation', |
187 | 'modele', |
188 | 'avisReferent', |
189 | 'avisDpd', |
190 | 'avisRepresentant', |
191 | 'avisResponsable', |
192 | 'actions', |
193 | ]; |
194 | } |
195 | |
196 | private function generateActionCell(AnalyseImpact $analyseImpact): string |
197 | { |
198 | $cell = '<a href="' . $this->router->generate('aipd_analyse_impact_print', ['id' => $analyseImpact->getId()]) . '"> |
199 | <i aria-hidden="true" class="fa fa-print"></i> ' . |
200 | $this->translator->trans('global.action.print') . ' |
201 | </a>'; |
202 | $treatment = $analyseImpact->getConformiteTraitement()->getTraitement(); |
203 | $user = $this->userProvider->getAuthenticatedUser(); |
204 | // if user has services check if the treatment is allowed to be interacted with |
205 | $interact = true; |
206 | if ($treatment->getCollectivity()->getIsServicesEnabled() && $user->hasServices() && !$treatment->isInUserServices($user)) { |
207 | $interact = false; |
208 | } |
209 | if ('ROLE_PREVIEW' !== $user->getRoles()[0] && $interact) { |
210 | if (!$analyseImpact->isValidated()) { |
211 | $cell .= '<a href="' . $this->router->generate('aipd_analyse_impact_edit', ['id' => $analyseImpact->getId()]) . '"> |
212 | <i aria-hidden="true" class="fa fa-pencil"></i> ' . |
213 | $this->translator->trans('global.action.edit') . ' |
214 | </a>'; |
215 | if ($analyseImpact->isReadyForValidation()) { |
216 | $cell .= '<a href="' . $this->router->generate('aipd_analyse_impact_validation', ['id' => $analyseImpact->getId()]) . '"> |
217 | <i aria-hidden="true" class="fa fa-check-square"></i> ' . |
218 | $this->translator->trans('global.action.validate') . ' |
219 | </a>'; |
220 | } |
221 | } |
222 | $cell .= ' <a href="' . $this->router->generate('aipd_analyse_impact_delete', ['id' => $analyseImpact->getId()]) . '"> |
223 | <i aria-hidden="true" class="fa fa-trash"></i> ' . |
224 | $this->translator->trans('global.action.delete') . ' |
225 | </a>'; |
226 | } |
227 | |
228 | return $cell; |
229 | } |
230 | |
231 | public function generateAvisLabel(AnalyseAvis $avis) |
232 | { |
233 | switch ($avis->getReponse()) { |
234 | case ReponseAvisDictionary::REPONSE_FAVORABLE: |
235 | $color = 'label-success'; |
236 | break; |
237 | case ReponseAvisDictionary::REPONSE_FAVORABLE_RESERVE: |
238 | $color = 'label-warning'; |
239 | break; |
240 | case ReponseAvisDictionary::REPONSE_DEFAVORABLE: |
241 | $color = 'label-danger'; |
242 | break; |
243 | default: |
244 | $color = 'label-default'; |
245 | } |
246 | |
247 | return '<span class="label ' . $color . '" style="min-width: 100%; display: inline-block;">' . ReponseAvisDictionary::getReponseAvis()[$avis->getReponse()] . '</span>'; |
248 | } |
249 | |
250 | /** |
251 | * {@inheritdoc} |
252 | * - Upload documentFile before object persistence in database. |
253 | * |
254 | * @throws \Exception |
255 | */ |
256 | public function formPrePersistData($object, $form = null) |
257 | { |
258 | if (!$object instanceof AnalyseImpact) { |
259 | throw new \RuntimeException('You must persist a ' . AnalyseImpact::class . ' object class with your form'); |
260 | } |
261 | |
262 | foreach ($object->getCriterePrincipeFondamentaux() as $criterePrincipeFondamental) { |
263 | $file = $criterePrincipeFondamental->getFichierFile(); |
264 | |
265 | if ($file) { |
266 | $filename = Uuid::uuid4()->toString() . '.' . $file->getClientOriginalExtension(); |
267 | $this->fichierFilesystem->write($filename, \fopen($file->getRealPath(), 'r')); |
268 | $criterePrincipeFondamental->setFichier($filename); |
269 | $criterePrincipeFondamental->setFichierFile(null); |
270 | } |
271 | } |
272 | } |
273 | |
274 | /** |
275 | * The creation action view |
276 | * Create a new data. |
277 | */ |
278 | public function createAnalyseAction(Request $request, string $id): Response |
279 | { |
280 | if (null === $object = $this->repository->findOneByIdWithoutInvisibleScenarios($id)) { |
281 | throw new NotFoundHttpException("No object found with ID '{$id}'"); |
282 | } |
283 | /** @var AnalyseImpact $object */ |
284 | $traitement = $object->getConformiteTraitement()->getTraitement(); |
285 | if ($traitement->getCollectivity() && !$traitement->getCollectivity()->isHasModuleConformiteTraitement()) { |
286 | throw new AccessDeniedHttpException('La structure de ce traitement a le module conformité des traitements désactivé'); |
287 | } |
288 | |
289 | $this->analyseFlow->bind($object); |
290 | $form = $this->analyseFlow->createForm(); |
291 | |
292 | if ($this->analyseFlow->isValid($form)) { |
293 | $this->formPrePersistData($object); |
294 | $this->analyseFlow->saveCurrentStepData($form); |
295 | |
296 | if ($this->analyseFlow->nextStep()) { |
297 | $form = $this->analyseFlow->createForm(); |
298 | // TODO Persist and flush here to allow draft ? |
299 | } else { |
300 | $this->entityManager->persist($object); |
301 | $this->entityManager->flush(); |
302 | |
303 | $this->analyseFlow->reset(); |
304 | |
305 | $this->addFlash('success', $this->getFlashbagMessage('success', 'create', $object)); |
306 | |
307 | return $this->redirectToRoute($this->getRouteName('evaluation'), [ |
308 | 'id' => $id, |
309 | ]); |
310 | } |
311 | } |
312 | |
313 | return $this->render($this->getTemplatingBasePath('create'), [ |
314 | 'flow' => $this->analyseFlow, |
315 | 'form' => $form->createView(), |
316 | ]); |
317 | } |
318 | |
319 | public function editAction(Request $request, string $id): Response |
320 | { |
321 | if (null === $object = $this->repository->findOneByIdWithoutInvisibleScenarios($id)) { |
322 | throw new NotFoundHttpException("No object found with ID '{$id}'"); |
323 | } |
324 | |
325 | $traitement = $object->getConformiteTraitement()->getTraitement(); |
326 | if ($traitement->getCollectivity() && !$traitement->getCollectivity()->isHasModuleConformiteTraitement()) { |
327 | throw new AccessDeniedHttpException('La structure de ce traitement a le module conformité des traitements désactivé'); |
328 | } |
329 | /** @var User $user */ |
330 | $user = $this->getUser(); |
331 | if (!$user->hasAccessTo($traitement)) { |
332 | return $this->redirectToRoute($this->getRouteName('list')); |
333 | } |
334 | |
335 | /** |
336 | * @var AnalyseImpact $object |
337 | */ |
338 | if ($object->isValidated()) { |
339 | $this->addFlash('info', $this->getFlashbagMessage('info', 'cant_edit', $object)); |
340 | |
341 | return $this->redirectToRoute($this->getRouteName('list')); |
342 | } |
343 | |
344 | $this->analyseFlow->bind($object); |
345 | $form = $this->analyseFlow->createForm(); |
346 | |
347 | if ($this->analyseFlow->isValid($form)) { |
348 | $this->formPrePersistData($object); |
349 | $this->analyseFlow->saveCurrentStepData($form); |
350 | |
351 | if ($this->analyseFlow->nextStep()) { |
352 | $form = $this->analyseFlow->createForm(); |
353 | } else { |
354 | $this->entityManager->persist($object); |
355 | $this->entityManager->flush(); |
356 | |
357 | $this->analyseFlow->reset(); |
358 | |
359 | $this->addFlash('success', $this->getFlashbagMessage('success', 'edit', $object)); |
360 | |
361 | return $this->redirectToRoute($this->getRouteName('evaluation'), [ |
362 | 'id' => $id, |
363 | ]); |
364 | } |
365 | } |
366 | |
367 | return $this->render($this->getTemplatingBasePath('edit'), [ |
368 | 'flow' => $this->analyseFlow, |
369 | 'form' => $form->createView(), |
370 | ]); |
371 | } |
372 | |
373 | public function modelesDatatablesAction() |
374 | { |
375 | $request = $this->requestStack->getMasterRequest(); |
376 | $collectivity = $this->entityManager->getRepository(Collectivity::class)->find($request->query->get('collectivity')); |
377 | |
378 | $modeles = $this->getModeleResults($request); |
379 | |
380 | $reponse = $this->getBaseDataTablesResponse($request, $modeles); |
381 | foreach ($modeles as $modele) { |
382 | $collectivityType = $collectivity->getType(); |
383 | $authorizedCollectivities = $modele->getAuthorizedCollectivities(); |
384 | $authorizedCollectivityTypes = $modele->getAuthorizedCollectivityTypes(); |
385 | |
386 | if ((!\is_null($authorizedCollectivityTypes) |
387 | && in_array($collectivityType, $authorizedCollectivityTypes)) |
388 | || $authorizedCollectivities->contains($collectivity) |
389 | ) { |
390 | $reponse['data'][] = [ |
391 | 'nom' => '<div class="radio"><label class="required" for="' . $modele->getId() . '"><input type="radio" id="' . $modele->getId() . '" value="' . $modele->getId() . '" name="modele_choice" required="true"/> ' . $modele->getNom() . '</label></div>', |
392 | 'description' => $modele->getDescription(), |
393 | ]; |
394 | } |
395 | } |
396 | $reponse['recordsTotal'] = count($reponse['data']); |
397 | $reponse['recordsFiltered'] = count($reponse['data']); |
398 | |
399 | return new JsonResponse($reponse); |
400 | } |
401 | |
402 | public function evaluationAction(string $id) |
403 | { |
404 | if (null === $object = $this->repository->findOneById($id)) { |
405 | throw new NotFoundHttpException("No object found with ID '{$id}'"); |
406 | } |
407 | /** @var AnalyseImpact $object */ |
408 | if (!$object->getConformiteTraitement()->getTraitement()->getCollectivity()->isHasModuleConformiteTraitement()) { |
409 | throw new AccessDeniedHttpException('Ce module est désactivé sur la structure ' . $object->getConformiteTraitement()->getTraitement()->getCollectivity()); |
410 | } |
411 | |
412 | return $this->render($this->getTemplatingBasePath('evaluation'), [ |
413 | 'analyseImpact' => $object, |
414 | ]); |
415 | } |
416 | |
417 | protected function getModeleResults(Request $request): ?Paginator |
418 | { |
419 | $first = $request->request->get('start'); |
420 | $maxResults = $request->request->get('length'); |
421 | $orders = $request->request->get('order'); |
422 | $columns = $request->request->get('columns'); |
423 | |
424 | $orderColumn = $this->getCorrespondingLabelFromkeyForModeles($orders[0]['column']); |
425 | $orderDir = $orders[0]['dir']; |
426 | |
427 | $searches = []; |
428 | foreach ($columns as $column) { |
429 | if ('' !== $column['search']['value']) { |
430 | $searches[$column['data']] = $column['search']['value']; |
431 | } |
432 | } |
433 | |
434 | return $this->modeleRepository->findPaginated($first, $maxResults, $orderColumn, $orderDir, $searches); |
435 | } |
436 | |
437 | private function getCorrespondingLabelFromkeyForModeles(string $key) |
438 | { |
439 | return \array_key_exists($key, $this->getLabelAndKeysArrayForModeles()) ? $this->getLabelAndKeysArrayForModeles()[$key] : null; |
440 | } |
441 | |
442 | private function getLabelAndKeysArrayForModeles() |
443 | { |
444 | return [ |
445 | '0' => 'nom', |
446 | '1' => 'description', |
447 | ]; |
448 | } |
449 | |
450 | public function printAction(Request $request, string $id) |
451 | { |
452 | if (null === $object = $this->repository->findOneById($id)) { |
453 | throw new NotFoundHttpException("No object found with ID '{$id}'"); |
454 | } |
455 | |
456 | $traitement = $object->getConformiteTraitement()->getTraitement(); |
457 | if (!$traitement->getCollectivity()->isHasModuleConformiteTraitement()) { |
458 | throw new AccessDeniedHttpException('Ce module est désactivé sur la structure ' . $traitement->getCollectivity()); |
459 | } |
460 | /** @var User $user */ |
461 | $user = $this->getUser(); |
462 | if (!$user->hasAccessTo($traitement, false)) { |
463 | return $this->redirectToRoute($this->getRouteName('list')); |
464 | } |
465 | |
466 | $this->pdf->setOption('header-html', $this->renderView($this->getTemplatingBasePath('pdf_header'))); |
467 | $this->pdf->setOption('margin-top', '20'); |
468 | $this->pdf->setOption('margin-bottom', '15'); |
469 | $this->pdf->setOption('margin-left', '20'); |
470 | $this->pdf->setOption('margin-right', '20'); |
471 | |
472 | $slugger = new AsciiSlugger(); |
473 | $filename = $slugger->slug($object->getConformiteTraitement()->getTraitement()->getName()); |
474 | |
475 | $mesures = []; |
476 | $scenarios = $object->getScenarioMenaces(); |
477 | |
478 | foreach ($scenarios as $scenario) { |
479 | /* |
480 | * @var AnalyseScenarioMenace |
481 | */ |
482 | if ('negligeable' !== $scenario->getGravite() || 'vide' !== $scenario->getGravite() || 'negligeable' !== $scenario->getVraisemblance() || 'vide' !== $scenario->getVraisemblance()) { |
483 | foreach ($scenario->getMesuresProtections() as $mesure) { |
484 | if (!array_key_exists($mesure->getNom(), $mesures) && ($mesure->getPoidsGravite() <= 1 || $mesure->getPoidsVraisemblance() <= 1)) { |
485 | $mesures[$mesure->getNom()] = $mesure; |
486 | } |
487 | } |
488 | } |
489 | } |
490 | |
491 | return new PdfResponse( |
492 | $this->pdf->getOutputFromHtml( |
493 | $this->renderView($this->getTemplatingBasePath('pdf'), [ |
494 | 'object' => $object, |
495 | 'mesuresProtection' => $mesures, |
496 | 'base_dir' => $this->getParameter('kernel.project_dir') . '/public' . $request->getBasePath(), |
497 | ]), ['javascript-delay' => 1000]), |
498 | $filename . '.pdf' |
499 | ); |
500 | } |
501 | |
502 | public function validationAction(Request $request, string $id) |
503 | { |
504 | if (null === $object = $this->repository->findOneById($id)) { |
505 | throw new NotFoundHttpException("No object found with ID '{$id}'"); |
506 | } |
507 | if (!$object->isReadyForValidation()) { |
508 | $object->setIsReadyForValidation(true); |
509 | $this->entityManager->flush(); |
510 | } |
511 | |
512 | $traitement = $object->getConformiteTraitement()->getTraitement(); |
513 | if ($traitement->getCollectivity() && !$traitement->getCollectivity()->isHasModuleConformiteTraitement()) { |
514 | throw new AccessDeniedHttpException('La structure de ce traitement a le module conformité des traitements désactivé'); |
515 | } |
516 | /** @var User $user */ |
517 | $user = $this->getUser(); |
518 | if (!$user->hasAccessTo($traitement)) { |
519 | return $this->redirectToRoute($this->getRouteName('list')); |
520 | } |
521 | |
522 | /** @var Form $form */ |
523 | $form = $this->createForm(AnalyseAvisType::class, $object); |
524 | $form->handleRequest($request); |
525 | |
526 | if ($form->isSubmitted() && $form->isValid()) { |
527 | if ((!$form->getClickedButton() || 'saveDraft' !== $form->getClickedButton()->getName()) && ReponseAvisDictionary::REPONSE_NONE !== $object->getAvisResponsable()->getReponse()) { |
528 | $object->setDateValidation(new \DateTime()); |
529 | $object->setIsValidated(true); |
530 | $object->setStatut($object->getAvisResponsable()->getReponse()); |
531 | } |
532 | |
533 | $this->entityManager->flush(); |
534 | |
535 | return $this->redirectToRoute($this->getRouteName('list')); |
536 | } |
537 | |
538 | return $this->render($this->getTemplatingBasePath('validation'), [ |
539 | 'form' => $form->createView(), |
540 | ]); |
541 | } |
542 | |
543 | public function apiDeleteFile(ManagerRegistry $doctrine, Request $request): Response |
544 | { |
545 | $id = $request->get('id'); |
546 | $this->entityManager = $doctrine->getManager(); |
547 | $critere = $doctrine->getRepository(CriterePrincipeFondamental::class) |
548 | ->findOneBy(['fichier' => $id]); |
549 | |
550 | $critere->setFichier(null); |
551 | $this->entityManager->persist($critere); |
552 | $this->entityManager->flush(); |
553 | |
554 | $jsonResponse = new JsonResponse(); |
555 | $jsonResponse->setJson(json_encode($critere)); |
556 | |
557 | return $jsonResponse; |
558 | } |
559 | |
560 | public function deleteConfirmationAction(string $id): Response |
561 | { |
562 | /** @var AnalyseImpact $object */ |
563 | $object = $this->repository->findOneById($id); |
564 | if (!$object) { |
565 | throw new NotFoundHttpException("No object found with ID '{$id}'"); |
566 | } |
567 | $traitement = $object->getConformiteTraitement()->getTraitement(); |
568 | |
569 | if ($traitement->getCollectivity() && !$traitement->getCollectivity()->isHasModuleConformiteTraitement()) { |
570 | throw new AccessDeniedHttpException('La structure de ce traitement a le module conformité des traitements désactivé'); |
571 | } |
572 | |
573 | return parent::deleteConfirmationAction($id); |
574 | } |
575 | |
576 | public function deleteAction(string $id): Response |
577 | { |
578 | /** @var AnalyseImpact $object */ |
579 | $object = $this->repository->findOneById($id); |
580 | if (!$object) { |
581 | throw new NotFoundHttpException("No object found with ID '{$id}'"); |
582 | } |
583 | /** |
584 | * @var User $user |
585 | */ |
586 | $user = $this->getUser(); |
587 | $traitement = $object->getConformiteTraitement()->getTraitement(); |
588 | |
589 | if ($traitement->getCollectivity() && !$traitement->getCollectivity()->isHasModuleConformiteTraitement()) { |
590 | throw new AccessDeniedHttpException('La structure de ce traitement a le module conformité des traitements désactivé'); |
591 | } |
592 | if (!$user->hasAccessTo($traitement)) { |
593 | return $this->redirectToRoute($this->getRouteName('list')); |
594 | } |
595 | |
596 | return $this->render($this->getTemplatingBasePath('delete'), [ |
597 | 'object' => $object, |
598 | 'id' => $id, |
599 | ]); |
600 | } |
601 | } |