Skip to content

Commit 3d87c2d

Browse files
authored
Merge pull request #248 from php-tmdb/TvEpisodeGroups
Tv episode groups
2 parents 0349e2c + 55f8495 commit 3d87c2d

19 files changed

+1162
-9
lines changed

lib/Tmdb/Api/Tv.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,15 @@ public function getAlternativeTitles($id)
295295
{
296296
return $this->get('tv/' . $id . '/alternative_titles');
297297
}
298+
299+
/**
300+
* Get the alternative titles for a specific show ID.
301+
*
302+
* @param integer $id
303+
* @return mixed
304+
*/
305+
public function getEpisodeGroups($id)
306+
{
307+
return $this->get('tv/' . $id . '/episode_groups');
308+
}
298309
}

lib/Tmdb/Api/TvEpisodeGroup.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 sheriffmarley
11+
* @copyright (c) 2013, Michael Roterman
12+
* @version 4.0.0
13+
*/
14+
15+
namespace Tmdb\Api;
16+
17+
/**
18+
* Class TvEpisode
19+
* @package Tmdb\Api
20+
* @see http://docs.themoviedb.apiary.io/#tvepisodes
21+
*/
22+
class TvEpisodeGroup extends AbstractApi
23+
{
24+
/**
25+
* Get the primary information about a TV episode group by it's id.
26+
*
27+
* @param $episode_group
28+
* @param array $parameters
29+
* @param array $headers
30+
* @return mixed
31+
*/
32+
public function getEpisodeGroup(
33+
$episode_group,
34+
array $parameters = [],
35+
array $headers = []
36+
) {
37+
return $this->get(
38+
sprintf(
39+
'tv/episode_group/%s',
40+
$episode_group
41+
),
42+
$parameters,
43+
$headers
44+
);
45+
}
46+
}

lib/Tmdb/ApiMethodsTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,12 @@ public function getTvEpisodeApi()
207207
{
208208
return new Api\TvEpisode($this);
209209
}
210+
211+
/**
212+
* @return Api\TvEpisodeGroup
213+
*/
214+
public function getTvEpisodeGroupApi()
215+
{
216+
return new Api\TvEpisodeGroup($this);
217+
}
210218
}

lib/Tmdb/Factory/MovieFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function create(array $data = []): ?AbstractModel
211211
$watchProviders = new GenericCollection();
212212
foreach ($data['watch/providers']['results'] as $iso31661 => $countryWatchData) {
213213
$countryWatchData['iso_3166_1'] = $iso31661;
214-
214+
215215
foreach (['flatrate', 'rent', 'buy'] as $providerType) {
216216
$typeProviders = new GenericCollection();
217217
foreach ($countryWatchData[$providerType] ?? [] as $providerData) {
@@ -221,14 +221,14 @@ public function create(array $data = []): ?AbstractModel
221221
if (isset($providerData['provider_name'])) {
222222
$providerData['name'] = $providerData['provider_name'];
223223
}
224-
224+
225225
$providerData['iso_3166_1'] = $iso31661;
226226
$providerData['type'] = $providerType;
227227
$typeProviders->add(null, $this->hydrate(new Watch\Provider(), $providerData));
228228
}
229229
$countryWatchData[$providerType] = $typeProviders;
230230
}
231-
231+
232232
$watchProviders->add($iso31661, $this->hydrate(new Watch\Providers(), $countryWatchData));
233233
}
234234
$movie->setWatchProviders($watchProviders);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 sheriffmarley
11+
* @copyright (c) 2013, Michael Roterman
12+
* @version 4.0.0
13+
*/
14+
15+
namespace Tmdb\Factory;
16+
17+
use Tmdb\Model\Network;
18+
use Tmdb\Model\AbstractModel;
19+
use Tmdb\Model\Tv\EpisodeGroup;
20+
use Tmdb\HttpClient\HttpClient;
21+
use Tmdb\Model\Common\GenericCollection;
22+
23+
/**
24+
* Class TvEpisodeGroupFactory
25+
* @package Tmdb\Factory
26+
*/
27+
class TvEpisodeGroupFactory extends AbstractFactory
28+
{
29+
30+
/**
31+
* @var TvEpisodeGroupsFactory
32+
*/
33+
private $tvEpisodeGroupsFactory;
34+
35+
/**
36+
* Constructor
37+
*
38+
* @param HttpClient $httpClient
39+
*/
40+
public function __construct(HttpClient $httpClient)
41+
{
42+
$this->tvEpisodeGroupsFactory = new TvEpisodeGroupsFactory($httpClient);
43+
44+
parent::__construct($httpClient);
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function createCollection(array $data = [])
51+
{
52+
$collection = new GenericCollection();
53+
54+
foreach ($data as $item) {
55+
$collection->add(null, $this->create($item));
56+
}
57+
58+
return $collection;
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
*
64+
* @return AbstractModel|null
65+
*/
66+
public function create(array $data = []): ?AbstractModel
67+
{
68+
if (!$data) {
69+
return null;
70+
}
71+
72+
$episodeGroup = new EpisodeGroup();
73+
74+
if (array_key_exists('network', $data) && !is_null($data['network'])) {
75+
$episodeGroup->setNetwork($this->hydrate(new Network(), $data['network']));
76+
}
77+
78+
if (array_key_exists('groups', $data) && $data['groups'] !== null) {
79+
$episodeGroup->setGroups($this->tvEpisodeGroupsFactory->createCollection($data['groups']));
80+
}
81+
82+
return $this->hydrate($episodeGroup, $data);
83+
}
84+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 sheriffmarley
11+
* @copyright (c) 2013, Michael Roterman
12+
* @version 4.0.0
13+
*/
14+
15+
namespace Tmdb\Factory;
16+
17+
use Tmdb\Model\AbstractModel;
18+
use Tmdb\HttpClient\HttpClient;
19+
use Tmdb\Model\Tv\TvEpisodeGroup;
20+
use Tmdb\Model\Common\GenericCollection;
21+
22+
/**
23+
* Class TvEpisodeGroupsFactory
24+
* @package Tmdb\Factory
25+
*/
26+
class TvEpisodeGroupsFactory extends AbstractFactory
27+
{
28+
29+
/**
30+
* @var TvEpisodeFactory
31+
*/
32+
private $tvEpisodeFactory;
33+
34+
/**
35+
* Constructor
36+
*
37+
* @param HttpClient $httpClient
38+
*/
39+
public function __construct(HttpClient $httpClient)
40+
{
41+
$this->tvEpisodeFactory = new TvEpisodeFactory($httpClient);
42+
43+
parent::__construct($httpClient);
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function createCollection(array $data = [])
50+
{
51+
$collection = new GenericCollection();
52+
53+
foreach ($data as $item) {
54+
$collection->add(null, $this->create($item));
55+
}
56+
57+
return $collection;
58+
}
59+
60+
/**
61+
* {@inheritdoc}
62+
*
63+
* @return AbstractModel|null
64+
*/
65+
public function create(array $data = []): ?AbstractModel
66+
{
67+
if (!$data) {
68+
return null;
69+
}
70+
71+
$tvEpisodeGroup = new TvEpisodeGroup();
72+
73+
/** Episodes */
74+
if (array_key_exists('episodes', $data) && $data['episodes'] !== null) {
75+
$tvEpisodeGroup->setEpisodes($this->getTvEpisodeFactory()->createCollection($data['episodes']));
76+
}
77+
78+
return $this->hydrate($tvEpisodeGroup, $data);
79+
}
80+
81+
/**
82+
* @return TvEpisodeFactory
83+
*/
84+
public function getTvEpisodeFactory()
85+
{
86+
return $this->tvEpisodeFactory;
87+
}
88+
89+
/**
90+
* @param TvEpisodeFactory $tvEpisodeFactory
91+
* @return $this
92+
*/
93+
public function setTvEpisodeFactory($tvEpisodeFactory)
94+
{
95+
$this->tvEpisodeFactory = $tvEpisodeFactory;
96+
97+
return $this;
98+
}
99+
}

lib/Tmdb/Factory/TvFactory.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Tmdb\Model\Common\SpokenLanguage;
2727
use Tmdb\Model\Common\Translation;
2828
use Tmdb\Model\Company;
29+
use Tmdb\Model\Network;
2930
use Tmdb\Model\Person\CastMember;
3031
use Tmdb\Model\Person\CrewMember;
3132
use Tmdb\Model\Tv;
@@ -249,7 +250,7 @@ public function create(array $data = []): ?AbstractModel
249250
$watchProviders = new GenericCollection();
250251
foreach ($data['watch/providers']['results'] as $iso31661 => $countryWatchData) {
251252
$countryWatchData['iso_3166_1'] = $iso31661;
252-
253+
253254
foreach (['flatrate', 'rent', 'buy'] as $providerType) {
254255
$typeProviders = new GenericCollection();
255256
foreach ($countryWatchData[$providerType] ?? [] as $providerData) {
@@ -259,14 +260,14 @@ public function create(array $data = []): ?AbstractModel
259260
if (isset($providerData['provider_name'])) {
260261
$providerData['name'] = $providerData['provider_name'];
261262
}
262-
263+
263264
$providerData['iso_3166_1'] = $iso31661;
264265
$providerData['type'] = $providerType;
265266
$typeProviders->add(null, $this->hydrate(new Watch\Provider(), $providerData));
266267
}
267268
$countryWatchData[$providerType] = $typeProviders;
268269
}
269-
270+
270271
$watchProviders->add($iso31661, $this->hydrate(new Watch\Providers(), $countryWatchData));
271272
}
272273
$tvShow->setWatchProviders($watchProviders);
@@ -343,6 +344,19 @@ public function create(array $data = []): ?AbstractModel
343344
);
344345
}
345346

347+
if (array_key_exists('episode_groups', $data) && array_key_exists('results', $data['episode_groups'])) {
348+
$episodeGroupCollection = new GenericCollection();
349+
350+
foreach ($data['episode_groups']['results'] as $episodeGroup) {
351+
if (!is_null($episodeGroup['network'])) {
352+
$episodeGroup['network'] = $this->hydrate(new Network(), $episodeGroup['network']);
353+
}
354+
355+
$episodeGroupCollection->add(null, $this->hydrate(new Tv\EpisodeGroups(), $episodeGroup));
356+
}
357+
$tvShow->setEpisodeGroups($episodeGroupCollection);
358+
}
359+
346360
return $this->hydrate($tvShow, $data);
347361
}
348362

0 commit comments

Comments
 (0)