src/Controller/MainController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Note;
  4. use App\Entity\Movie;
  5. use App\Form\NoteType;
  6. use App\Entity\Session;
  7. use App\Form\MovieType;
  8. use App\Entity\Reservation;
  9. use Doctrine\ORM\Mapping\Id;
  10. use App\Form\ReservationType;
  11. use App\Repository\NoteRepository;
  12. use App\Repository\UserRepository;
  13. use App\Repository\MovieRepository;
  14. use App\Repository\SessionRepository;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use App\Repository\ReservationRepository;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
  23. class MainController extends AbstractController
  24. {
  25.     #[Route('/'name'main')]
  26.     public function index(MovieRepository $movieRepository): Response
  27.     {
  28.         return $this->render('main/index.html.twig', [
  29.             'controller_name' => 'MainController',
  30.             'movies' => $movieRepository->findAll(),
  31.         ]);
  32.     }
  33.     #[Route('/films'name'films')]
  34.     public function films(MovieRepository $movieRepository): Response
  35.     {
  36.         return $this->render('main/films.html.twig', [
  37.             'controller_name' => 'MainController',
  38.             'movies' => $movieRepository->findAll(),
  39.         ]);
  40.     }
  41.     #[Route('/films/{id}'name'filmsShow'methods: ['GET''POST'])]
  42.     public function filmsShow(Request $requestSessionRepository $sessionRepository,NoteRepository $noteRepository ,Movie $movieEntityManagerInterface $entityManager): Response
  43.     {
  44.         $note = new Note();
  45.         $user $this->getUser();
  46.         $allNotesByUser $noteRepository->findBy(array('idUser' => $user));
  47.         $notesStatus 0;
  48.         foreach($allNotesByUser as $value){
  49.             if($value->getIdMovie() == $movie){
  50.                 $notesStatus 1;
  51.             }
  52.         }
  53.         $note->setIdUser($this->getUser());
  54.         $note->setIdMovie($movie);
  55.         $form $this->createForm(NoteType::class, $note);
  56.         $form->handleRequest($request);
  57.         
  58.         if ($form->isSubmitted() && $form->isValid()) {
  59.             $entityManager->persist($note);
  60.             $entityManager->flush();
  61.             return $this->redirectToRoute('filmsShow', ['id' => $movie->getId()], Response::HTTP_SEE_OTHER);
  62.         }
  63.         return $this->renderForm('main/filmsShow.html.twig', [
  64.             'controller_name' => 'MainController',
  65.             'movie' => $movie,
  66.             'form' => $form,
  67.             'notesStatus' => $notesStatus,
  68.             'allNotesByMovie' => $noteRepository->findBy(array('idMovie' => $movie)),
  69.             'allSessionsByMovie' => $sessionRepository->findBy(array('idMovie' => $movie)),
  70.         ]);
  71.     }
  72.     #[Route('/contacts'name'contacts')]
  73.     public function contact(): Response
  74.     {
  75.         return $this->render('main/contact.html.twig', [
  76.             'controller_name' => 'MainController',
  77.         ]);
  78.     }
  79.     #[Route('/compte'name'compte')]
  80.     public function compte(UserRepository $userRepositorySessionRepository $sessionRepositoryReservationRepository $reservationRepositoryMovieRepository $movieRepositoryNoteRepository $noteRepository): Response
  81.     {
  82.         $user $this->getUser();
  83.         // Recupere les données des réservations
  84.         $allReservations $reservationRepository->findBy(array('idUser' => $user));
  85.         $allSessionsReserved = [];
  86.         foreach ($allReservations as $value) {
  87.             $value $sessionRepository->findOneBy(array('id' => $value->getIdSession()));
  88.             array_push($allSessionsReserved$value);
  89.         }
  90.         // Recupere les données des notes
  91.         $allNotesByUser =  $noteRepository->findBy(array('idUser' => $user));
  92.         return $this->render('main/profile.html.twig', [
  93.             'controller_name' => 'MainController',
  94.             'allReservation' => $allReservations,
  95.             'allSessionsReserved' => $allSessionsReserved,
  96.             'allNotesByUser' => $allNotesByUser,
  97.         ]);
  98.     }
  99.     #[Route('/tarifs'name'tarifs')]
  100.     public function tarifs(): Response
  101.     {
  102.         return $this->render('main/tarifs.html.twig', [
  103.             'controller_name' => 'MainController',
  104.         ]);
  105.     }
  106.     #[Route('/réservation/{id}'name'userReservation'methods: ['GET''POST'])]
  107.     public function userReservation(Session $session): Response
  108.     {
  109.         $sessionD $session->getNumberD();
  110.         return $this->render('main/userReservation.html.twig', [
  111.             'controller_name' => 'MainController',
  112.             'session' => $session,
  113.             'sessionD' => $sessionD,
  114.         ]);
  115.     }
  116.     #[Route('/réservation/validation/{id}'name'userReservationValidation'methods: ['GET''POST'])]
  117.     public function userReservationValidation(Session $sessionReservationRepository $reservationRepositoryEntityManagerInterface $entityManager): Response
  118.     {
  119.         $user $this->getUser();
  120.         if($user){
  121.             // Preparation de la reservation
  122.             $reservation = new Reservation();
  123.             $reservation->setIdUser($this->getUser());
  124.             $reservation->setIdSession($session);
  125.             // Recupere le nombre de places
  126.             $sessionD $session->getNumberD();
  127.             // Verification si l'utilisateur est connecte ET si il y a de la place dans la séance ET si l'utilisateur n'a pas deja reserve PUIS envoie
  128.             $sessionId strval($session->getId());
  129.             $userReservationCheck $reservationRepository->findOneBy(['idUser' => $user'idSession' => $sessionId]);
  130.             if( $user && $sessionD != && $userReservationCheck == null){
  131.                 // -1 place dans la salle
  132.                 $sessionD $sessionD 1;
  133.                 $session->setNumberD($sessionD);
  134.                 // envoie des données
  135.                 $entityManager->persist($reservation$session);
  136.                 $entityManager->flush();
  137.                 // redirection
  138.                 return $this->redirectToRoute('validationPage', ['id' => "1"], Response::HTTP_SEE_OTHER);
  139.             }
  140.         }
  141.         return $this->render('main/userReservation.html.twig', [
  142.             'controller_name' => 'MainController',
  143.             'session' => $session,
  144.             'sessionD' => $sessionD,
  145.         ]);
  146.     }
  147.     #[Route('/validation/{id}'name'validationPage'methods: ['GET''POST'])]
  148.     public function validationPage(Request $requestEntityManagerInterface $entityManager): Response
  149.     {
  150.         return $this->render('announcement/validation.html.twig', [
  151.             'controller_name' => 'MainController',
  152.         ]);
  153.     }
  154.     #[Route('/erreur/{id}'name'errorPage'methods: ['GET''POST'])]
  155.     public function errorPage(Request $requestEntityManagerInterface $entityManager): Response
  156.     {
  157.         return $this->render('announcement/error.html.twig', [
  158.             'controller_name' => 'MainController',
  159.         ]);
  160.     }
  161.     public function header(): Response
  162.     {
  163.         return $this->render('/includes/header.html.twig', [
  164.         ]);
  165.     }
  166.     public function footer(): Response
  167.     {
  168.         return $this->render('/includes/footer.html.twig', [
  169.         ]);
  170.     }
  171.     #[Route('/admin'name'app_admin'),
  172.     IsGranted("ROLE_ADMIN")]
  173.     public function admin(): Response
  174.     {
  175.         return $this->render('admin/index.html.twig', []);
  176.     }
  177. }