浏览代码

Mise à jour des repository

François 5 年之前
父节点
当前提交
ef62bd05fe

+ 5 - 4
src/Controller/GenreController.php

@@ -4,6 +4,8 @@ namespace App\Controller;
 
 use App\Entity\Genre;
 use App\Form\GenreType;
+use App\Repository\FilmRepository;
+use App\Repository\GenreRepository;
 use App\Service\GenreManager;
 use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -15,8 +17,7 @@ class GenreController extends AbstractController
     /**
      * @Route("/genre", name="genre_liste")
      */
-    public function indexAction(EntityManagerInterface $em) {
-        $repo = $em->getRepository('App:Genre');
+    public function indexAction(GenreRepository $repo) {
         $genres = $repo->findAll();
 
         return $this->render('genre/liste.html.twig', array(
@@ -49,11 +50,11 @@ class GenreController extends AbstractController
 	/**
 	 * @Route("/genre/modifier/{id}", name="genre_modifier")
 	 */
-	public function modifierAction(Request $request, Genre $genre, EntityManagerInterface $em, GenreManager $genreManager)
+	public function modifierAction(Request $request, Genre $genre, FilmRepository $repo, GenreManager $genreManager)
 	{
 		$form = $this->createForm(GenreType::class, $genre);
 		$form->handleRequest($request);
-        $films = $em->getRepository('App:Film')->findFilmWithGenre(array($genre->getName()));
+        $films = $repo->findFilmWithGenre(array($genre->getName()));
 
 		if ($form->isSubmitted() && $form->isValid())
 		{

+ 2 - 2
src/Controller/RealisateurController.php

@@ -4,6 +4,7 @@ namespace App\Controller;
 
 use App\Entity\Realisateur;
 use App\Form\RealisateurType;
+use App\Repository\RealisateurRepository;
 use App\Service\RealisateurManager;
 use Doctrine\ORM\EntityManagerInterface;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
@@ -16,8 +17,7 @@ class RealisateurController extends AbstractController
     /**
      * @Route("/real/", name="realisateur_liste")
      */
-    public function indexAction(EntityManagerInterface $em) {
-        $repo = $em->getRepository('App:Realisateur');
+    public function indexAction(RealisateurRepository $repo) {
         $realisateurs = $repo->findAll();
 
         return $this->render('realisateur/liste.html.twig', array(

+ 15 - 18
src/Controller/VideothequeController.php

@@ -11,21 +11,22 @@ 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 Doctrine\ORM\EntityManagerInterface;
 
 class VideothequeController extends AbstractController
 {
 	/**
 	 * @Route("/", name="videotheque_liste")
 	 */
-	public function listeAction(Request $request, EntityManagerInterface $em)
+	public function listeAction(Request $request, FilmRepository $repo)
 	{
-		$repo = $em->getRepository(Film::class);
         $listeFilms = $repo->findTous();
 
 		return $this->render('videotheque/liste.html.twig', array(
@@ -37,9 +38,9 @@ class VideothequeController extends AbstractController
     /**
      * @Route("/liste-by/{id}", name="videotheque_listepargenre")
      */
-	public function  listeParGenreAction(\App\Entity\Genre $genre, EntityManagerInterface $em)
+	public function  listeParGenreAction(\App\Entity\Genre $genre, FilmRepository $repo)
     {
-        $films = $em->getRepository(Film::class)->findFilmWithGenre(array($genre->getName()));
+        $films = $repo->findFilmWithGenre(array($genre->getName()));
 
         return $this->render('videotheque/liste.html.twig', array(
             'listeFilms'    => $films,
@@ -50,9 +51,9 @@ class VideothequeController extends AbstractController
     /**
      * @Route("/liste-by_real/{id}", name="videotheque_listeparreal")
      */
-    public function  listeParRealisateurAction(Realisateur $realisateur, EntityManagerInterface $em)
+    public function  listeParRealisateurAction(Realisateur $realisateur, FilmRepository $repo)
     {
-        $films = $em->getRepository(Film::class)->findFilmWithReal(array($realisateur->getNomComplet()));
+        $films = $repo->findFilmWithReal(array($realisateur->getNomComplet()));
 
         return $this->render('videotheque/liste.html.twig', array(
             'listeFilms'    => $films,
@@ -124,11 +125,11 @@ class VideothequeController extends AbstractController
 	/**
      * @Route("/fichefilm/{id}", name="videotheque_voirfilm")
      */
-	public function voirFilmAction(Request $request, \App\Entity\Film $film, CommentaireManager $cm, Security $security, EntityManagerInterface $em)
+	public function voirFilmAction(Request $request, \App\Entity\Film $film, CommentaireManager $cm, Security $security, CommentaireRepository $repo)
     {
         if ($security->isGranted('IS_AUTHENTICATED_REMEMBERED'))
         {
-            $commentaireUser = $em->getRepository(Commentaire::class)->findOneBy(array('film'=>$film, 'user'=>$this->getUser()));
+            $commentaireUser = $repo->findOneBy(array('film'=>$film, 'user'=>$this->getUser()));
             if (is_null($commentaireUser))
             {
                 $commentaireUser = new Commentaire();
@@ -154,11 +155,9 @@ class VideothequeController extends AbstractController
     /**
      * @Route("/ajax_req_realisateurs", name="videotheque_ajax_realisateurs")
      */
-    public function ajaxRealisateurs(Request $request, EntityManagerInterface $em)
+    public function ajaxRealisateurs(Request $request, RealisateurRepository $repo)
     {
-        $realisateurs = $em
-            ->getRepository(Realisateur::class)
-            ->findNomsComplets();
+        $realisateurs = $repo->findNomsComplets();
         $liste = array();
         foreach ($realisateurs as $key=>$nom)
         {
@@ -171,11 +170,9 @@ class VideothequeController extends AbstractController
     /**
      * @Route("/ajax_req_genres", name="videotheque_ajax_genres")
      */
-    public function ajaxGenres(Request $request, EntityManagerInterface $em)
+    public function ajaxGenres(Request $request, GenreRepository $repo)
     {
-        $genres = $em
-            ->getRepository(Genre::class)
-            ->findGenres();
+        $genres = $repo->findGenres();
         $liste = array();
         foreach ($genres as $key=>$nom)
         {

+ 5 - 8
src/Controller/VideothequePersonnelleController.php

@@ -2,6 +2,7 @@
 
 namespace App\Controller;
 
+use App\Repository\FilmRepository;
 use Doctrine\ORM\EntityManagerInterface;
 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
 use Symfony\Component\HttpFoundation\JsonResponse;
@@ -13,11 +14,9 @@ class VideothequePersonnelleController extends AbstractController
 	/**
      * @Route("/maliste/", name="videothequepersonnelle_maliste")
      */
-	public function maListeAction (Request $request, EntityManagerInterface $em)
+	public function maListeAction (Request $request, FilmRepository $repo)
     {
-        $films = $em
-            ->getRepository('App:Film')
-            ->findTousFavoritesByUser($this->getUser());
+        $films = $repo->findTousFavoritesByUser($this->getUser());
 
         return $this->render('videotheque/liste.html.twig', array(
             'listeFilms'    =>  $films,
@@ -41,9 +40,8 @@ class VideothequePersonnelleController extends AbstractController
      * @param Request $request
      * @return JsonResponse
      */
-    public function modifierFilmDansListeAction(Request $request, EntityManagerInterface $em)
+    public function modifierFilmDansListeAction(Request $request, EntityManagerInterface $em, FilmRepository $repo)
     {
-        $repo = $em->getRepository('App:Film');
         $film = $repo->find($request->request->get('id_film'));
         if ($request->isXmlHttpRequest())
         {
@@ -59,9 +57,8 @@ class VideothequePersonnelleController extends AbstractController
      * @param Request $request
      * @return JsonResponse
      */
-    public function modifierFilmVusAction(Request $request, EntityManagerInterface $em)
+    public function modifierFilmVusAction(Request $request, FilmRepository $repo, EntityManagerInterface $em)
     {
-        $repo = $em->getRepository('App:Film');
         $film = $repo->find($request->request->get('id_film'));
         if ($request->isXmlHttpRequest())
         {

+ 14 - 5
src/Repository/CommentaireRepository.php

@@ -2,14 +2,23 @@
 
 namespace App\Repository;
 
+use App\Entity\Commentaire;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Common\Persistence\ManagerRegistry;
+
 /**
- * CommentaireRepository
- *
- * This class was generated by the Doctrine ORM. Add your own custom
- * repository methods below.
+ * @method Commentaire|null find($id, $lockMode = null, $lockVersion = null)
+ * @method Commentaire|null findOneBy(array $criteria, array $orderBy = null)
+ * @method Commentaire[]    findAll()
+ * @method Commentaire[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  */
-class CommentaireRepository extends \Doctrine\ORM\EntityRepository
+class CommentaireRepository extends ServiceEntityRepository
 {
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, Commentaire::class);
+    }
+
     public function findLast ($limit = 5)
     {
         return $qb = $this->createQueryBuilder('c')

+ 15 - 5
src/Repository/FilmRepository.php

@@ -2,14 +2,24 @@
 
 namespace App\Repository;
 
+use App\Entity\Film;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Common\Persistence\ManagerRegistry;
+
 /**
- * FilmRepository
- *
- * This class was generated by the Doctrine ORM. Add your own custom
- * repository methods below.
+ * @method Film|null find($id, $lockMode = null, $lockVersion = null)
+ * @method Film|null findOneBy(array $criteria, array $orderBy = null)
+ * @method Film[]    findAll()
+ * @method Film[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  */
-class FilmRepository extends \Doctrine\ORM\EntityRepository
+
+class FilmRepository extends ServiceEntityRepository
 {
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, Film::class);
+    }
+
     public function findFilm($id) {
         $qb = $this->createQueryBuilder('f');
         $query = $qb

+ 14 - 1
src/Repository/GenreRepository.php

@@ -3,6 +3,15 @@
 namespace App\Repository;
 
 use App\Entity\Genre;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Common\Persistence\ManagerRegistry;
+
+/**
+ * @method Genre|null find($id, $lockMode = null, $lockVersion = null)
+ * @method Genre|null findOneBy(array $criteria, array $orderBy = null)
+ * @method Genre[]    findAll()
+ * @method Genre[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ */
 
 /**
  * GenreRepository
@@ -10,8 +19,12 @@ use App\Entity\Genre;
  * This class was generated by the Doctrine ORM. Add your own custom
  * repository methods below.
  */
-class GenreRepository extends \Doctrine\ORM\EntityRepository
+class GenreRepository extends ServiceEntityRepository
 {
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, Genre::class);   
+    }
     public function findGenres ()
     {
         $qb = $this->createQueryBuilder('g');

+ 14 - 5
src/Repository/RealisateurRepository.php

@@ -2,14 +2,23 @@
 
 namespace App\Repository;
 
+use App\Entity\Realisateur;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Common\Persistence\ManagerRegistry;
+
 /**
- * RealisateurRepository
- *
- * This class was generated by the Doctrine ORM. Add your own custom
- * repository methods below.
+ * @method Realisateur|null find($id, $lockMode = null, $lockVersion = null)
+ * @method Realisateur|null findOneBy(array $criteria, array $orderBy = null)
+ * @method Realisateur[]    findAll()
+ * @method Realisateur[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  */
-class RealisateurRepository extends \Doctrine\ORM\EntityRepository
+
+class RealisateurRepository extends ServiceEntityRepository
 {
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, Realisateur::class);  
+    }
     public function findByNom($nom)
     {
         $qb = $this->createQueryBuilder ('r');