|
|
@@ -210,6 +210,11 @@ class FilmRepository extends ServiceEntityRepository
|
|
|
->getResult();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Films déjà en base correspondant au film TMDb (mêmes réalisateurs et titre proche).
|
|
|
+ * Le titre est comparé de façon tolérante : TMDb renomme parfois ses films
|
|
|
+ * (ponctuation, sous-titre) et l'égalité stricte raterait alors le doublon.
|
|
|
+ */
|
|
|
public function findFilmInImdb(Film $film): array
|
|
|
{
|
|
|
$reals = [];
|
|
|
@@ -217,14 +222,33 @@ class FilmRepository extends ServiceEntityRepository
|
|
|
$reals[] = $real->getNomComplet();
|
|
|
}
|
|
|
$qb = $this->createQueryBuilder("f");
|
|
|
- $qb->andWhere("f.titre = :titre")
|
|
|
- ->setParameter("titre", $film->getTitre())
|
|
|
+ $qb->andWhere("f.titre LIKE :titrePattern")
|
|
|
+ ->setParameter("titrePattern", $this->titrePattern($film->getTitre()))
|
|
|
->innerJoin("f.realisateurs", "rea")
|
|
|
->andWhere($qb->expr()->in("rea.nomComplet", ":reals"))
|
|
|
->setParameter("reals", $reals);
|
|
|
return $qb->getQuery()->getResult();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Transforme un titre en motif LIKE : minuscules, accents réduits à l'ASCII
|
|
|
+ * et toute suite de non-alphanumériques remplacée par %.
|
|
|
+ * "Kaamelott - Premier volet" -> "%kaamelott%premier%volet%"
|
|
|
+ */
|
|
|
+ private function titrePattern(?string $titre): string
|
|
|
+ {
|
|
|
+ $normalise = mb_strtolower(trim((string) $titre));
|
|
|
+ $ascii = @iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $normalise);
|
|
|
+ if (is_string($ascii) && $ascii !== "") {
|
|
|
+ $normalise = $ascii;
|
|
|
+ }
|
|
|
+ $motif = (string) preg_replace("/[^a-z0-9]+/", "%", $normalise);
|
|
|
+ if (trim($motif, "%") === "") {
|
|
|
+ return (string) $titre;
|
|
|
+ }
|
|
|
+ return "%" . trim($motif, "%") . "%";
|
|
|
+ }
|
|
|
+
|
|
|
public function findRandom(int $nb = 5): array
|
|
|
{
|
|
|
$films = $this->createQueryBuilder("f")
|