123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Service;
- use App\Repository\GenreRepository;
- use App\Repository\RealisateurRepository;
- use Doctrine\ORM\EntityManagerInterface;
- use App\Entity\Film;
- /**
- * Faire des recherches de films
- */
- class UniciteCollections
- {
- protected $repoReal;
- protected $repoGenre;
- /**
- * Search constructor.
- * @param EntityManagerInterface $em
- */
- public function __construct(RealisateurRepository $repoReal, GenreRepository $repoGenre)
- {
- $this->repoGenre = $repoGenre;
- $this->repoReal = $repoReal;
- }
- /**
- * @param \App\Entity\Film $film
- * @return \App\Entity\Film
- */
- public function assureUniciteCollections(Film $film)
- {
- $film = $this->checkRealisateurs($film);
- $film = $this->checkGenres($film);
- return $film;
- }
- /**
- * @param \App\Entity\Film $film
- * @return \App\Entity\Film
- */
- protected function checkRealisateurs(Film $film, )
- {
- $realisateurs = $film->getRealisateurs();
- foreach ($realisateurs as $realisateur)
- {
- if ($realisateur->getId() == null)
- {
- $recherche = $this->repoReal->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(Film $film)
- {
- $genres = $film->getGenres();
- foreach ($genres as $genre)
- {
- if ($genre->getId() == null)
- {
- $recherche = $this->repoGenre->findOneBy(array('name'=>$genre->getName()));
- if ($recherche != null)
- {
- $film->removeGenre($genre);
- $film->addGenre($recherche);
- }
- }
- }
- return $film;
- }
- }
|