Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 49 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
MesureProtectionController | |
0.00% |
0 / 49 |
|
0.00% |
0 / 9 |
240 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getDomain | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getModel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getModelClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFormType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
listAction | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
listDataTables | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
42 | |||
getLabelAndKeysArray | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
generateActionCellContent | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 |
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\Form\Type\MesureProtectionAIPDType; |
11 | use App\Domain\AIPD\Model\ModeleMesureProtection; |
12 | use App\Domain\AIPD\Repository; |
13 | use Doctrine\ORM\EntityManagerInterface; |
14 | use Knp\Snappy\Pdf; |
15 | use Symfony\Component\HttpFoundation\JsonResponse; |
16 | use Symfony\Component\HttpFoundation\Request; |
17 | use Symfony\Component\HttpFoundation\RequestStack; |
18 | use Symfony\Component\HttpFoundation\Response; |
19 | use Symfony\Component\Routing\RouterInterface; |
20 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
21 | use Symfony\Contracts\Translation\TranslatorInterface; |
22 | |
23 | /** |
24 | * @property Repository\ModeleMesureProtection $repository |
25 | */ |
26 | class MesureProtectionController extends CRUDController |
27 | { |
28 | use ServersideDatatablesTrait; |
29 | |
30 | private RequestStack $requestStack; |
31 | |
32 | /** |
33 | * @var RouterInterface |
34 | */ |
35 | private $router; |
36 | |
37 | public function __construct( |
38 | EntityManagerInterface $entityManager, |
39 | TranslatorInterface $translator, |
40 | Repository\ModeleMesureProtection $repository, |
41 | Pdf $pdf, |
42 | UserProvider $userProvider, |
43 | AuthorizationCheckerInterface $authorizationChecker, |
44 | RequestStack $requestStack, |
45 | RouterInterface $router, |
46 | ) { |
47 | parent::__construct($entityManager, $translator, $repository, $pdf, $userProvider, $authorizationChecker); |
48 | $this->requestStack = $requestStack; |
49 | $this->router = $router; |
50 | } |
51 | |
52 | protected function getDomain(): string |
53 | { |
54 | return 'aipd'; |
55 | } |
56 | |
57 | protected function getModel(): string |
58 | { |
59 | return 'mesure_protection'; |
60 | } |
61 | |
62 | protected function getModelClass(): string |
63 | { |
64 | return ModeleMesureProtection::class; |
65 | } |
66 | |
67 | protected function getFormType(): string |
68 | { |
69 | return MesureProtectionAIPDType::class; |
70 | } |
71 | |
72 | public function listAction(): Response |
73 | { |
74 | return $this->render($this->getTemplatingBasePath('list'), [ |
75 | 'totalItem' => $this->repository->count(), |
76 | 'route' => $this->router->generate('aipd_mesure_protection_list_datatables'), |
77 | ]); |
78 | } |
79 | |
80 | public function listDataTables(Request $request): JsonResponse |
81 | { |
82 | $request = $this->requestStack->getMasterRequest(); |
83 | |
84 | $mesures = $this->getResults($request); |
85 | |
86 | $reponse = $this->getBaseDataTablesResponse($request, $mesures); |
87 | /** @var ModeleMesureProtection $mesure */ |
88 | foreach ($mesures as $mesure) { |
89 | /** @var ModeleMesureProtection $m */ |
90 | $m = $mesure[0]; |
91 | $reponse['data'][] = [ |
92 | 'nom' => $m->getNom(), |
93 | 'nomCourt' => $m->getNomCourt(), |
94 | 'detail' => $m->getDetail(), |
95 | 'poidsVraisemblance' => $m->getPoidsVraisemblance(), |
96 | 'poidsGravite' => $m->getPoidsGravite(), |
97 | 'createdAt' => $m->getCreatedAt() && $m->getCreatedAt()->format('Y') > 0 ? $m->getCreatedAt()->format('d-m-Y H:i') : '', |
98 | 'updatedAt' => $m->getUpdatedAt() && $m->getUpdatedAt()->format('Y') > 0 ? $m->getUpdatedAt()->format('d-m-Y H:i') : '', |
99 | 'actions' => $this->generateActionCellContent($mesure['id']), |
100 | ]; |
101 | } |
102 | |
103 | $jsonResponse = new JsonResponse(); |
104 | $jsonResponse->setJson(json_encode($reponse)); |
105 | |
106 | return $jsonResponse; |
107 | } |
108 | |
109 | protected function getLabelAndKeysArray(): array |
110 | { |
111 | return [ |
112 | '0' => 'nom', |
113 | '1' => 'nomCourt', |
114 | '2' => 'detail', |
115 | '3' => 'poidsVraisemblance', |
116 | '4' => 'poidsGravite', |
117 | '5' => 'createdAt', |
118 | '6' => 'updatedAt', |
119 | '7' => 'actions', |
120 | ]; |
121 | } |
122 | |
123 | private function generateActionCellContent($id) |
124 | { |
125 | if ($id) { |
126 | $editPath = $this->router->generate('aipd_mesure_protection_edit', ['id' => $id]); |
127 | $deletePath = $this->router->generate('aipd_mesure_protection_delete', ['id' => $id]); |
128 | |
129 | return '<a href="' . $editPath . '"> |
130 | <i aria-hidden="true" class="fa fa-pencil"></i> |
131 | ' . $this->translator->trans('global.action.edit') . ' |
132 | </a> |
133 | <a href="' . $deletePath . '"> |
134 | <i aria-hidden="true" class="fa fa-trash"></i> |
135 | ' . $this->translator->trans('global.action.delete') . ' |
136 | </a>' |
137 | ; |
138 | } |
139 | |
140 | return null; |
141 | } |
142 | } |