FilmRepository.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Film;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Common\Persistence\ManagerRegistry;
  6. /**
  7. * @method Film|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method Film|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method Film[] findAll()
  10. * @method Film[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11. */
  12. class FilmRepository extends ServiceEntityRepository
  13. {
  14. public function __construct(ManagerRegistry $registry)
  15. {
  16. parent::__construct($registry, Film::class);
  17. }
  18. public function findFilm($id) {
  19. $qb = $this->createQueryBuilder('f');
  20. $query = $qb
  21. ->select('f.titre', 'f.annee')
  22. ->where('f.id = :id')
  23. ->setParameter('id', $id)
  24. ->getQuery();
  25. return $query->getSingleResult();
  26. }
  27. public function findFilmWithGenre(array $genreNames) {
  28. $qb = $this->createQueryBuilder('f');
  29. $qb
  30. ->innerJoin('f.genres', 'g')
  31. ->addSelect('f');
  32. $qb->where($qb->expr()->in('g.name', $genreNames));
  33. return $qb
  34. ->getQuery()
  35. ->getResult();
  36. }
  37. public function findFilmWithReal(array $realisateursnames) {
  38. $qb = $this->createQueryBuilder('f');
  39. $qb
  40. ->leftJoin('f.realisateurs', 'rea')
  41. ->addSelect('f')
  42. ->where($qb->expr()->in('rea.nomComplet', $realisateursnames));
  43. return $qb
  44. ->getQuery()
  45. ->getResult();
  46. }
  47. public function findFilmWithRealLike($query)
  48. {
  49. $qb = $this->createQueryBuilder('f');
  50. $qb
  51. ->innerJoin('f.realisateurs', 'r')
  52. ->addSelect('f');
  53. $qb
  54. ->where($qb->expr()->like('r.nomComplet', ':nomComplet'))
  55. ->setParameter('nomComplet', '%'.$query.'%');
  56. return $qb->getQuery()->getResult();
  57. }
  58. public function findFilmWithGenreLike($genreName) {
  59. $qb = $this->createQueryBuilder('f');
  60. $qb
  61. ->innerJoin('f.genres', 'g')
  62. ->addSelect('f');
  63. $qb->where($qb->expr()->like('g.name', ':genreName'))
  64. ->setParameter('genreName', '%'.$genreName.'%');
  65. return $qb
  66. ->getQuery()
  67. ->getResult();
  68. }
  69. public function findTousDesc() {
  70. $qb = $this->createQueryBuilder('f');
  71. $qb
  72. ->select('f')
  73. ->orderBy('f.dateSubmited', 'DESC');
  74. return $qb
  75. ->getQuery()
  76. ->getResult();
  77. }
  78. public function findTous () {
  79. $qb = $this->createQueryBuilder('f')
  80. ->leftJoin('f.authered', 'aut')->addSelect('aut')
  81. ->leftJoin('f.genres', 'gen')->addSelect('gen')
  82. ->leftJoin('f.realisateurs', 'rea')->addSelect('rea')
  83. ->orderBy('f.dateSubmited', 'DESC');
  84. return $qb
  85. ->getQuery()
  86. ->getResult();
  87. }
  88. public function findTousFavoritesByUser($user)
  89. {
  90. $qb = $this->createQueryBuilder('f');
  91. $qb
  92. ->leftJoin('f.authered', 'aut')->addSelect('aut')
  93. ->leftJoin('f.genres', 'gen')->addSelect('gen')
  94. ->leftJoin('f.realisateurs', 'rea')->addSelect('rea')
  95. ->leftJoin('f.usersWantToView', 'wan')
  96. ->where($qb->expr()->in('wan', ':user'))
  97. ->setParameter('user', $user)
  98. ->orderBy('f.dateSubmited', 'DESC');
  99. return $qb
  100. ->getQuery()
  101. ->getResult();
  102. }
  103. }