Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
JournalisationController | |
0.00% |
0 / 42 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
indexAction | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
listDataTables | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
6 | |||
generateLinkCellContent | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
getLabelAndKeysArray | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Domain\Reporting\Controller; |
4 | |
5 | use App\Application\Traits\ServersideDatatablesTrait; |
6 | use App\Domain\Reporting\Dictionary\LogJournalActionDictionary; |
7 | use App\Domain\Reporting\Dictionary\LogJournalSubjectDictionary; |
8 | use App\Domain\Reporting\Generator\LogJournalLinkGenerator; |
9 | use App\Domain\Reporting\Model\LogJournal as LogModel; |
10 | use App\Domain\Reporting\Repository\LogJournal; |
11 | use Doctrine\ORM\Tools\Pagination\Paginator; |
12 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
13 | use Symfony\Component\HttpFoundation\JsonResponse; |
14 | use Symfony\Component\HttpFoundation\Request; |
15 | use Symfony\Component\Routing\RouterInterface; |
16 | use Symfony\Contracts\Translation\TranslatorInterface; |
17 | |
18 | class JournalisationController extends AbstractController |
19 | { |
20 | use ServersideDatatablesTrait; |
21 | |
22 | /** |
23 | * @var RouterInterface |
24 | */ |
25 | private $router; |
26 | |
27 | /** |
28 | * @var LogJournalLinkGenerator |
29 | */ |
30 | private $logJournalLinkGenerator; |
31 | private TranslatorInterface $translator; |
32 | |
33 | public function __construct(LogJournal $logRepository, TranslatorInterface $translator, RouterInterface $router, LogJournalLinkGenerator $logJournalLinkGenerator) |
34 | { |
35 | $this->translator = $translator; |
36 | $this->repository = $logRepository; |
37 | $this->router = $router; |
38 | $this->logJournalLinkGenerator = $logJournalLinkGenerator; |
39 | } |
40 | |
41 | public function indexAction() |
42 | { |
43 | return $this->render('Reporting/Journalisation/list.html.twig', [ |
44 | 'totalItem' => $this->repository->count(), |
45 | 'route' => $this->router->generate('reporting_journalisation_list_datatables'), |
46 | ]); |
47 | } |
48 | |
49 | public function listDataTables(Request $request): JsonResponse |
50 | { |
51 | /** @var Paginator $logs */ |
52 | $logs = $this->getResults($request); |
53 | |
54 | $reponse = $this->getBaseDataTablesResponse($request, $logs); |
55 | |
56 | /** @var LogModel $log */ |
57 | foreach ($logs as $log) { |
58 | $reponse['data'][] = [ |
59 | 'subjectId' => $log->getSubjectId(), |
60 | 'userFullName' => $log->getUserFullName(), |
61 | 'userEmail' => $log->getUserEmail(), |
62 | 'collectivite' => $log->getCollectivity()->getName(), |
63 | 'date' => date_format($log->getDate(), 'd-m-Y H:i'), |
64 | 'subject' => LogJournalSubjectDictionary::getSubjectLabelFromSubjectType($log->getSubjectType()), |
65 | 'action' => LogJournalActionDictionary::getActions()[$log->getAction()], |
66 | 'subjectName' => $log->getSubjectName(), |
67 | 'link' => $this->generateLinkCellContent($log), |
68 | ]; |
69 | } |
70 | |
71 | $jsonResponse = new JsonResponse(); |
72 | $jsonResponse->setJson(json_encode($reponse)); |
73 | |
74 | return $jsonResponse; |
75 | } |
76 | |
77 | private function generateLinkCellContent(LogModel $log) |
78 | { |
79 | if (LogJournalSubjectDictionary::ADMIN_DUPLICATION === $log->getSubjectType()) { |
80 | return; |
81 | } |
82 | |
83 | $content = $this->logJournalLinkGenerator->getLink($log); |
84 | |
85 | if (LogJournalLinkGenerator::DELETE_LABEL === $content) { |
86 | return $content; |
87 | } |
88 | |
89 | return '<a href="' . $content . '">' . $this->translator->trans('reporting.journalisation.action.check') . '</a>'; |
90 | } |
91 | |
92 | protected function getLabelAndKeysArray(): array |
93 | { |
94 | return [ |
95 | '0' => 'subjectId', |
96 | '1' => 'userFullName', |
97 | '2' => 'userEmail', |
98 | '3' => 'collectivite', |
99 | '4' => 'date', |
100 | '5' => 'subject', |
101 | '6' => 'action', |
102 | '7' => 'subjectName', |
103 | '8' => 'link', |
104 | ]; |
105 | } |
106 | } |