|
1
|
|
|
<?php |
|
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
|
|
|
|
|
11
|
|
|
* @author Vincent Faliès <[email protected]> |
|
12
|
|
|
* @copyright Copyright (c) 2017 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
namespace vfalies\tmdb\Items; |
|
17
|
|
|
|
|
18
|
|
|
use vfalies\tmdb\Abstracts\Item; |
|
19
|
|
|
use vfalies\tmdb\Interfaces\Items\MovieInterface; |
|
20
|
|
|
use vfalies\tmdb\Traits\ElementTrait; |
|
21
|
|
|
use vfalies\tmdb\Items\MovieCredit; |
|
22
|
|
|
use vfalies\tmdb\lib\Guzzle\Client as HttpClient; |
|
23
|
|
|
use vfalies\tmdb\Results\Image; |
|
24
|
|
|
use vfalies\tmdb\Interfaces\TmdbInterface; |
|
25
|
|
|
use vfalies\tmdb\Results\Movie as ResultMovie; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Movie class |
|
29
|
|
|
* @package Tmdb |
|
30
|
|
|
* @author Vincent Faliès <[email protected]> |
|
31
|
|
|
* @copyright Copyright (c) 2017 |
|
32
|
|
|
*/ |
|
33
|
|
|
class Movie extends Item implements MovieInterface |
|
34
|
|
|
{ |
|
35
|
|
|
|
|
36
|
|
|
use ElementTrait; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Constructor |
|
40
|
|
|
* @param \vfalies\tmdb\Interfaces\TmdbInterface $tmdb |
|
41
|
|
|
* @param int $movie_id |
|
42
|
|
|
* @param array $options |
|
43
|
|
|
*/ |
|
44
|
39 |
|
public function __construct(TmdbInterface $tmdb, $movie_id, array $options = array()) |
|
45
|
|
|
{ |
|
46
|
39 |
|
parent::__construct($tmdb, $movie_id, $options, 'movie'); |
|
47
|
38 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get movie genres |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
2 |
|
public function getGenres() |
|
54
|
|
|
{ |
|
55
|
2 |
|
if (isset($this->data->genres)) |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->data->genres; |
|
58
|
|
|
} |
|
59
|
1 |
|
return []; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get movie title |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
2 |
|
public function getTitle() |
|
67
|
|
|
{ |
|
68
|
2 |
|
if (isset($this->data->title)) |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->data->title; |
|
71
|
|
|
} |
|
72
|
1 |
|
return ''; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get movie overview |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
2 |
|
public function getOverview() |
|
80
|
|
|
{ |
|
81
|
2 |
|
if (isset($this->data->overview)) |
|
82
|
|
|
{ |
|
83
|
1 |
|
return $this->data->overview; |
|
84
|
|
|
} |
|
85
|
1 |
|
return ''; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get movie release date |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
2 |
|
public function getReleaseDate() |
|
93
|
|
|
{ |
|
94
|
2 |
|
if (isset($this->data->release_date)) |
|
95
|
|
|
{ |
|
96
|
1 |
|
return $this->data->release_date; |
|
97
|
|
|
} |
|
98
|
1 |
|
return ''; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get movie original title |
|
103
|
|
|
* @return string |
|
104
|
|
|
*/ |
|
105
|
2 |
|
public function getOriginalTitle() |
|
106
|
|
|
{ |
|
107
|
2 |
|
if (isset($this->data->original_title)) |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->data->original_title; |
|
110
|
|
|
} |
|
111
|
1 |
|
return ''; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get movie note |
|
116
|
|
|
* @return float |
|
117
|
|
|
*/ |
|
118
|
2 |
|
public function getNote() |
|
119
|
|
|
{ |
|
120
|
2 |
|
if (isset($this->data->vote_average)) |
|
121
|
|
|
{ |
|
122
|
1 |
|
return $this->data->vote_average; |
|
123
|
|
|
} |
|
124
|
1 |
|
return 0; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Get movie id |
|
129
|
|
|
* @return int |
|
130
|
|
|
*/ |
|
131
|
1 |
|
public function getId() |
|
132
|
|
|
{ |
|
133
|
1 |
|
return $this->id; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Get IMDB movie id |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
2 |
|
public function getIMDBId() |
|
141
|
|
|
{ |
|
142
|
2 |
|
if (isset($this->data->imdb_id)) |
|
143
|
|
|
{ |
|
144
|
1 |
|
return $this->data->imdb_id; |
|
145
|
|
|
} |
|
146
|
1 |
|
return ''; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Get movie tagline |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
2 |
|
public function getTagLine() |
|
154
|
|
|
{ |
|
155
|
2 |
|
if (isset($this->data->tagline)) |
|
156
|
|
|
{ |
|
157
|
1 |
|
return $this->data->tagline; |
|
158
|
|
|
} |
|
159
|
1 |
|
return ''; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Get collection id |
|
164
|
|
|
* @return int |
|
165
|
|
|
*/ |
|
166
|
2 |
|
public function getCollectionId() |
|
167
|
|
|
{ |
|
168
|
2 |
|
if ( ! empty($this->data->belongs_to_collection)) |
|
169
|
|
|
{ |
|
170
|
1 |
|
return (int) $this->data->belongs_to_collection->id; |
|
171
|
|
|
} |
|
172
|
1 |
|
return 0; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Get movie crew |
|
177
|
|
|
* @return \Generator|Results\Crew |
|
178
|
|
|
*/ |
|
179
|
1 |
|
public function getCrew() |
|
180
|
|
|
{ |
|
181
|
1 |
|
$credit = new MovieCredit($this->tmdb, $this->id); |
|
182
|
1 |
|
return $credit->getCrew(); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Get movie cast |
|
187
|
|
|
* @return \Generator|Results\Cast |
|
188
|
|
|
*/ |
|
189
|
9 |
|
public function getCast() |
|
190
|
|
|
{ |
|
191
|
9 |
|
$cast = new MovieCredit($this->tmdb, $this->id); |
|
192
|
9 |
|
return $cast->getCast(); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get production compagnies |
|
197
|
|
|
* @return \Generator|stdClass |
|
198
|
|
|
*/ |
|
199
|
1 |
|
public function getProductionCompanies() |
|
200
|
|
|
{ |
|
201
|
1 |
|
if ( ! empty($this->data->production_companies)) |
|
202
|
|
|
{ |
|
203
|
1 |
|
foreach ($this->data->production_companies as $p) |
|
204
|
|
|
{ |
|
205
|
1 |
|
$res = new \stdClass(); |
|
206
|
1 |
|
$res->id = $p->id; |
|
207
|
1 |
|
$res->name = $p->name; |
|
208
|
|
|
|
|
209
|
1 |
|
yield $res; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
1 |
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Get production countries |
|
216
|
|
|
* @return \Generator|stdClass |
|
217
|
|
|
*/ |
|
218
|
1 |
|
public function getProductionCountries() |
|
219
|
|
|
{ |
|
220
|
1 |
|
if ( ! empty($this->data->production_countries)) |
|
221
|
|
|
{ |
|
222
|
1 |
|
foreach ($this->data->production_countries as $c) |
|
223
|
|
|
{ |
|
224
|
1 |
|
$res = new \stdClass(); |
|
225
|
1 |
|
$res->iso_3166_1 = $c->iso_3166_1; |
|
226
|
1 |
|
$res->name = $c->name; |
|
227
|
|
|
|
|
228
|
1 |
|
yield $res; |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
1 |
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Get image backdrops list |
|
235
|
|
|
* @return \Generator|Results\Image |
|
236
|
|
|
*/ |
|
237
|
1 |
View Code Duplication |
public function getBackdrops() |
|
|
|
|
|
|
238
|
|
|
{ |
|
239
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/movie/'.(int) $this->id.'/images', null, $this->params); |
|
240
|
|
|
|
|
241
|
1 |
|
foreach ($data->backdrops as $b) |
|
242
|
|
|
{ |
|
243
|
1 |
|
$image = new Image($this->tmdb, $this->id, $b); |
|
244
|
1 |
|
yield $image; |
|
245
|
|
|
} |
|
246
|
1 |
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Get image posters list |
|
250
|
|
|
* @return \Generator|Results\Image |
|
251
|
|
|
*/ |
|
252
|
1 |
View Code Duplication |
public function getPosters() |
|
|
|
|
|
|
253
|
|
|
{ |
|
254
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/movie/'.(int) $this->id.'/images', null, $this->params); |
|
255
|
|
|
|
|
256
|
1 |
|
foreach ($data->posters as $b) |
|
257
|
|
|
{ |
|
258
|
1 |
|
$image = new Image($this->tmdb, $this->id, $b); |
|
259
|
1 |
|
yield $image; |
|
260
|
|
|
} |
|
261
|
1 |
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* Get similar movies from current movie |
|
265
|
|
|
* @return \Generator|Results\Movie |
|
266
|
|
|
*/ |
|
267
|
1 |
View Code Duplication |
public function getSimilar() |
|
|
|
|
|
|
268
|
|
|
{ |
|
269
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/movie/'.(int) $this->id.'/similar', null, $this->params); |
|
270
|
|
|
|
|
271
|
1 |
|
foreach ($data->results as $s) |
|
272
|
|
|
{ |
|
273
|
1 |
|
$movie = new ResultMovie($this->tmdb, $s); |
|
274
|
1 |
|
yield $movie; |
|
275
|
|
|
} |
|
276
|
1 |
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.