12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Service;
- use Doctrine\ORM\EntityManagerInterface;
- /**
- * Faire des recherches de films
- */
- class UniciteCollections
- {
- protected $em;
- /**
- * Search constructor.
- * @param EntityManagerInterface $em
- */
- public function __construct(EntityManagerInterface $em)
- {
- $this->em = $em;
- }
- /**
- * @param \App\Entity\Film $film
- * @return \App\Entity\Film
- */
- public function assureUniciteCollections(\App\Entity\Film $film)
- {
- $film = $this->checkRealisateurs($film);
- $film = $this->checkGenres($film);
- return $film;
- }
- /**
- * @param \App\Entity\Film $film
- * @return \App\Entity\Film
- */
- protected function checkRealisateurs(\App\Entity\Film $film)
- {
- $realisateurs = $film->getRealisateurs();
- foreach ($realisateurs as $realisateur)
- {
- if ($realisateur->getId() == null)
- {
- $recherche = $this->em->getRepository('App:Realisateur')->findOneBy(array('nomComplet'=>$realisateur->getNomComplet()));
- if ($recherche != null)
- {
- $film->removeRealisateur($realisateur);
- $film->addRealisateur($recherche);
- }
- }
- }
- return $film;
- }
- /**
- * @param \App\Entity\Film $film
- * @return \App\Entity\Film
- */
- protected function checkGenres(\App\Entity\Film $film)
- {
- $genres = $film->getGenres();
- foreach ($genres as $genre)
- {
- if ($genre->getId() == null)
- {
- $recherche = $this->em->getRepository('App:Genre')->findOneBy(array('name'=>$genre->getName()));
- if ($recherche != null)
- {
- $film->removeGenre($genre);
- $film->addGenre($recherche);
- }
- }
- }
- return $film;
- }
- }
|