-
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathTvSeasonRepository.php
More file actions
223 lines (192 loc) · 6.38 KB
/
TvSeasonRepository.php
File metadata and controls
223 lines (192 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <michael@wtfz.net>
* @copyright (c) 2013, Michael Roterman
* @version 4.0.0
*/
namespace Tmdb\Repository;
use Tmdb\Api\TvSeason;
use Tmdb\Exception\RuntimeException;
use Tmdb\Factory\TvSeasonFactory;
use Tmdb\Model\AbstractModel;
use Tmdb\Model\Collection\CreditsCollection;
use Tmdb\Model\Collection\Images;
use Tmdb\Model\Collection\Videos;
use Tmdb\Model\Common\Video;
use Tmdb\Model\Tv;
use Tmdb\Model\Tv\Season;
use Tmdb\Model\Tv\Season\QueryParameter\AppendToResponse;
/**
* Class TvSeasonRepository
* @package Tmdb\Repository
* @see http://docs.themoviedb.apiary.io/#tvseasons
*/
class TvSeasonRepository extends AbstractRepository
{
/**
* Load a tv season with the given identifier
*
* If you want to optimize the result set/bandwidth you should define the AppendToResponse parameter
*
* @param int|Tv $tvShow
* @param int|Season $season
* @param array $parameters
* @param array $headers
* @return null|AbstractModel
* @throws RuntimeException
*/
public function load($tvShow, $season, array $parameters = [], array $headers = [])
{
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}
if ($season instanceof Season) {
$season = $season->getSeasonNumber();
}
if (null === $tvShow || null === $season) {
throw new RuntimeException('Not all required parameters to load an tv season are present.');
}
if (!isset($parameters['append_to_response'])) {
$parameters = array_merge($parameters, [
new AppendToResponse([
AppendToResponse::CREDITS,
AppendToResponse::EXTERNAL_IDS,
AppendToResponse::IMAGES,
AppendToResponse::CHANGES,
AppendToResponse::VIDEOS
])
]);
}
$data = $this->getApi()->getSeason($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
return $this->getFactory()->create($data);
}
/**
* Return the Seasons API Class
*
* @return TvSeason
*/
public function getApi()
{
return $this->getClient()->getTvSeasonApi();
}
/**
* @return TvSeasonFactory
*/
public function getFactory()
{
return new TvSeasonFactory($this->getClient()->getHttpClient());
}
/**
* Get the cast & crew information about a TV series.
*
* Just like the website, we pull this information from the last season of the series.
*
* @param Tv|int $tvShow
* @param Season|int $season
* @param array $parameters
* @param array $headers
* @return CreditsCollection
*/
public function getCredits($tvShow, $season, array $parameters = [], array $headers = [])
{
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}
if ($season instanceof Season) {
$season = $season->getSeasonNumber();
}
$data = $this->getApi()->getCredits($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
$season = $this->getFactory()->create(['credits' => $data]);
return $season->getCredits();
}
/**
* Get the external ids that we have stored for a TV series.
*
* @param $tvShow
* @param $season
* @param $parameters
* @param $headers
* @return null|AbstractModel
*/
public function getExternalIds($tvShow, $season, array $parameters = [], array $headers = [])
{
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}
if ($season instanceof Season) {
$season = $season->getSeasonNumber();
}
$data = $this->getApi()->getExternalIds($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
$season = $this->getFactory()->create(['external_ids' => $data]);
return $season->getExternalIds();
}
/**
* Get the images (posters and backdrops) for a TV series.
*
* @param $tvShow
* @param $season
* @param $parameters
* @param $headers
* @return Images
*/
public function getImages($tvShow, $season, array $parameters = [], array $headers = [])
{
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}
if ($season instanceof Season) {
$season = $season->getSeasonNumber();
}
$data = $this->getApi()->getImages($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
$season = $this->getFactory()->create(['images' => $data]);
return $season->getImages();
}
/**
* Get the videos that have been added to a TV season (trailers, teasers, etc...)
*
* @param $tvShow
* @param $season
* @param $parameters
* @param $headers
* @return Videos|Video[]
*/
public function getVideos($tvShow, $season, array $parameters = [], array $headers = [])
{
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}
if ($season instanceof Season) {
$season = $season->getSeasonNumber();
}
$data = $this->getApi()->getVideos($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
$season = $this->getFactory()->create(['videos' => $data]);
return $season->getVideos();
}
/**
* Get the videos that have been added to a TV season (trailers, teasers, etc...)
*
* @param $tvShow
* @param $season
* @param $parameters
* @param $headers
* @return Videos|Video[]
*/
public function getTranslations($tvShow, $season, array $parameters = [], array $headers = [])
{
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}
if ($season instanceof Season) {
$season = $season->getSeasonNumber();
}
$data = $this->getApi()->getTranslations($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
$season = $this->getFactory()->create(['translations' => $data]);
return $season->getTranslations();
}
}