Skip to content

Commit d47bbfd

Browse files
committed
Add support for watch providers to movie objects
1 parent e800d43 commit d47bbfd

6 files changed

Lines changed: 347 additions & 0 deletions

File tree

lib/Tmdb/Factory/MovieFactory.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Tmdb\Model\Common\Translation;
2929
use Tmdb\Model\Company;
3030
use Tmdb\Model\Movie;
31+
use Tmdb\Model\Watch;
3132

3233
/**
3334
* Class MovieFactory
@@ -206,6 +207,26 @@ public function create(array $data = []): ?AbstractModel
206207
$movie->setReleaseDates($release_dates);
207208
}
208209

210+
if (array_key_exists('watch/providers', $data) && array_key_exists('results', $data['watch/providers'])) {
211+
$watchProviders = new GenericCollection();
212+
foreach ($data['watch/providers']['results'] as $iso_31661 => $country_watch_data) {
213+
$country_watch_data['iso_3166_1'] = $iso_31661;
214+
215+
foreach (['flatrate', 'rent', 'buy'] as $providerType) {
216+
$typeProviders = new GenericCollection();
217+
foreach ($country_watch_data[$providerType] ?? [] as $providerData) {
218+
$providerData['iso_3166_1'] = $iso_31661;
219+
$providerData['type'] = $providerType;
220+
$typeProviders->add(null, $this->hydrate(new Watch\Provider(), $providerData));
221+
}
222+
$country_watch_data[$providerType] = $typeProviders;
223+
}
224+
225+
$watchProviders->add($iso_31661, $this->hydrate(new Watch\Providers(), $country_watch_data));
226+
}
227+
$movie->setWatchProviders($watchProviders);
228+
}
229+
209230
if (array_key_exists('videos', $data)) {
210231
$movie->setVideos($this->getVideoFactory()->createCollection($data['videos']));
211232
}

lib/Tmdb/Model/Movie.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ class Movie extends AbstractModel
230230
* @var int
231231
*/
232232
private $voteCount;
233+
/**
234+
* @var GenericCollection
235+
*/
236+
private $watchProviders;
233237

234238
/**
235239
* Constructor
@@ -255,6 +259,7 @@ public function __construct()
255259
$this->recommendations = new GenericCollection();
256260
$this->translations = new GenericCollection();
257261
$this->videos = new Videos();
262+
$this->watchProviders = new GenericCollection();
258263
}
259264

260265
/**
@@ -1032,4 +1037,23 @@ public function setVideos($videos)
10321037

10331038
return $this;
10341039
}
1040+
1041+
/**
1042+
* @return GenericCollection
1043+
*/
1044+
public function getWatchProviders(): GenericCollection
1045+
{
1046+
return $this->watchProviders;
1047+
}
1048+
1049+
/**
1050+
* @param GenericCollection $watchProviders
1051+
* @return $this
1052+
*/
1053+
public function setWatchProviders($watchProviders)
1054+
{
1055+
$this->watchProviders = $watchProviders;
1056+
1057+
return $this;
1058+
}
10351059
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ final class AppendToResponse extends BaseAppendToResponse
4040
public const LISTS = 'lists';
4141
public const CHANGES = 'changes';
4242
public const VIDEOS = 'videos';
43+
public const WATCH_PROVIDERS = 'watch/providers';
4344
}

lib/Tmdb/Model/Watch/Provider.php

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Tmdb PHP API created by Michael Roterman.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @package Tmdb
10+
* @author Michael Roterman <michael@wtfz.net>
11+
* @copyright (c) 2013, Michael Roterman
12+
* @version 4.0.0
13+
*/
14+
15+
namespace Tmdb\Model\Watch;
16+
17+
use Tmdb\Model\AbstractModel;
18+
use Tmdb\Model\Filter\CountryFilter;
19+
20+
/**
21+
* Class Watch Provider
22+
* @package Tmdb\Model\Watch
23+
*/
24+
class Provider extends AbstractModel implements CountryFilter
25+
{
26+
public static $properties = [
27+
'iso_3166_1',
28+
'provider_id',
29+
'provider_name',
30+
'logo_path',
31+
'display_priority',
32+
'type'
33+
];
34+
private $iso31661;
35+
private $providerID;
36+
private $providerName;
37+
private $logoPath;
38+
private $displayPriority;
39+
private $type;
40+
41+
/**
42+
* @return string
43+
*/
44+
public function getIso31661()
45+
{
46+
return $this->iso31661;
47+
}
48+
49+
/**
50+
* @param string $iso31661
51+
* @return $this
52+
*/
53+
public function setIso31661($iso31661)
54+
{
55+
$this->iso31661 = $iso31661;
56+
57+
return $this;
58+
}
59+
60+
/**
61+
* @return int|null
62+
*/
63+
public function getProviderID()
64+
{
65+
return $this->providerID;
66+
}
67+
68+
/**
69+
* @param int|null $providerID
70+
* @return $this
71+
*/
72+
public function setProviderID($providerID)
73+
{
74+
$this->providerID = $providerID;
75+
76+
return $this;
77+
}
78+
79+
/**
80+
* @return string|null
81+
*/
82+
public function getProviderName()
83+
{
84+
return $this->providerName;
85+
}
86+
87+
/**
88+
* @param string|null $providerName
89+
* @return $this
90+
*/
91+
public function setProviderName($providerName)
92+
{
93+
$this->providerName = $providerName;
94+
95+
return $this;
96+
}
97+
98+
/**
99+
* @return string|null
100+
*/
101+
public function getLogoPath()
102+
{
103+
return $this->logoPath;
104+
}
105+
106+
/**
107+
* @param string|null $logoPath
108+
* @return $this
109+
*/
110+
public function setLogoPath($logoPath)
111+
{
112+
$this->logoPath = $logoPath;
113+
114+
return $this;
115+
}
116+
117+
/**
118+
* @return int|null
119+
*/
120+
public function getDisplayPriority()
121+
{
122+
return $this->displayPriority;
123+
}
124+
125+
/**
126+
* @param int|null $displayPriority
127+
* @return $this
128+
*/
129+
public function setDisplayPriority($displayPriority)
130+
{
131+
$this->displayPriority = $displayPriority;
132+
133+
return $this;
134+
}
135+
136+
/**
137+
* @return string|null
138+
*/
139+
public function getType()
140+
{
141+
return $this->type;
142+
}
143+
144+
/**
145+
* @param string|null $type
146+
* @return $this
147+
*/
148+
public function setType($type)
149+
{
150+
$this->type = $type;
151+
152+
return $this;
153+
}
154+
}

lib/Tmdb/Model/Watch/Providers.php

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Tmdb PHP API created by Michael Roterman.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @package Tmdb
10+
* @author Michael Roterman <michael@wtfz.net>
11+
* @copyright (c) 2013, Michael Roterman
12+
* @version 4.0.0
13+
*/
14+
15+
namespace Tmdb\Model\Watch;
16+
17+
use Tmdb\Model\AbstractModel;
18+
use Tmdb\Model\Common\GenericCollection;
19+
use Tmdb\Model\Filter\CountryFilter;
20+
21+
/**
22+
* Class Watch Providers
23+
* @package Tmdb\Model\Watch
24+
*/
25+
class Providers extends AbstractModel implements CountryFilter
26+
{
27+
public static $properties = [
28+
'iso_3166_1',
29+
'link',
30+
'flatrate',
31+
'rent',
32+
'buy'
33+
];
34+
private $iso31661;
35+
private $link;
36+
private $flatrate;
37+
private $rent;
38+
private $buy;
39+
40+
/**
41+
* Constructor
42+
*
43+
* Set all default collections
44+
*/
45+
public function __construct()
46+
{
47+
$this->flatrate = new GenericCollection();
48+
$this->rent = new GenericCollection();
49+
$this->buy = new GenericCollection();
50+
}
51+
52+
/**
53+
* @return string|null
54+
*/
55+
public function getLink()
56+
{
57+
return $this->link;
58+
}
59+
60+
/**
61+
* @param string|null $link
62+
* @return $this
63+
*/
64+
public function setLink($link)
65+
{
66+
$this->link = $link;
67+
68+
return $this;
69+
}
70+
71+
/**
72+
* @return string
73+
*/
74+
public function getIso31661()
75+
{
76+
return $this->iso31661;
77+
}
78+
79+
/**
80+
* @param string $iso31661
81+
* @return $this
82+
*/
83+
public function setIso31661($iso31661)
84+
{
85+
$this->iso31661 = $iso31661;
86+
87+
return $this;
88+
}
89+
90+
/**
91+
* @return GenericCollection
92+
*/
93+
public function getFlatrate()
94+
{
95+
return $this->flatrate;
96+
}
97+
98+
/**
99+
* @param GenericCollection $flatrate
100+
* @return $this
101+
*/
102+
public function setFlatrate($flatrate)
103+
{
104+
$this->flatrate = $flatrate;
105+
106+
return $this;
107+
}
108+
109+
/**
110+
* @return GenericCollection
111+
*/
112+
public function getRent()
113+
{
114+
return $this->rent;
115+
}
116+
117+
/**
118+
* @param GenericCollection $rent
119+
* @return $this
120+
*/
121+
public function setRent($rent)
122+
{
123+
$this->rent = $rent;
124+
125+
return $this;
126+
}
127+
128+
/**
129+
* @return GenericCollection
130+
*/
131+
public function getBuy()
132+
{
133+
return $this->buy;
134+
}
135+
136+
/**
137+
* @param GenericCollection $buy
138+
* @return $this
139+
*/
140+
public function setBuy($buy)
141+
{
142+
$this->buy = $buy;
143+
144+
return $this;
145+
}
146+
}

lib/Tmdb/Repository/MovieRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function load($id, array $parameters = [], array $headers = [])
8282
AppendToResponse::RECOMMENDATIONS,
8383
AppendToResponse::TRANSLATIONS,
8484
AppendToResponse::VIDEOS,
85+
AppendToResponse::WATCH_PROVIDERS,
8586
])
8687
]);
8788
}

0 commit comments

Comments
 (0)