123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Service;
- use Doctrine\ORM\EntityManagerInterface;
- use App\Repository\FilmRepository;
- /**
- * Faire des recherches de films
- */
- class Search
- {
- protected $em;
- protected $repoFilm;
- /**
- * Search constructor.
- * @param EntityManagerInterface $em
- */
- public function __construct(EntityManagerInterface $em, FilmRepository $repoFilm)
- {
- $this->em = $em;
- $this->repoFilm = $repoFilm;
- }
- /**
- * @param string $query
- * @return \App\Entity\Film[]
- */
- public function search($query)
- {
- return \array_merge(
- $this->searchByFilm($query),
- $this->searchByRealisateur($query),
- $this->searchByGenre($query)
- );
- }
- /**
- * @param $query
- * @return array
- */
- protected function searchByFilm($query)
- {
- $q = $this->em
- ->createQuery('SELECT f from App:Film f WHERE f.titre like :titre')
- ->setParameter('titre', '%'.$query.'%')
- ->getResult();
- return $q;
- }
- /**
- * @param $query
- * @return array
- */
- protected function searchByRealisateur($query)
- {
- return $this->repoFilm->findFilmWithRealLike($query);
- }
- /**
- * @param $query
- * @return array
- */
- protected function searchByGenre($query)
- {
- return $this->repoFilm->findFilmWithGenreLike($query);
- }
- }
|