src/Controller/ActionController.php line 110

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Entity\Action;
  5. use App\Entity\ActionEconomique;
  6. use App\Entity\ActionFamiliale;
  7. use App\Entity\ActionPolitique;
  8. use App\Entity\ActionPublic;
  9. use App\Entity\ActionTag;
  10. use App\Entity\Departement;
  11. use App\Entity\Region;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Knp\Component\Pager\PaginatorInterface;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. /**
  19. * Action controller.
  20. */
  21. #[Route(path: '/action')]
  22. class ActionController extends AbstractController
  23. {
  24. private PaginatorInterface $paginator;
  25. private ManagerRegistry $em;
  26. public function __construct(PaginatorInterface $paginator, ManagerRegistry $em)
  27. {
  28. $this->paginator = $paginator;
  29. $this->em = $em;
  30. }
  31. /**
  32. * Lists all actions.
  33. */
  34. #[Route(path: '/actions', name: 'list_actions')]
  35. public function listActions(Request $request): Response
  36. {
  37. $query = $request->query;
  38. $filter_public = $query->get('public', '');
  39. $filter_familiale = $query->get('familiale', '');
  40. $filter_economique = $query->get('economique', '');
  41. $filter_culturel = $query->get('culturel', '');
  42. $filter_politique = $query->get('politique', '');
  43. $filter_departement = $query->get('departement', '');
  44. $filter_region = $query->get('region', '');
  45. $filter_annee = $query->get('annee', '');
  46. $filter_tag = $query->get('tag', '');
  47. // recuperations des items de liste
  48. $departements = $this->em->getRepository(Departement::class)->getAllByRegion($filter_region);
  49. $regions = $this->em->getRepository(Region::class)->findAll();
  50. $publics = $this->em->getRepository(ActionPublic::class)->findAll();
  51. $actionFamiliales = $this->em->getRepository(ActionFamiliale::class)->findAll();
  52. $actionEconomiques = $this->em->getRepository(ActionEconomique::class)->findAll();
  53. $actionCulturels = $this->em->getRepository(ActionEconomique::class)->findAll();
  54. $actionPolitiques = $this->em->getRepository(ActionPolitique::class)->findAll();
  55. $actionTags = $this->em->getRepository(ActionTag::class)->findAll();
  56. $pagination = $this->paginator->paginate(
  57. $this->em->getRepository(Action::class)->getListAction(
  58. $query->get('sort', 'e.created'),
  59. $query->get('direction', 'DESC'),
  60. $filter_public,
  61. $filter_familiale,
  62. $filter_economique,
  63. $filter_culturel,
  64. $filter_politique,
  65. $filter_departement,
  66. $filter_region,
  67. $filter_annee,
  68. $filter_tag
  69. ),
  70. $query->getInt('page', 1), /* page number */
  71. 25 /* limit per page */
  72. );
  73. return $this->render('Action/index.html.twig', [
  74. 'filter_public' => $filter_public,
  75. 'filter_familiale' => $filter_familiale,
  76. 'filter_economique' => $filter_economique,
  77. 'filter_culturel' => $filter_culturel,
  78. 'filter_politique' => $filter_politique,
  79. 'filter_departement' => $filter_departement,
  80. 'filter_region' => $filter_region,
  81. 'filter_annee' => $filter_annee,
  82. 'filter_tag' => $filter_tag,
  83. 'pagination' => $pagination,
  84. 'departements' => $departements,
  85. 'regions' => $regions,
  86. 'publics' => $publics,
  87. 'actionFamiliales' => $actionFamiliales,
  88. 'actionEconomiques' => $actionEconomiques,
  89. 'actionCulturels' => $actionCulturels,
  90. 'actionPolitiques' => $actionPolitiques,
  91. 'actionTags' => $actionTags,
  92. ]);
  93. }
  94. /**
  95. * Afficher les infos d'une action.
  96. */
  97. #[Route(path: '/show/{id}', name: 'show_action', methods: ['GET'])]
  98. public function show($id = null): Response
  99. {
  100. $entity = $this->em->getRepository(Action::class)->find($id);
  101. if (!$entity) {
  102. throw $this->createNotFoundException('Unable to find Action entity.');
  103. }
  104. return $this->render('Action/show.html.twig', [
  105. 'entity' => $entity,
  106. ]);
  107. }
  108. /**
  109. * Recherche geographique et par mots cles.
  110. */
  111. #[Route(path: '/geographical-and-tag-search', name: 'geographical_and_tag_search_action')]
  112. public function geographicalAndTagSearch(): Response
  113. {
  114. $connection = $this->em->getConnection();
  115. // tags
  116. $statement = $connection->prepare('SELECT at.action_tag_id, t.nom, count(at.action_tag_id) as count
  117. FROM actions_tag at
  118. LEFT JOIN ActionTag t ON at.action_tag_id = t.id
  119. GROUP BY at.action_tag_id
  120. ORDER BY t.nom ASC');
  121. $results_tags = $statement->execute()->fetchAll();
  122. $baseFontSize = '0.8';
  123. $maxFontSize = '2.5';
  124. // map
  125. $BaseQuery = 'SELECT * FROM Action a LEFT JOIN Structure s ON a.structure_id = s.id LEFT JOIN Departement d ON s.departement_id=d.id ';
  126. $statement1 = $connection->prepare('SELECT * FROM imap_departements');
  127. $GetImapDepartements = $statement1->execute()->fetchAll();
  128. $map_array = [];
  129. foreach ($GetImapDepartements as $result) {
  130. $statement2 = $connection->prepare($BaseQuery." WHERE d.num='".$result['id']."'");
  131. $Get_All = $statement2->execute()->fetchAll();
  132. $total_resultats = is_countable($Get_All) ? count($Get_All) : 0;
  133. $map_array[$result['id']]['id'] = $result['id'];
  134. $map_array[$result['id']]['departement'] = $result['departement'];
  135. $map_array[$result['id']]['total_resultats'] = $total_resultats;
  136. $map_array[$result['id']]['coords'] = $result['coords'];
  137. }
  138. return $this->render('Action/geographical_and_tag_search.html.twig', [
  139. 'results_tags' => $results_tags,
  140. 'baseFontSize' => $baseFontSize,
  141. 'maxFontSize' => $maxFontSize,
  142. 'map_array' => $map_array,
  143. ]);
  144. }
  145. }