MainController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Requirement\Requirement;
  6. use Symfony\Component\Routing\Attribute\Route;
  7. use App\Repository\EventRepository;
  8. use App\Entity\Event;
  9. use App\Entity\Gamemaster;
  10. final class MainController extends AbstractController
  11. {
  12. #[Route('/', name: 'app_main')]
  13. public function index(EventRepository $repository): Response
  14. {
  15. // Est-ce qu'un utilisateur est connecté et qu'il est au moins "staff" ?
  16. $user = $this->getUser();
  17. $onlyPublicAccess = true;
  18. if ($user) {
  19. $roles = $user->getRoles();
  20. if (in_array('ROLE_STAFF', $roles) || in_array('ROLE_MANAGER', $roles) || in_array('ROLE_ADMIN', $roles)) {
  21. $onlyPublicAccess = false;
  22. }
  23. }
  24. // Récupérer la liste des événements visibles
  25. $events = $repository->findEventsToCome($onlyPublicAccess);
  26. return $this->render('main/index.html.twig', [
  27. 'events' => $events,
  28. ]);
  29. }
  30. #[Route('/booking', name: 'app_main_booking_main')]
  31. public function bookingMain(EventRepository $repository): Response
  32. {
  33. // Est-ce qu'un utilisateur est connecté et qu'il est au moins "staff" ?
  34. $user = $this->getUser();
  35. $onlyPublicAccess = true;
  36. if ($user) {
  37. $roles = $user->getRoles();
  38. if (in_array('ROLE_STAFF', $roles) || in_array('ROLE_MANAGER', $roles) || in_array('ROLE_ADMIN', $roles)) {
  39. $onlyPublicAccess = false;
  40. }
  41. }
  42. // Récupérer la liste des événements visibles
  43. $events = $repository->findEventsToCome($onlyPublicAccess);
  44. if (!$events) {
  45. $this->addFlash('info', 'Aucun d\'événement n\'est plannifié pour le moment.');
  46. return $this->redirectToRoute('app_main');
  47. }
  48. $event = $events[0];
  49. return $this->render('main/booking.html.twig', [
  50. 'event' => $event,
  51. 'events' => $events
  52. ]);
  53. }
  54. #[Route('/booking/{id}', name: 'app_main_booking', requirements: ['id' => Requirement::UUID_V7], methods: ['GET', 'POST'])]
  55. public function booking(?Event $event, EventRepository $repository): Response
  56. {
  57. // Contrôler qu'un événement est bien ok
  58. if (!$event) {
  59. $this->addFlash('danger', 'Événement inconnu !');
  60. $this->redirectToRoute('app_main_booking_main');
  61. }
  62. // Est-ce qu'un utilisateur est connecté et qu'il est au moins "staff" ?
  63. $user = $this->getUser();
  64. $onlyPublicAccess = true;
  65. if ($user) {
  66. $roles = $user->getRoles();
  67. if (in_array('ROLE_STAFF', $roles) || in_array('ROLE_MANAGER', $roles) || in_array('ROLE_ADMIN', $roles)) {
  68. $onlyPublicAccess = false;
  69. }
  70. }
  71. // Récupérer la liste des événements visibles
  72. $events = $repository->findEventsToCome($onlyPublicAccess);
  73. return $this->render('main/booking.html.twig', [
  74. 'event' => $event,
  75. 'events' => $events
  76. ]);
  77. }
  78. #[Route('/charte-animations', name: 'app_code_of_conduct')]
  79. public function codeOfConduct(): Response
  80. {
  81. // Lire le contenu de la charte des animations depuis un fichier
  82. $codeContent = file_get_contents(__DIR__ . '/../../public/pages/code.md');
  83. return $this->render('main/markdown.html.twig', [
  84. 'codeContent' => $codeContent,
  85. ]);
  86. }
  87. #[Route('/cgu', name: 'app_terms')]
  88. public function terms(): Response
  89. {
  90. // Lire le contenu de la charte des animations depuis un fichier
  91. $codeContent = file_get_contents(__DIR__ . '/../../public/pages/terms.md');
  92. return $this->render('main/markdown.html.twig', [
  93. 'codeContent' => $codeContent,
  94. ]);
  95. }
  96. #[Route('/legal', name: 'app_legal')]
  97. public function legal(): Response
  98. {
  99. // Lire le contenu de la charte des animations depuis un fichier
  100. $codeContent = file_get_contents(__DIR__ . '/../../public/pages/legal.md');
  101. return $this->render('main/markdown.html.twig', [
  102. 'codeContent' => $codeContent,
  103. ]);
  104. }
  105. #[Route('/contact', name: 'app_contact')]
  106. public function contact(): Response
  107. {
  108. // TODO: formulaire de contact avec envoi d'un mail
  109. // Lire le contenu de la charte des animations depuis un fichier
  110. $codeContent = file_get_contents(__DIR__ . '/../../public/pages/legal.md');
  111. return $this->render('main/markdown.html.twig', [
  112. 'codeContent' => $codeContent,
  113. ]);
  114. }
  115. #[Route('/gamemaster/{id}', name: 'app_gamemaster_public_profile', requirements: ['id' => Requirement::UUID_V7], methods: ['GET'])]
  116. public function gamemasterPublicProfile(?Gamemaster $gamemaster): Response
  117. {
  118. if ($gamemaster) {
  119. return $this->render('main/_modal.gamemaster.html.twig', [
  120. 'gamemaster' => $gamemaster,
  121. ]);
  122. } else {
  123. $this->addFlash('danger', 'Meneur(euse) de jeu inconnu(e).');
  124. return $this->redirectToRoute('app_main');
  125. }
  126. }
  127. }