|
@@ -10,31 +10,25 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
|
|
|
|
class TmdbApiService
|
|
class TmdbApiService
|
|
|
{
|
|
{
|
|
|
- protected string $content = '';
|
|
|
|
|
|
|
+ protected string $content = "";
|
|
|
protected int $nbResults = 0;
|
|
protected int $nbResults = 0;
|
|
|
protected int $nbPages = 0;
|
|
protected int $nbPages = 0;
|
|
|
protected array $films = [];
|
|
protected array $films = [];
|
|
|
|
|
|
|
|
public function __construct(
|
|
public function __construct(
|
|
|
protected HttpClientInterface $tmdbClient,
|
|
protected HttpClientInterface $tmdbClient,
|
|
|
- protected UniciteCollections $uc
|
|
|
|
|
- )
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ protected UniciteCollections $uc,
|
|
|
|
|
+ ) {}
|
|
|
|
|
|
|
|
public function query(string $titre, int $page = 1): bool
|
|
public function query(string $titre, int $page = 1): bool
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
- $response = $this->tmdbClient->request(
|
|
|
|
|
- 'GET',
|
|
|
|
|
- 'search/movie',[
|
|
|
|
|
- 'query' => [
|
|
|
|
|
- 'query' => $titre,
|
|
|
|
|
- 'page' => $page
|
|
|
|
|
- ]
|
|
|
|
|
- ]
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ $response = $this->tmdbClient->request("GET", "search/movie", [
|
|
|
|
|
+ "query" => [
|
|
|
|
|
+ "query" => $titre,
|
|
|
|
|
+ "page" => $page,
|
|
|
|
|
+ ],
|
|
|
|
|
+ ]);
|
|
|
|
|
|
|
|
$this->content = $response->getContent();
|
|
$this->content = $response->getContent();
|
|
|
$this->jsonDecode();
|
|
$this->jsonDecode();
|
|
@@ -48,16 +42,12 @@ class TmdbApiService
|
|
|
{
|
|
{
|
|
|
$detail = null;
|
|
$detail = null;
|
|
|
try {
|
|
try {
|
|
|
- $response = $this->tmdbClient->request(
|
|
|
|
|
- 'GET',
|
|
|
|
|
- 'movie/'. $id ,[
|
|
|
|
|
- 'query' => [
|
|
|
|
|
- 'append_to_response' => 'credits,videos',
|
|
|
|
|
- ]
|
|
|
|
|
- ]
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ $response = $this->tmdbClient->request("GET", "movie/" . $id, [
|
|
|
|
|
+ "query" => [
|
|
|
|
|
+ "append_to_response" => "credits,videos",
|
|
|
|
|
+ ],
|
|
|
|
|
+ ]);
|
|
|
$detail = $response->getContent();
|
|
$detail = $response->getContent();
|
|
|
-
|
|
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -87,40 +77,33 @@ class TmdbApiService
|
|
|
$this->nbPages = $json->total_pages;
|
|
$this->nbPages = $json->total_pages;
|
|
|
$entrees = $json->results;
|
|
$entrees = $json->results;
|
|
|
|
|
|
|
|
- foreach($entrees as $entree) {
|
|
|
|
|
|
|
+ foreach ($entrees as $entree) {
|
|
|
$film = $this->hydrateFilm($entree->id);
|
|
$film = $this->hydrateFilm($entree->id);
|
|
|
|
|
|
|
|
- $this->films[$entree->id]['data'] = $film;
|
|
|
|
|
|
|
+ $this->films[$entree->id]["data"] = $film;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function hydrateFilm($filmTmdbId): Film
|
|
|
|
|
|
|
+ public function hydrateFilm(int $filmTmdbId): Film
|
|
|
{
|
|
{
|
|
|
$filmTmdb = json_decode($this->getDetailMovie($filmTmdbId));
|
|
$filmTmdb = json_decode($this->getDetailMovie($filmTmdbId));
|
|
|
|
|
+ dump($filmTmdb);
|
|
|
$film = new Film();
|
|
$film = new Film();
|
|
|
- $film
|
|
|
|
|
- ->setTitre($filmTmdb->title)
|
|
|
|
|
- ->setInformation($filmTmdb->overview);
|
|
|
|
|
|
|
+ $film->setTitre($filmTmdb->title)->setInformation($filmTmdb->overview);
|
|
|
|
|
|
|
|
- if (preg_match ("/^\d{4}-\d{2}-\d{2}$/", $filmTmdb->release_date))
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (preg_match("/^\d{4}-\d{2}-\d{2}$/", $filmTmdb->release_date)) {
|
|
|
$dateSortie = $filmTmdb->release_date;
|
|
$dateSortie = $filmTmdb->release_date;
|
|
|
- $annee = substr($dateSortie, 0, 4) . '-01-01';
|
|
|
|
|
|
|
+ $annee = substr($dateSortie, 0, 4) . "-01-01";
|
|
|
$film
|
|
$film
|
|
|
->setDateSortie(new \DateTimeImmutable($dateSortie))
|
|
->setDateSortie(new \DateTimeImmutable($dateSortie))
|
|
|
- ->setAnnee(new \DateTimeImmutable($annee))
|
|
|
|
|
- ;
|
|
|
|
|
-
|
|
|
|
|
- } elseif (preg_match("/^\d{4}/", $filmTmdb->release_date)) {
|
|
|
|
|
- $annee = substr($filmTmdb->release_date, 0, 4) . '-01-01';
|
|
|
|
|
- $film
|
|
|
|
|
->setAnnee(new \DateTimeImmutable($annee));
|
|
->setAnnee(new \DateTimeImmutable($annee));
|
|
|
- ;
|
|
|
|
|
|
|
+ } elseif (preg_match("/^\d{4}/", $filmTmdb->release_date)) {
|
|
|
|
|
+ $annee = substr($filmTmdb->release_date, 0, 4) . "-01-01";
|
|
|
|
|
+ $film->setAnnee(new \DateTimeImmutable($annee));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ;
|
|
|
|
|
foreach ($filmTmdb->genres as $genre) {
|
|
foreach ($filmTmdb->genres as $genre) {
|
|
|
- $film->addGenre((new Genre())->setName($genre->name));
|
|
|
|
|
|
|
+ $film->addGenre(new Genre()->setName($genre->name));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->getRealisateurs($filmTmdb) as $realisateur) {
|
|
foreach ($this->getRealisateurs($filmTmdb) as $realisateur) {
|
|
@@ -130,7 +113,7 @@ class TmdbApiService
|
|
|
$videoTmdb = $this->getOneVideo($filmTmdb);
|
|
$videoTmdb = $this->getOneVideo($filmTmdb);
|
|
|
if (!empty($videoTmdb)) {
|
|
if (!empty($videoTmdb)) {
|
|
|
$video = new MediaVideo();
|
|
$video = new MediaVideo();
|
|
|
- $video->setFromTmdb($videoTmdb['type'], $videoTmdb['identif']);
|
|
|
|
|
|
|
+ $video->setFromTmdb($videoTmdb["type"], $videoTmdb["identif"]);
|
|
|
$film->addMediaVideo($video);
|
|
$film->addMediaVideo($video);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -138,11 +121,15 @@ class TmdbApiService
|
|
|
return $film;
|
|
return $film;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function getRealisateurs($detailMovie): array
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param array<string, mixed> $detailMovie
|
|
|
|
|
+ * @return array<int, Realisateur>
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getRealisateurs(array $detailMovie): array
|
|
|
{
|
|
{
|
|
|
- $directors = array();
|
|
|
|
|
- foreach($detailMovie->credits->crew as $crew) {
|
|
|
|
|
- if ($crew->job === 'Director') {
|
|
|
|
|
|
|
+ $directors = [];
|
|
|
|
|
+ foreach ($detailMovie->credits->crew as $crew) {
|
|
|
|
|
+ if ($crew->job === "Director") {
|
|
|
$realisateur = new Realisateur();
|
|
$realisateur = new Realisateur();
|
|
|
$realisateur->setNomComplet($crew->name);
|
|
$realisateur->setNomComplet($crew->name);
|
|
|
$directors[] = $realisateur;
|
|
$directors[] = $realisateur;
|
|
@@ -151,21 +138,27 @@ class TmdbApiService
|
|
|
return $directors;
|
|
return $directors;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function getOneVideo($detailMovie): array
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param array<string, mixed> $detailMovie
|
|
|
|
|
+ * @return array<string, string>
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getOneVideo(array $detailMovie): array
|
|
|
{
|
|
{
|
|
|
- foreach($detailMovie->videos->results as $video) {
|
|
|
|
|
|
|
+ foreach ($detailMovie->videos->results as $video) {
|
|
|
if (
|
|
if (
|
|
|
- ($video->site === "YouTube" || $video->site === "Vimeo" || $video->site === "DailyMotion") &&
|
|
|
|
|
|
|
+ ($video->site === "YouTube" ||
|
|
|
|
|
+ $video->site === "Vimeo" ||
|
|
|
|
|
+ $video->site === "DailyMotion") &&
|
|
|
$video->type === "Trailer" &&
|
|
$video->type === "Trailer" &&
|
|
|
- $video->iso_639_1 === "fr" && $video->iso_3166_1 === "FR"
|
|
|
|
|
|
|
+ $video->iso_639_1 === "fr" &&
|
|
|
|
|
+ $video->iso_3166_1 === "FR"
|
|
|
) {
|
|
) {
|
|
|
return [
|
|
return [
|
|
|
- 'type' => strtolower($video->site),
|
|
|
|
|
- 'identif' => $video->key
|
|
|
|
|
|
|
+ "type" => strtolower($video->site),
|
|
|
|
|
+ "identif" => $video->key,
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|