1 | <?php declare(strict_types=1); |
||
2 | /** |
||
3 | * This file is part of the Tmdb package. |
||
4 | * |
||
5 | * (c) Vincent Faliès <[email protected]> |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | * |
||
10 | * @author Vincent Faliès <[email protected]> |
||
11 | * @copyright Copyright (c) 2017-2021 |
||
12 | */ |
||
13 | |||
14 | |||
15 | namespace VfacTmdb\Items; |
||
16 | |||
17 | use VfacTmdb\Abstracts\Item; |
||
18 | use VfacTmdb\Interfaces\Items\TVShowInterface; |
||
19 | use VfacTmdb\Traits\ElementTrait; |
||
20 | use VfacTmdb\Interfaces\TmdbInterface; |
||
21 | use VfacTmdb\Results; |
||
22 | |||
23 | /** |
||
24 | * TVShow class |
||
25 | * @package Tmdb |
||
26 | * @author Vincent Faliès <[email protected]> |
||
27 | * @copyright Copyright (c) 2017-2021 |
||
28 | */ |
||
29 | class TVShow extends Item implements TVShowInterface |
||
30 | { |
||
31 | use ElementTrait; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | * @param TmdbInterface $tmdb |
||
36 | * @param int $tv_id |
||
37 | * @param array $options |
||
38 | */ |
||
39 | 105 | public function __construct(TmdbInterface $tmdb, int $tv_id, array $options = array()) |
|
40 | { |
||
41 | 105 | parent::__construct($tmdb, $tv_id, $options, 'tv'); |
|
42 | |||
43 | 102 | $this->setElementTrait($this->data); |
|
44 | 102 | } |
|
45 | |||
46 | /** |
||
47 | * Get TV show id |
||
48 | * @return int |
||
49 | */ |
||
50 | 3 | public function getId() : int |
|
51 | { |
||
52 | 3 | return $this->id; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get TVSHow genres |
||
57 | * @return array |
||
58 | */ |
||
59 | 6 | public function getGenres() : array |
|
60 | { |
||
61 | 6 | if (isset($this->data->genres)) { |
|
62 | 3 | return $this->data->genres; |
|
63 | } |
||
64 | 3 | return []; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Get TVshow note |
||
69 | * @return float |
||
70 | */ |
||
71 | 6 | public function getNote() : float |
|
72 | { |
||
73 | 6 | if (isset($this->data->vote_average)) { |
|
74 | 3 | return $this->data->vote_average; |
|
75 | } |
||
76 | 3 | return 0; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Get TVshow number of episodes |
||
81 | * @return int |
||
82 | */ |
||
83 | 6 | public function getNumberEpisodes() : int |
|
84 | { |
||
85 | 6 | if (isset($this->data->number_of_episodes)) { |
|
86 | 3 | return $this->data->number_of_episodes; |
|
87 | } |
||
88 | 3 | return 0; |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * Get TVShow number of seasons |
||
93 | * @return int |
||
94 | */ |
||
95 | 6 | public function getNumberSeasons() : int |
|
96 | { |
||
97 | 6 | if (isset($this->data->number_of_seasons)) { |
|
98 | 3 | return $this->data->number_of_seasons; |
|
99 | } |
||
100 | 3 | return 0; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Get TVShow original title |
||
105 | * @return string |
||
106 | */ |
||
107 | 6 | public function getOriginalTitle() : string |
|
108 | { |
||
109 | 6 | if (isset($this->data->original_name)) { |
|
110 | 3 | return $this->data->original_name; |
|
111 | } |
||
112 | 3 | return ''; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Get TVShow overview |
||
117 | * @return string |
||
118 | */ |
||
119 | 6 | public function getOverview() : string |
|
120 | { |
||
121 | 6 | if (isset($this->data->overview)) { |
|
122 | 3 | return $this->data->overview; |
|
123 | } |
||
124 | 3 | return ''; |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * Get TVShow release date |
||
129 | * @return string |
||
130 | */ |
||
131 | 6 | public function getReleaseDate() : string |
|
132 | { |
||
133 | 6 | if (isset($this->data->first_air_date)) { |
|
134 | 3 | return $this->data->first_air_date; |
|
135 | } |
||
136 | 3 | return ''; |
|
137 | } |
||
138 | |||
139 | /** |
||
140 | * Get TVShow status |
||
141 | * @return string |
||
142 | */ |
||
143 | 6 | public function getStatus() : string |
|
144 | { |
||
145 | 6 | if (isset($this->data->status)) { |
|
146 | 3 | return $this->data->status; |
|
147 | } |
||
148 | 3 | return ''; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * Get TVShow title |
||
153 | * @return string |
||
154 | */ |
||
155 | 6 | public function getTitle() : string |
|
156 | { |
||
157 | 6 | if (isset($this->data->name)) { |
|
158 | 3 | return $this->data->name; |
|
159 | } |
||
160 | 3 | return ''; |
|
161 | } |
||
162 | |||
163 | /** |
||
164 | * Get TVShow seasons |
||
165 | * @return \Generator|Results\TVSeason |
||
166 | */ |
||
167 | 18 | public function getSeasons() : \Generator |
|
168 | { |
||
169 | 18 | if (!empty($this->data->seasons)) { |
|
170 | 15 | foreach ($this->data->seasons as $season) { |
|
171 | 15 | $season = new Results\TVSeason($this->tmdb, $season); |
|
172 | 15 | yield $season; |
|
173 | } |
||
174 | } |
||
175 | 6 | } |
|
176 | |||
177 | /** |
||
178 | * Get TVShow networks |
||
179 | * @return \Generator|\stdClass |
||
180 | */ |
||
181 | 3 | public function getNetworks() : \Generator |
|
182 | { |
||
183 | 3 | if (!empty($this->data->networks)) { |
|
184 | 3 | foreach ($this->data->networks as $network) { |
|
185 | 3 | $n = new \stdClass(); |
|
186 | 3 | $n->id = $network->id; |
|
187 | 3 | $n->name = $network->name; |
|
188 | |||
189 | 3 | yield $n; |
|
190 | } |
||
191 | } |
||
192 | 3 | } |
|
193 | |||
194 | /** |
||
195 | * Backdrops list |
||
196 | * @return \Generator|Results\Image |
||
197 | */ |
||
198 | 3 | public function getBackdrops() : \Generator |
|
199 | { |
||
200 | 3 | $params = []; |
|
201 | 3 | $this->tmdb->checkOptionLanguage($this->params, $params); |
|
202 | 3 | $data = $this->tmdb->getRequest('tv/' . (int) $this->id . '/images', $params); |
|
203 | |||
204 | 3 | foreach ($data->backdrops as $b) { |
|
205 | 3 | $image = new Results\Image($this->tmdb, $this->id, $b); |
|
206 | 3 | yield $image; |
|
207 | } |
||
208 | 3 | } |
|
209 | |||
210 | /** |
||
211 | * Posters list |
||
212 | * @return \Generator|Results\Image |
||
213 | */ |
||
214 | 3 | public function getPosters() : \Generator |
|
215 | { |
||
216 | 3 | $params = []; |
|
217 | 3 | $this->tmdb->checkOptionLanguage($this->params, $params); |
|
218 | 3 | $data = $this->tmdb->getRequest('tv/' . (int) $this->id . '/images', $params); |
|
219 | |||
220 | 3 | foreach ($data->posters as $b) { |
|
221 | 3 | $image = new Results\Image($this->tmdb, $this->id, $b); |
|
222 | 3 | yield $image; |
|
223 | } |
||
224 | 3 | } |
|
225 | |||
226 | /** |
||
227 | * Get Similar TVShow |
||
228 | * @return \Generator|Results\TVShow |
||
229 | */ |
||
230 | 3 | public function getSimilar() : \Generator |
|
231 | { |
||
232 | 3 | $params = []; |
|
233 | 3 | $this->tmdb->checkOptionLanguage($this->params, $params); |
|
234 | 3 | $this->tmdb->checkOptionPage($this->params, $params); |
|
235 | 3 | $similar = $this->tmdb->getRequest('tv/' . (int) $this->id . '/similar', $params); |
|
236 | |||
237 | 3 | foreach ($similar->results as $t) { |
|
238 | 3 | $tvshow = new Results\TVShow($this->tmdb, $t); |
|
239 | 3 | yield $tvshow; |
|
240 | } |
||
241 | 3 | } |
|
242 | |||
243 | |||
244 | /** |
||
245 | * Get TVShow crew |
||
246 | * @return \Generator|Results\Crew |
||
247 | */ |
||
248 | 3 | public function getCrew() : \Generator |
|
249 | { |
||
250 | 3 | $credit = new TVShowCredit($this->tmdb, $this->id); |
|
251 | return $credit->getCrew(); |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * Get TVShow cast |
||
256 | * @return \Generator|Results\Cast |
||
257 | */ |
||
258 | 3 | public function getCast() : \Generator |
|
259 | { |
||
260 | 3 | $cast = new TVShowCredit($this->tmdb, $this->id); |
|
261 | 3 | return $cast->getCast(); |
|
262 | } |
||
263 | |||
264 | /** |
||
265 | * Get the underlying ItemChanges object for this Item |
||
266 | * @param array $options Array of options for the request |
||
267 | * @return TVShowItemChanges |
||
268 | */ |
||
269 | public function getItemChanges(array $options = array()) : TVShowItemChanges |
||
270 | { |
||
271 | return new TVShowItemChanges($this->tmdb, $this->id, $options); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Get this Item's Changes |
||
276 | * @param array $options Array of options for the request |
||
277 | * @return \Generator |
||
278 | */ |
||
279 | public function getChanges(array $options = array()) : \Generator |
||
280 | { |
||
281 | $changes = $this->getItemChanges($options); |
||
282 | return $changes->getChanges(); |
||
283 | } |
||
284 | } |
||
285 |