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 |
||
12 | */ |
||
13 | |||
14 | |||
15 | namespace VfacTmdb\Results; |
||
16 | |||
17 | use VfacTmdb\Abstracts; |
||
18 | use VfacTmdb\Results; |
||
19 | use VfacTmdb\Interfaces\Results\TVEpisodeResultsInterface; |
||
20 | use VfacTmdb\Traits\ElementTrait; |
||
21 | use VfacTmdb\Traits\TVEpisodeTrait; |
||
22 | use VfacTmdb\Interfaces\TmdbInterface; |
||
23 | |||
24 | /** |
||
25 | * Class to manipulate a TV Episode result |
||
26 | * @package Tmdb |
||
27 | * @author Vincent Faliès <[email protected]> |
||
28 | * @copyright Copyright (c) 2017 |
||
29 | */ |
||
30 | class TVEpisode extends Abstracts\Results implements TVEpisodeResultsInterface |
||
31 | { |
||
32 | use ElementTrait; |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
33 | use TVEpisodeTrait; |
||
0 ignored issues
–
show
|
|||
34 | |||
35 | /** |
||
36 | * Episode number |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $episode_number = 0; |
||
40 | /** |
||
41 | * Name |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $name = ''; |
||
45 | /** |
||
46 | * Air date |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $air_date = null; |
||
50 | /** |
||
51 | * Season number |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $season_number = 0; |
||
55 | /** |
||
56 | * Vote average |
||
57 | * @var float |
||
58 | */ |
||
59 | protected $vote_average = 0; |
||
60 | /** |
||
61 | * Vote count |
||
62 | * @var int |
||
63 | */ |
||
64 | protected $vote_count = 0; |
||
65 | /** |
||
66 | * Overview |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $overview = ''; |
||
70 | /** |
||
71 | * Production code |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $production_code = ''; |
||
75 | /** |
||
76 | * Image still path |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $still_path = ''; |
||
80 | /** |
||
81 | * Id |
||
82 | * @var int |
||
83 | */ |
||
84 | protected $id = null; |
||
85 | /** |
||
86 | * Guest stars |
||
87 | * @var array |
||
88 | */ |
||
89 | protected $guest_stars = []; |
||
90 | |||
91 | /** |
||
92 | * Constructor |
||
93 | * @param TmdbInterface $tmdb |
||
94 | * @param \stdClass $result |
||
95 | * @throws \Exception |
||
96 | */ |
||
97 | 66 | public function __construct(TmdbInterface $tmdb, \stdClass $result) |
|
98 | { |
||
99 | 66 | $result = $this->initResultObject($result); |
|
100 | |||
101 | 66 | parent::__construct($tmdb, $result); |
|
102 | |||
103 | // Populate data |
||
104 | 66 | $this->id = $this->data->id; |
|
105 | 66 | $this->air_date = $this->data->air_date; |
|
106 | 66 | $this->season_number = $this->data->season_number; |
|
107 | 66 | $this->episode_number = $this->data->episode_number; |
|
108 | 66 | $this->name = $this->data->name; |
|
109 | 66 | $this->vote_average = $this->data->vote_average; |
|
110 | 66 | $this->vote_count = $this->data->vote_count; |
|
111 | 66 | $this->overview = $this->data->overview; |
|
112 | 66 | $this->production_code = $this->data->production_code; |
|
113 | 66 | $this->still_path = $this->data->still_path; |
|
114 | 66 | $this->guest_stars = $this->data->guest_stars; |
|
115 | |||
116 | 66 | $this->setElementTrait($this->data); |
|
117 | 66 | $this->setTVEpisodeTrait($tmdb, $this->data); |
|
118 | 66 | } |
|
119 | |||
120 | /** |
||
121 | * initResultObject |
||
122 | * @param \stdClass $result |
||
123 | * @return \stdClass |
||
124 | */ |
||
125 | 66 | private function initResultObject(\stdClass $result) : \stdClass |
|
126 | { |
||
127 | 66 | if (!isset($result->overview)) { |
|
128 | 3 | $result->overview = null; |
|
129 | } |
||
130 | 66 | if (!isset($result->production_code)) { |
|
131 | 3 | $result->production_code = null; |
|
132 | } |
||
133 | 66 | if (!isset($result->guest_stars)) { |
|
134 | 6 | $result->guest_stars = null; |
|
135 | } |
||
136 | 66 | return $result; |
|
137 | } |
||
138 | |||
139 | /** |
||
140 | * Air date |
||
141 | * @return string |
||
142 | */ |
||
143 | 3 | public function getAirDate() : string |
|
144 | { |
||
145 | 3 | return $this->air_date; |
|
146 | } |
||
147 | |||
148 | /** |
||
149 | * Episode number |
||
150 | * @return int |
||
151 | */ |
||
152 | 3 | public function getEpisodeNumber() : int |
|
153 | { |
||
154 | 3 | return (int) $this->episode_number; |
|
155 | } |
||
156 | |||
157 | /** |
||
158 | * Guests stars |
||
159 | * @return \Generator|Results\Cast |
||
160 | */ |
||
161 | 3 | public function getGuestStars() : \Generator |
|
162 | { |
||
163 | 3 | if (isset($this->guest_stars)) { |
|
164 | 3 | foreach ($this->guest_stars as $gs) { |
|
165 | 3 | $gs->gender = null; |
|
166 | 3 | $gs->cast_id = null; |
|
167 | |||
168 | 3 | $star = new Results\Cast($this->tmdb, $gs); |
|
169 | 3 | yield $star; |
|
170 | } |
||
171 | } |
||
172 | 3 | } |
|
173 | |||
174 | /** |
||
175 | * Id |
||
176 | * @return int |
||
177 | */ |
||
178 | 3 | public function getId() : int |
|
179 | { |
||
180 | 3 | return (int) $this->id; |
|
181 | } |
||
182 | |||
183 | /** |
||
184 | * Name |
||
185 | * @return string |
||
186 | */ |
||
187 | 6 | public function getName() : string |
|
188 | { |
||
189 | 6 | return $this->name; |
|
190 | } |
||
191 | |||
192 | /** |
||
193 | * Note |
||
194 | * @return float |
||
195 | */ |
||
196 | 3 | public function getNote() : float |
|
197 | { |
||
198 | 3 | return $this->vote_average; |
|
199 | } |
||
200 | |||
201 | /** |
||
202 | * Note count |
||
203 | * @return int |
||
204 | */ |
||
205 | 3 | public function getNoteCount() : int |
|
206 | { |
||
207 | 3 | return (int) $this->vote_count; |
|
208 | } |
||
209 | |||
210 | /** |
||
211 | * Overview |
||
212 | * @return string |
||
213 | */ |
||
214 | 3 | public function getOverview() : string |
|
215 | { |
||
216 | 3 | return $this->overview; |
|
217 | } |
||
218 | |||
219 | /** |
||
220 | * Production code |
||
221 | * @return string |
||
222 | */ |
||
223 | 3 | public function getProductionCode() : string |
|
224 | { |
||
225 | 3 | return $this->production_code; |
|
226 | } |
||
227 | |||
228 | /** |
||
229 | * Season number |
||
230 | * @return int |
||
231 | */ |
||
232 | 3 | public function getSeasonNumber() : int |
|
233 | { |
||
234 | 3 | return (int) $this->season_number; |
|
235 | } |
||
236 | |||
237 | /** |
||
238 | * Image still path |
||
239 | * @return string |
||
240 | */ |
||
241 | 3 | public function getStillPath() : string |
|
242 | { |
||
243 | 3 | return $this->still_path; |
|
244 | } |
||
245 | } |
||
246 |