123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace App\Repository;
- use App\Entity\Film;
- use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
- use Doctrine\Common\Persistence\ManagerRegistry;
- /**
- * @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 ServiceEntityRepository
- {
- public function __construct(ManagerRegistry $registry)
- {
- parent::__construct($registry, Film::class);
- }
- public function findFilm($id) {
- $qb = $this->createQueryBuilder('f');
- $query = $qb
- ->select('f.titre', 'f.annee')
- ->where('f.id = :id')
- ->setParameter('id', $id)
- ->getQuery();
- return $query->getSingleResult();
- }
- public function findFilmWithGenre(array $genreNames) {
- $qb = $this->createQueryBuilder('f');
- $qb
- ->innerJoin('f.genres', 'g')
- ->addSelect('f');
- $qb->where($qb->expr()->in('g.name', $genreNames));
- return $qb
- ->getQuery()
- ->getResult();
- }
- public function findFilmWithReal(array $realisateursnames) {
- $qb = $this->createQueryBuilder('f');
- $qb
- ->leftJoin('f.realisateurs', 'rea')
- ->addSelect('f')
- ->where($qb->expr()->in('rea.nomComplet', $realisateursnames));
- return $qb
- ->getQuery()
- ->getResult();
- }
- public function findFilmWithRealLike($query)
- {
- $qb = $this->createQueryBuilder('f');
- $qb
- ->innerJoin('f.realisateurs', 'r')
- ->addSelect('f');
- $qb
- ->where($qb->expr()->like('r.nomComplet', ':nomComplet'))
- ->setParameter('nomComplet', '%'.$query.'%');
- return $qb->getQuery()->getResult();
- }
- public function findFilmWithGenreLike($genreName) {
- $qb = $this->createQueryBuilder('f');
- $qb
- ->innerJoin('f.genres', 'g')
- ->addSelect('f');
- $qb->where($qb->expr()->like('g.name', ':genreName'))
- ->setParameter('genreName', '%'.$genreName.'%');
- return $qb
- ->getQuery()
- ->getResult();
- }
- public function findTousDesc() {
- $qb = $this->createQueryBuilder('f');
- $qb
- ->select('f')
- ->orderBy('f.dateSubmited', 'DESC');
- return $qb
- ->getQuery()
- ->getResult();
- }
- public function findTous () {
- $qb = $this->createQueryBuilder('f')
- ->leftJoin('f.authered', 'aut')->addSelect('aut')
- ->leftJoin('f.genres', 'gen')->addSelect('gen')
- ->leftJoin('f.realisateurs', 'rea')->addSelect('rea')
- ->orderBy('f.dateSubmited', 'DESC');
- return $qb
- ->getQuery()
- ->getResult();
- }
- public function findTousFavoritesByUser($user)
- {
- $qb = $this->createQueryBuilder('f');
- $qb
- ->leftJoin('f.authered', 'aut')->addSelect('aut')
- ->leftJoin('f.genres', 'gen')->addSelect('gen')
- ->leftJoin('f.realisateurs', 'rea')->addSelect('rea')
- ->leftJoin('f.usersWantToView', 'wan')
- ->where($qb->expr()->in('wan', ':user'))
- ->setParameter('user', $user)
- ->orderBy('f.dateSubmited', 'DESC');
- return $qb
- ->getQuery()
- ->getResult();
- }
- }
|