|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace vfalies\tmdb\Items; |
|
4
|
|
|
|
|
5
|
|
|
use vfalies\tmdb\Abstracts\Item; |
|
6
|
|
|
use vfalies\tmdb\Interfaces\Items\TVSeasonInterface; |
|
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\TVEpisode; |
|
|
|
|
|
|
11
|
|
|
use vfalies\tmdb\Results\Image; |
|
12
|
|
|
|
|
13
|
|
|
class TVSeason extends Item implements TVSeasonInterface |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
use ElementTrait; |
|
17
|
|
|
|
|
18
|
|
|
protected $season_number; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Constructor |
|
22
|
|
|
* @param \vfalies\tmdb\Tmdb $tmdb |
|
23
|
|
|
* @param int $tv_id |
|
24
|
|
|
* @param int $season_number |
|
25
|
|
|
* @param array $options |
|
26
|
|
|
* @throws Exception |
|
27
|
|
|
*/ |
|
28
|
33 |
|
public function __construct(Tmdb $tmdb, $tv_id, $season_number, array $options = array()) |
|
29
|
|
|
{ |
|
30
|
33 |
|
parent::__construct($tmdb, $season_number, $options, 'tv/'.$tv_id); |
|
31
|
|
|
|
|
32
|
33 |
|
$this->season_number = $season_number; |
|
33
|
33 |
|
} |
|
34
|
|
|
|
|
35
|
2 |
|
public function getId() |
|
36
|
|
|
{ |
|
37
|
2 |
|
if ( ! empty($this->data->id)) |
|
38
|
|
|
{ |
|
39
|
1 |
|
return (int) $this->data->id; |
|
40
|
|
|
} |
|
41
|
1 |
|
return 0; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
2 |
|
public function getAirDate() |
|
45
|
|
|
{ |
|
46
|
2 |
|
if ( ! empty($this->data->air_date)) |
|
47
|
|
|
{ |
|
48
|
1 |
|
return $this->data->air_date; |
|
49
|
|
|
} |
|
50
|
1 |
|
return ''; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
public function getEpisodeCount() |
|
54
|
|
|
{ |
|
55
|
2 |
|
if ( ! empty($this->data->episodes)) |
|
56
|
|
|
{ |
|
57
|
1 |
|
return count($this->data->episodes); |
|
58
|
|
|
} |
|
59
|
1 |
|
return 0; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
2 |
|
public function getSeasonNumber() |
|
63
|
|
|
{ |
|
64
|
2 |
|
if ( ! empty($this->data->season_number)) |
|
65
|
|
|
{ |
|
66
|
1 |
|
return (int) $this->data->season_number; |
|
67
|
|
|
} |
|
68
|
1 |
|
return 0; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
20 |
|
public function getEpisodes() |
|
72
|
|
|
{ |
|
73
|
20 |
|
if ( ! empty($this->data->episodes)) |
|
74
|
|
|
{ |
|
75
|
19 |
|
foreach ($this->data->episodes as $episode) |
|
76
|
|
|
{ |
|
77
|
19 |
|
$episode = new TVEpisode($this->tmdb, $episode); |
|
78
|
19 |
|
yield $episode; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
2 |
|
} |
|
82
|
|
|
|
|
83
|
2 |
|
public function getName() |
|
84
|
|
|
{ |
|
85
|
2 |
|
if ( ! empty($this->data->name)) |
|
86
|
|
|
{ |
|
87
|
1 |
|
return $this->data->name; |
|
88
|
|
|
} |
|
89
|
1 |
|
return ''; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
2 |
|
public function getOverview() |
|
93
|
|
|
{ |
|
94
|
2 |
|
if ( ! empty($this->data->overview)) |
|
95
|
|
|
{ |
|
96
|
1 |
|
return $this->data->overview; |
|
97
|
|
|
} |
|
98
|
1 |
|
return ''; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
View Code Duplication |
public function getPosters() |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/tv/'.(int) $this->id.'/seasons/'.$this->season_number.'/images', null, $this->params); |
|
104
|
|
|
|
|
105
|
1 |
|
foreach ($data->posters as $b) |
|
106
|
|
|
{ |
|
107
|
1 |
|
$image = new Image($this->tmdb, $this->id, $b); |
|
108
|
1 |
|
yield $image; |
|
109
|
|
|
} |
|
110
|
1 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
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: