|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace vfalies\tmdb\Items; |
|
4
|
|
|
|
|
5
|
|
|
use vfalies\tmdb\Abstracts\Item; |
|
6
|
|
|
use vfalies\tmdb\Interfaces\Items\TVShowInterface; |
|
7
|
|
|
use vfalies\tmdb\Tmdb; |
|
8
|
|
|
use vfalies\tmdb\Traits\ElementTrait; |
|
9
|
|
|
use vfalies\tmdb\lib\Guzzle\Client as HttpClient; |
|
10
|
|
|
use vfalies\tmdb\Results\TVSeason; |
|
|
|
|
|
|
11
|
|
|
use vfalies\tmdb\Results\Image; |
|
12
|
|
|
|
|
13
|
|
|
class TVShow extends Item implements TVShowInterface |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
use ElementTrait; |
|
17
|
|
|
|
|
18
|
32 |
|
public function __construct(Tmdb $tmdb, $tv_id, array $options = array()) |
|
19
|
|
|
{ |
|
20
|
32 |
|
parent::__construct($tmdb, $tv_id, $options, 'tv'); |
|
21
|
31 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Get TV show id |
|
25
|
|
|
* @return int |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function getId() |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->id; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Get TVSHow genres |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
2 |
|
public function getGenres() |
|
37
|
|
|
{ |
|
38
|
2 |
|
if (isset($this->data->genres)) { |
|
39
|
1 |
|
return $this->data->genres; |
|
40
|
|
|
} |
|
41
|
1 |
|
return []; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get TVshow note |
|
46
|
|
|
* @return float |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function getNote() |
|
49
|
|
|
{ |
|
50
|
2 |
|
if (isset($this->data->vote_average)) { |
|
51
|
1 |
|
return $this->data->vote_average; |
|
52
|
|
|
} |
|
53
|
1 |
|
return 0; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get TVshow number of episodes |
|
58
|
|
|
* @return int |
|
59
|
|
|
*/ |
|
60
|
2 |
|
public function getNumberEpisodes() |
|
61
|
|
|
{ |
|
62
|
2 |
|
if (isset($this->data->number_of_episodes)) { |
|
63
|
1 |
|
return $this->data->number_of_episodes; |
|
64
|
|
|
} |
|
65
|
1 |
|
return 0; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get TVShow number of seasons |
|
70
|
|
|
* @return int |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function getNumberSeasons() |
|
73
|
|
|
{ |
|
74
|
2 |
|
if (isset($this->data->number_of_seasons)) { |
|
75
|
1 |
|
return $this->data->number_of_seasons; |
|
76
|
|
|
} |
|
77
|
1 |
|
return 0; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get TVShow original title |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
2 |
|
public function getOriginalTitle() |
|
85
|
|
|
{ |
|
86
|
2 |
|
if (isset($this->data->original_name)) { |
|
87
|
1 |
|
return $this->data->original_name; |
|
88
|
|
|
} |
|
89
|
1 |
|
return ''; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get TVShow overview |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
2 |
|
public function getOverview() |
|
97
|
|
|
{ |
|
98
|
2 |
|
if (isset($this->data->overview)) { |
|
99
|
1 |
|
return $this->data->overview; |
|
100
|
|
|
} |
|
101
|
1 |
|
return ''; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Get TVShow release date |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
2 |
|
public function getReleaseDate() |
|
109
|
|
|
{ |
|
110
|
2 |
|
if (isset($this->data->first_air_date)) { |
|
111
|
1 |
|
return $this->data->first_air_date; |
|
112
|
|
|
} |
|
113
|
1 |
|
return ''; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Get TVShow status |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
2 |
|
public function getStatus() |
|
121
|
|
|
{ |
|
122
|
2 |
|
if (isset($this->data->status)) { |
|
123
|
1 |
|
return $this->data->status; |
|
124
|
|
|
} |
|
125
|
1 |
|
return ''; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Get TVShow title |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
2 |
|
public function getTitle() |
|
133
|
|
|
{ |
|
134
|
2 |
|
if (isset($this->data->name)) { |
|
135
|
1 |
|
return $this->data->name; |
|
136
|
|
|
} |
|
137
|
1 |
|
return ''; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Get TVShow seasons |
|
142
|
|
|
* @return \Generator |
|
143
|
|
|
* @throws \Exception |
|
144
|
|
|
*/ |
|
145
|
6 |
|
public function getSeasons() |
|
146
|
|
|
{ |
|
147
|
6 |
|
if (!empty($this->data->seasons)) { |
|
148
|
5 |
|
foreach ($this->data->seasons as $season) { |
|
149
|
5 |
|
$season = new TVSeason($this->tmdb, $season); |
|
150
|
5 |
|
yield $season; |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
2 |
|
} |
|
154
|
|
|
|
|
155
|
1 |
|
public function getBackdrops() |
|
156
|
|
|
{ |
|
157
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/'.(int) $this->id.'/images', null, $this->params); |
|
158
|
|
|
|
|
159
|
1 |
|
foreach ($data->backdrops as $b) |
|
160
|
|
|
{ |
|
161
|
1 |
|
$image = new Image($this->tmdb, $this->id, $b); |
|
162
|
1 |
|
yield $image; |
|
163
|
|
|
} |
|
164
|
1 |
|
} |
|
165
|
|
|
|
|
166
|
1 |
|
public function getPosters() |
|
167
|
|
|
{ |
|
168
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/'.(int) $this->id.'/images', null, $this->params); |
|
169
|
|
|
|
|
170
|
1 |
|
foreach ($data->posters as $b) |
|
171
|
|
|
{ |
|
172
|
1 |
|
$image = new Image($this->tmdb, $this->id, $b); |
|
173
|
1 |
|
yield $image; |
|
174
|
|
|
} |
|
175
|
1 |
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: