Browse Source

Réorganisation controlleurs videotheque

Sangfroid 9 months ago
parent
commit
dde63e2768

+ 130 - 0
src/Controller/VideothequeCrudController.php

@@ -0,0 +1,130 @@
+<?php
+
+namespace App\Controller;
+
+use App\Entity\Film;
+use App\Form\FilmType;
+use App\Repository\FilmRepository;
+use App\Service\FilmManager;
+use App\Service\TmdbApiService;
+use Doctrine\ORM\EntityManagerInterface;
+use Symfony\Component\Form\FormFactoryInterface;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\Routing\Annotation\Route;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Security\Http\Attribute\IsGranted;
+
+class VideothequeCrudController extends FilmAbstractController
+{
+    #[Route("/maliste/modifieravoir", name:"maliste_modifier_a_voir", methods: ['PATCH'])]
+    public function modifierFilmDansListeAction(Request $request, EntityManagerInterface $em, FilmRepository $repo, FilmManager $filmManager): Response
+    {
+        $result = null;
+        $film = $repo->find($request->toArray()['id_film']);
+        $result = $filmManager->inverseUserWantToView($film);
+        $em->flush();
+        /*$resultat = $this->get('serializer')->serialize($film, 'json');*/
+        return new JsonResponse((object)['newState' => $result]);
+    }
+
+    #[Route("/maliste/modifiervus", name:"maliste_modifier_vus", methods: ['PATCH'])]
+    public function modifierFilmVusAction(Request $request, FilmRepository $repo, EntityManagerInterface $em, FilmManager $filmManager): Response
+    {
+        $result = null;
+
+        $film = $repo->find($request->toArray()['id_film']);
+        $result = $filmManager->inverseUserWhoSeen($film);
+        $em->flush();
+        return new JsonResponse((object)['newState' => $result]);
+    }
+
+    #[Route("/ajouter/{idtmdb}", name: "videotheque_ajouter")]
+	public function ajouterAction(Request $request, FilmManager $filmManager, TmdbApiService $tmdbApiService, string $idtmdb=null): Response
+	{
+        if ($idtmdb !== null) {
+            $film = $tmdbApiService->hydrateFilm($idtmdb);
+        } else {
+    		$film = new Film;
+        }
+		$form = $this->createForm(FilmType::class, $film);
+
+		$form->handleRequest($request);
+		if ($form->isSubmitted() && $form->isValid())
+		{
+			$filmManager->addFilm($film);
+			$this->addFlash('success', 'Le film a été ajouté');
+			return $this->redirectToRoute('videotheque_voirfilm', array('id'=>$film->getId()));
+		}
+
+		return $this->render('videotheque/ajouter.html.twig', array(
+			'form'	=>	$form,
+		));
+	}
+
+    #[Route("/addtmdb", name: "videotheque_ajouter_tmdb")]
+    public function ajouterTmdb(Request $request, TmdbApiService $tmdbApiService): Response
+    {
+        $films = array();
+        $nbFilms = 0;
+        $nbPages = 0;
+        
+        $page = (int) $request->query->get('page', 1);
+        if ($page === 0) {
+            $page = 1;
+        }
+        $recherche = $request->query->get('query', "");
+
+        if ($tmdbApiService->query($recherche, $page)) {
+            $nbFilms = $tmdbApiService->countResults();
+            $nbPages = $tmdbApiService->countPages();
+            $films = $tmdbApiService->getFilms();
+        }
+        
+        return $this->render('videotheque/add_tmdb.html.twig', [
+            'titre' => 'Ajouter via TheMovieDB.org',
+            'films'  => $films,
+            'nbFilms'    => $nbFilms,
+            'nbPages'   => $nbPages,
+            'page'  => $page,
+            'recherche' => $recherche
+        ]);
+    }
+
+	#[Route("/modifier/{id}", name: "videotheque_modifier")]
+	public function modifierAction(Request $request, Film $film, FilmManager $filmManager): Response
+	{
+		$form = $this->createForm(FilmType::class, $film);
+		$form->handleRequest($request);
+		if ($form->isSubmitted() && $form->isValid())
+		{
+            $filmManager->editFilm($film);
+			$this->addFlash('success', 'Le film a été modifié');
+			return $this->redirectToRoute('videotheque_voirfilm',array('id'=>$film->getId()));
+		}
+
+		return $this->render('videotheque/modifier.html.twig', array(
+			'form'	=> $form,
+		));
+	}
+
+	#[Route("/supprimer/{id}", name: "videotheque_supprimer")]
+    #[IsGranted("ROLE_ADMIN")]
+	public function supprimerAction(Request $request, Film $film, FilmManager $filmManager, FormFactoryInterface $ffi): Response
+	{
+        $form = $ffi->create();
+        $form->handleRequest($request);
+        if ($form->isSubmitted() && $form->isValid())
+        {
+            $filmManager->delFilm($film);
+            $this->addFlash('success', 'Le film '.$film->getTitre().' a bien été supprimé.');
+            return $this->redirectToRoute('videotheque_liste');
+        }
+
+		return $this->render('videotheque/supprimer.html.twig', array(
+			'film'  =>  $film,
+            'form'  =>  $form
+		));
+	}
+
+}

+ 13 - 95
src/Controller/VideothequeController.php → src/Controller/VideothequeListController.php

@@ -7,24 +7,18 @@ use App\Entity\Realisateur;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\Routing\Annotation\Route;
 use Symfony\Component\HttpFoundation\Request;
-use App\Entity\Film;
 use App\Entity\Genre;
 use App\Form\CommentaireType;
-use App\Form\FilmType;
 use App\Repository\CommentaireRepository;
 use App\Repository\FilmRepository;
 use App\Repository\GenreRepository;
 use App\Repository\RealisateurRepository;
 use App\Service\CommentaireManager;
-use App\Service\FilmManager;
 use App\Service\OptionsManager;
-use App\Service\TmdbApiService;
 use Symfony\Bundle\SecurityBundle\Security;
-use Symfony\Component\Form\FormFactoryInterface;
 use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\Security\Http\Attribute\IsGranted;
 
-class VideothequeController extends FilmAbstractController
+class VideothequeListController extends FilmAbstractController
 {
 	#[Route("/", name: "videotheque_liste")]
 	public function listeAction(Request $request, FilmRepository $filmRepository, OptionsManager $options): Response
@@ -39,6 +33,18 @@ class VideothequeController extends FilmAbstractController
 		));
     }
 
+    #[Route("/maliste", name:"videothequepersonnelle_maliste")]
+	public function maListeAction (Request $request, OptionsManager $options, FilmRepository $filmRepository): Response
+    {
+        $filtersForm = $this->formPagination($request);
+        $listeFilms = $filmRepository->findTousFavoritesByUser($this->getUser(), $filtersForm->getData()->toArray());
+        return $this->render('videotheque/liste_'.$options->vue().'.html.twig', array(
+            'listeFilms'    =>  $listeFilms,
+            'titre'         =>  'Ma liste de films à voir',
+            'filtersForm'   => $filtersForm->createView()
+        ));
+    }
+
     #[Route("/prochaines-sorties", name: "prochaines_sorties")]
     public function prochainesSorties(FilmRepository $repo, OptionsManager $options): Response
     {
@@ -76,94 +82,6 @@ class VideothequeController extends FilmAbstractController
         ));
     }
 
-	#[Route("/ajouter/{idtmdb}", name: "videotheque_ajouter")]
-	public function ajouterAction(Request $request, FilmManager $filmManager, TmdbApiService $tmdbApiService, string $idtmdb=null): Response
-	{
-        if ($idtmdb !== null) {
-            $film = $tmdbApiService->hydrateFilm($idtmdb);
-        } else {
-    		$film = new Film;
-        }
-		$form = $this->createForm(FilmType::class, $film);
-
-		$form->handleRequest($request);
-		if ($form->isSubmitted() && $form->isValid())
-		{
-			$filmManager->addFilm($film);
-			$this->addFlash('success', 'Le film a été ajouté');
-			return $this->redirectToRoute('videotheque_voirfilm', array('id'=>$film->getId()));
-		}
-
-		return $this->render('videotheque/ajouter.html.twig', array(
-			'form'	=>	$form,
-		));
-	}
-
-    #[Route("/addtmdb", name: "videotheque_ajouter_tmdb")]
-    public function ajouterTmdb(Request $request, TmdbApiService $tmdbApiService): Response
-    {
-        $films = array();
-        $nbFilms = 0;
-        $nbPages = 0;
-        
-        $page = (int) $request->query->get('page', 1);
-        if ($page === 0) {
-            $page = 1;
-        }
-        $recherche = $request->query->get('query', "");
-
-        if ($tmdbApiService->query($recherche, $page)) {
-            $nbFilms = $tmdbApiService->countResults();
-            $nbPages = $tmdbApiService->countPages();
-            $films = $tmdbApiService->getFilms();
-        }
-        
-        return $this->render('videotheque/add_tmdb.html.twig', [
-            'titre' => 'Ajouter via TheMovieDB.org',
-            'films'  => $films,
-            'nbFilms'    => $nbFilms,
-            'nbPages'   => $nbPages,
-            'page'  => $page,
-            'recherche' => $recherche
-        ]);
-    }
-
-	#[Route("/modifier/{id}", name: "videotheque_modifier")]
-	public function modifierAction(Request $request, Film $film, FilmManager $filmManager): Response
-	{
-		$form = $this->createForm(FilmType::class, $film);
-		$form->handleRequest($request);
-		if ($form->isSubmitted() && $form->isValid())
-		{
-            $filmManager->editFilm($film);
-			$this->addFlash('success', 'Le film a été modifié');
-			return $this->redirectToRoute('videotheque_voirfilm',array('id'=>$film->getId()));
-		}
-
-		return $this->render('videotheque/modifier.html.twig', array(
-			'form'	=> $form,
-		));
-	}
-
-	#[Route("/supprimer/{id}", name: "videotheque_supprimer")]
-    #[IsGranted("ROLE_ADMIN")]
-	public function supprimerAction(Request $request, Film $film, FilmManager $filmManager, FormFactoryInterface $ffi): Response
-	{
-        $form = $ffi->create();
-        $form->handleRequest($request);
-        if ($form->isSubmitted() && $form->isValid())
-        {
-            $filmManager->delFilm($film);
-            $this->addFlash('success', 'Le film '.$film->getTitre().' a bien été supprimé.');
-            return $this->redirectToRoute('videotheque_liste');
-        }
-
-		return $this->render('videotheque/supprimer.html.twig', array(
-			'film'  =>  $film,
-            'form'  =>  $form
-		));
-	}
-
 	#[Route("/fichefilm/{id}", name: "videotheque_voirfilm")]
 	public function voirFilmAction(Request $request, \App\Entity\Film $film, CommentaireManager $cm, Security $security, CommentaireRepository $repo): Response
     {

+ 0 - 50
src/Controller/VideothequePersonnelleController.php

@@ -1,50 +0,0 @@
-<?php
-
-namespace App\Controller;
-
-use App\Repository\FilmRepository;
-use App\Service\FilmManager;
-use App\Service\OptionsManager;
-use Doctrine\ORM\EntityManagerInterface;
-use Symfony\Component\HttpFoundation\JsonResponse;
-use Symfony\Component\Routing\Annotation\Route;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-
-class VideothequePersonnelleController extends FilmAbstractController
-{
-	#[Route("/maliste", name:"videothequepersonnelle_maliste")]
-	public function maListeAction (Request $request, OptionsManager $options, FilmRepository $filmRepository): Response
-    {
-        $filtersForm = $this->formPagination($request);
-        $listeFilms = $filmRepository->findTousFavoritesByUser($this->getUser(), $filtersForm->getData()->toArray());
-        return $this->render('videotheque/liste_'.$options->vue().'.html.twig', array(
-            'listeFilms'    =>  $listeFilms,
-            'titre'         =>  'Ma liste de films à voir',
-            'filtersForm'   => $filtersForm->createView()
-        ));
-    }
-
-    #[Route("/maliste/modifieravoir", name:"maliste_modifier_a_voir", methods: ['PATCH'])]
-    public function modifierFilmDansListeAction(Request $request, EntityManagerInterface $em, FilmRepository $repo, FilmManager $filmManager): Response
-    {
-        $result = null;
-        $film = $repo->find($request->toArray()['id_film']);
-        $result = $filmManager->inverseUserWantToView($film);
-        $em->flush();
-        /*$resultat = $this->get('serializer')->serialize($film, 'json');*/
-        return new JsonResponse((object)['newState' => $result]);
-    }
-
-    #[Route("/maliste/modifiervus", name:"maliste_modifier_vus", methods: ['PATCH'])]
-    public function modifierFilmVusAction(Request $request, FilmRepository $repo, EntityManagerInterface $em, FilmManager $filmManager): Response
-    {
-        $result = null;
-
-        $film = $repo->find($request->toArray()['id_film']);
-        $result = $filmManager->inverseUserWhoSeen($film);
-        $em->flush();
-        return new JsonResponse((object)['newState' => $result]);
-    }
-
-}