Skip to content

Commit de40074

Browse files
committed
Add support for watch providers to tv show objects
1 parent d47bbfd commit de40074

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

lib/Tmdb/Factory/TvFactory.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Tmdb\Model\Person\CastMember;
3030
use Tmdb\Model\Person\CrewMember;
3131
use Tmdb\Model\Tv;
32+
use Tmdb\Model\Watch;
3233

3334
/**
3435
* Class TvFactory
@@ -244,6 +245,26 @@ public function create(array $data = []): ?AbstractModel
244245
$tvShow->setNetworks($this->getNetworkFactory()->createCollection($data['networks']));
245246
}
246247

248+
if (array_key_exists('watch/providers', $data) && array_key_exists('results', $data['watch/providers'])) {
249+
$watchProviders = new GenericCollection();
250+
foreach ($data['watch/providers']['results'] as $iso_31661 => $country_watch_data) {
251+
$country_watch_data['iso_3166_1'] = $iso_31661;
252+
253+
foreach (['flatrate', 'rent', 'buy'] as $providerType) {
254+
$typeProviders = new GenericCollection();
255+
foreach ($country_watch_data[$providerType] ?? [] as $providerData) {
256+
$providerData['iso_3166_1'] = $iso_31661;
257+
$providerData['type'] = $providerType;
258+
$typeProviders->add(null, $this->hydrate(new Watch\Provider(), $providerData));
259+
}
260+
$country_watch_data[$providerType] = $typeProviders;
261+
}
262+
263+
$watchProviders->add($iso_31661, $this->hydrate(new Watch\Providers(), $country_watch_data));
264+
}
265+
$tvShow->setWatchProviders($watchProviders);
266+
}
267+
247268
if (array_key_exists('videos', $data) && $data['videos'] !== null) {
248269
$tvShow->setVideos($this->getVideoFactory()->createCollection($data['videos']));
249270
}

lib/Tmdb/Model/Tv.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ class Tv extends AbstractModel
234234
* @var int
235235
*/
236236
private $voteCount;
237+
/**
238+
* @var GenericCollection
239+
*/
240+
private $watchProviders;
237241

238242
/**
239243
* Constructor
@@ -258,6 +262,7 @@ public function __construct()
258262
$this->contentRatings = new GenericCollection();
259263
$this->alternativeTitles = new GenericCollection();
260264
$this->languages = new GenericCollection();
265+
$this->watchProviders = new GenericCollection();
261266
}
262267

263268
/**
@@ -1045,4 +1050,23 @@ public function setType($type)
10451050

10461051
return $this;
10471052
}
1053+
1054+
/**
1055+
* @return GenericCollection
1056+
*/
1057+
public function getWatchProviders(): GenericCollection
1058+
{
1059+
return $this->watchProviders;
1060+
}
1061+
1062+
/**
1063+
* @param GenericCollection $watchProviders
1064+
* @return $this
1065+
*/
1066+
public function setWatchProviders($watchProviders)
1067+
{
1068+
$this->watchProviders = $watchProviders;
1069+
1070+
return $this;
1071+
}
10481072
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ class AppendToResponse extends BaseAppendToResponse
3333
public const RECOMMENDATIONS = 'recommendations';
3434
public const CONTENT_RATINGS = 'content_ratings';
3535
public const ALTERNATIVE_TITLES = 'alternative_titles';
36+
public const WATCH_PROVIDERS = 'watch/providers';
3637
}

lib/Tmdb/Repository/TvRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function load($id, array $parameters = [], array $headers = [])
6161
AppendToResponse::CONTENT_RATINGS,
6262
AppendToResponse::ALTERNATIVE_TITLES,
6363
AppendToResponse::VIDEOS,
64+
AppendToResponse::WATCH_PROVIDERS,
6465
])
6566
]);
6667
}

0 commit comments

Comments
 (0)