|
@@ -0,0 +1,72 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace AppBundle\Service;
|
|
|
+
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Faire des recherches de films
|
|
|
+ */
|
|
|
+class Search
|
|
|
+{
|
|
|
+ protected $em;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Search constructor.
|
|
|
+ * @param EntityManagerInterface $em
|
|
|
+ */
|
|
|
+ public function __construct(EntityManagerInterface $em)
|
|
|
+ {
|
|
|
+ $this->em = $em;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $query
|
|
|
+ * @return \AppBundle\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 AppBundle:Film f WHERE f.titre like :titre')
|
|
|
+ ->setParameter('titre', '%'.$query.'%')
|
|
|
+ ->getResult();
|
|
|
+ ;
|
|
|
+ return $q;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $query
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function searchByRealisateur($query)
|
|
|
+ {
|
|
|
+ $q = $this->em->getRepository('AppBundle:Film');
|
|
|
+ return $q->findFilmWithRealLike($query);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $query
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ protected function searchByGenre($query)
|
|
|
+ {
|
|
|
+ $q = $this->em->getRepository('AppBundle:Film');
|
|
|
+ return $q->findFilmWithGenreLike($query);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|