Skip to content

Commit 6cfe166

Browse files
committed
Add movie external_ids
1 parent 0335d97 commit 6cfe166

5 files changed

Lines changed: 66 additions & 0 deletions

File tree

lib/Tmdb/Api/Movies.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,17 @@ public function getVideos($movie_id, array $parameters = [], array $headers = []
295295
{
296296
return $this->get('movie/' . $movie_id . '/videos', $parameters, $headers);
297297
}
298+
299+
/**
300+
* Get the external ids that we have stored for a movie.
301+
*
302+
* @param $movie_id
303+
* @param array $parameters
304+
* @param array $headers
305+
* @return mixed
306+
*/
307+
public function getExternalIds($movie_id, array $parameters = [], array $headers = [])
308+
{
309+
return $this->get('movie/' . $movie_id . '/external_ids', $parameters, $headers);
310+
}
298311
}

lib/Tmdb/Factory/MovieFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Tmdb\HttpClient\HttpClient;
2323
use Tmdb\Model\AbstractModel;
2424
use Tmdb\Model\Common\Country;
25+
use Tmdb\Model\Common\ExternalIds;
2526
use Tmdb\Model\Common\GenericCollection;
2627
use Tmdb\Model\Common\SpokenLanguage;
2728
use Tmdb\Model\Common\Translation;
@@ -146,6 +147,13 @@ public function create(array $data = []): ?AbstractModel
146147
}
147148
}
148149

150+
/** External ids */
151+
if (array_key_exists('external_ids', $data)) {
152+
$movie->setExternalIds(
153+
$this->hydrate(new ExternalIds(), $data['external_ids'])
154+
);
155+
}
156+
149157
/** Genres */
150158
if (array_key_exists('genres', $data)) {
151159
$movie->setGenres($this->getGenreFactory()->createCollection($data['genres']));

lib/Tmdb/Model/Movie.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Tmdb\Model\Collection\ResultCollection;
2222
use Tmdb\Model\Collection\Videos;
2323
use Tmdb\Model\Common\Country;
24+
use Tmdb\Model\Common\ExternalIds;
2425
use Tmdb\Model\Common\GenericCollection;
2526
use Tmdb\Model\Common\SpokenLanguage;
2627
use Tmdb\Model\Movie\AlternativeTitle;
@@ -76,6 +77,12 @@ class Movie extends AbstractModel
7677
* @var CreditsCollection
7778
*/
7879
protected $credits;
80+
/**
81+
* External Ids
82+
*
83+
* @var ExternalIds
84+
*/
85+
private $externalIds;
7986
/**
8087
* Images
8188
*
@@ -785,6 +792,26 @@ public function setCredits(CreditsCollection $credits)
785792
return $this;
786793
}
787794

795+
/**
796+
* @return ExternalIds
797+
*/
798+
public function getExternalIds()
799+
{
800+
return $this->externalIds;
801+
}
802+
803+
/**
804+
* @param ExternalIds $externalIds
805+
* @return $this
806+
*/
807+
public function setExternalIds($externalIds)
808+
{
809+
$this->externalIds = $externalIds;
810+
811+
return $this;
812+
}
813+
814+
788815
/**
789816
* @return GenericCollection|Keyword[]
790817
*/

lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
final class AppendToResponse extends BaseAppendToResponse
2424
{
2525
public const ALTERNATIVE_TITLES = 'alternative_titles';
26+
public const EXTERNAL_IDS = 'external_ids';
2627
public const CREDITS = 'credits';
2728
public const IMAGES = 'images';
2829
public const KEYWORDS = 'keywords';

lib/Tmdb/Repository/MovieRepository.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function load($id, array $parameters = [], array $headers = [])
7070
$parameters = array_merge($parameters, [
7171
new AppendToResponse([
7272
AppendToResponse::ALTERNATIVE_TITLES,
73+
AppendToResponse::EXTERNAL_IDS,
7374
AppendToResponse::CHANGES,
7475
AppendToResponse::CREDITS,
7576
AppendToResponse::IMAGES,
@@ -453,6 +454,22 @@ public function getVideos($id, array $parameters = [], array $headers = [])
453454
return $movie->getVideos();
454455
}
455456

457+
/**
458+
* Get the external ids that we have stored for a movie.
459+
*
460+
* @param $id
461+
* @param $parameters
462+
* @param $headers
463+
* @return null|AbstractModel
464+
*/
465+
public function getExternalIds($id, array $parameters = [], array $headers = [])
466+
{
467+
$data = $this->getApi()->getExternalIds($id, $this->parseQueryParameters($parameters), $headers);
468+
$movie = $this->getFactory()->create(['external_ids' => $data]);
469+
470+
return $movie->getExternalIds();
471+
}
472+
456473
/**
457474
* @return AlternativeTitleFactory
458475
*/

0 commit comments

Comments
 (0)