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\Items; |
16
|
|
|
|
17
|
|
|
use VfacTmdb\Abstracts\Items\TVItem; |
18
|
|
|
use VfacTmdb\Exceptions\TmdbException; |
19
|
|
|
use VfacTmdb\Interfaces\Items\TVSeasonInterface; |
20
|
|
|
use VfacTmdb\Results; |
21
|
|
|
use VfacTmdb\Interfaces\TmdbInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* TVSeason class |
25
|
|
|
* @package Tmdb |
26
|
|
|
* @author Vincent Faliès <[email protected]> |
27
|
|
|
* @copyright Copyright (c) 2017 |
28
|
|
|
*/ |
29
|
|
|
class TVSeason extends TVItem implements TVSeasonInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Season number |
34
|
|
|
* @var int |
35
|
|
|
*/ |
36
|
|
|
protected $season_number; |
37
|
|
|
/** |
38
|
|
|
* TVShow Id |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
protected $tv_id; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Constructor |
45
|
|
|
* @param TmdbInterface $tmdb |
46
|
|
|
* @param int $tv_id |
47
|
|
|
* @param int $season_number |
48
|
|
|
* @param array $options |
49
|
|
|
* @throws TmdbException |
50
|
|
|
*/ |
51
|
35 |
|
public function __construct(TmdbInterface $tmdb, int $tv_id, int $season_number, array $options = array()) |
52
|
|
|
{ |
53
|
35 |
|
parent::__construct($tmdb, $season_number, $options, 'tv/' . $tv_id . '/season'); |
54
|
|
|
|
55
|
35 |
|
$this->season_number = $season_number; |
56
|
35 |
|
$this->tv_id = $tv_id; |
57
|
|
|
|
58
|
35 |
|
$this->setElementTrait($this->data); |
59
|
35 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Id |
63
|
|
|
* @return int |
64
|
|
|
*/ |
65
|
3 |
|
public function getId() : int |
66
|
|
|
{ |
67
|
3 |
|
if (!empty($this->data->id)) { |
68
|
2 |
|
return (int) $this->data->id; |
69
|
|
|
} |
70
|
1 |
|
return 0; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Air date |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
2 |
|
public function getAirDate() : string |
78
|
|
|
{ |
79
|
2 |
|
if (!empty($this->data->air_date)) { |
80
|
1 |
|
return $this->data->air_date; |
81
|
|
|
} |
82
|
1 |
|
return ''; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Episode count |
87
|
|
|
* @return int |
88
|
|
|
*/ |
89
|
2 |
|
public function getEpisodeCount() : int |
90
|
|
|
{ |
91
|
2 |
|
if (!empty($this->data->episodes)) { |
92
|
1 |
|
return count($this->data->episodes); |
93
|
|
|
} |
94
|
1 |
|
return 0; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Season number |
99
|
|
|
* @return int |
100
|
|
|
*/ |
101
|
2 |
|
public function getSeasonNumber() : int |
102
|
|
|
{ |
103
|
2 |
|
if (!empty($this->data->season_number)) { |
104
|
1 |
|
return (int) $this->data->season_number; |
105
|
|
|
} |
106
|
1 |
|
return 0; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Episodes list |
111
|
|
|
* @return \Generator|Results\TVEpisode |
112
|
|
|
*/ |
113
|
21 |
|
public function getEpisodes() : \Generator |
114
|
|
|
{ |
115
|
21 |
|
if (!empty($this->data->episodes)) { |
116
|
20 |
|
foreach ($this->data->episodes as $episode) { |
117
|
20 |
|
$episode = new Results\TVEpisode($this->tmdb, $episode); |
118
|
20 |
|
yield $episode; |
119
|
|
|
} |
120
|
|
|
} |
121
|
2 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Name |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
2 |
|
public function getName() : string |
128
|
|
|
{ |
129
|
2 |
|
if (!empty($this->data->name)) { |
130
|
1 |
|
return $this->data->name; |
131
|
|
|
} |
132
|
1 |
|
return ''; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Overview |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
2 |
|
public function getOverview() : string |
140
|
|
|
{ |
141
|
2 |
|
if (!empty($this->data->overview)) { |
142
|
1 |
|
return $this->data->overview; |
143
|
|
|
} |
144
|
1 |
|
return ''; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|