1: <?php
2: namespace Duyplus\TMDBApi\Classes\Data;
3:
4: use Duyplus\TMDBApi\Classes\Data\Episode;
5:
6: class Season
7: {
8: //------------------------------------------------------------------------------
9: // Class Variables
10: //------------------------------------------------------------------------------
11:
12: private $crawl;
13: private $idTVS;
14:
15: /**
16: * Construct Class
17: *
18: * @param array $data An array with the data of a Season
19: * @param int $idTVShow The id of the TVShow
20: */
21: public function __construct($data, $idTVShow = 0)
22: {
23: $this->crawl = $data;
24: $this->idTVS = $idTVShow;
25: }
26:
27: //------------------------------------------------------------------------------
28: // Get Variables
29: //------------------------------------------------------------------------------
30:
31: /**
32: * Get the Season's id
33: *
34: * @return int
35: */
36: public function getID()
37: {
38: return $this->crawl['id'];
39: }
40:
41: /**
42: * Get the Season's name
43: *
44: * @return string
45: */
46: public function getName()
47: {
48: return $this->crawl['name'];
49: }
50:
51: /**
52: * Get the TVShow id
53: *
54: * @return int
55: */
56: public function getTVShowID()
57: {
58: return $this->idTVS;
59: }
60:
61: /**
62: * Get the Season's number
63: *
64: * @return int
65: */
66: public function getSeasonNumber()
67: {
68: return $this->crawl['season_number'];
69: }
70:
71: /**
72: * Get the Season's number of episodes
73: *
74: * @return int
75: */
76: public function getNumEpisodes()
77: {
78: return count($this->crawl['episodes']);
79: }
80:
81: /**
82: * Get the Season's episodes
83: *
84: * @param int $numEpisode The episode number
85: * @return Episode
86: */
87: public function getEpisode($numEpisode)
88: {
89: return new Episode($this->crawl['episodes'][$numEpisode], $this->getTVShowID());
90: }
91:
92: /**
93: * Get the Season's episodes
94: *
95: * @return Episode[]
96: */
97: public function getEpisodes()
98: {
99: $episodes = array();
100:
101: foreach ($this->crawl['episodes'] as $data) {
102: $episodes[] = new Episode($data, $this->getTVShowID());
103: }
104:
105: return $episodes;
106: }
107:
108: /**
109: * Get the Season's poster
110: *
111: * @return string
112: */
113: public function getPoster()
114: {
115: return $this->crawl['poster_path'];
116: }
117:
118: /**
119: * Get the Season's AirDate
120: *
121: * @return string
122: */
123: public function getAirDate()
124: {
125: if (isset($this->crawl['air_date'])) {
126: return $this->crawl['air_date'];
127: }
128:
129: return '';
130: }
131:
132: /**
133: * Get Generic.
134: * Get a item of the array, you should not get used to use this, better use specific get's.
135: *
136: * @param string $item The item of the $data array you want
137: * @return array|mixed|null Returns the entire data array, a specific item, or null if the item does not exist.
138: */
139: public function get($item = '')
140: {
141: if (empty($item)) {
142: return $this->crawl;
143: }
144: if (array_key_exists($item, $this->crawl)) {
145: return $this->crawl[$item];
146: }
147: return null;
148: }
149:
150: /**
151: * Get the JSON representation of the Season
152: *
153: * @return string
154: */
155: public function getJSON()
156: {
157: return json_encode($this->crawl, JSON_PRETTY_PRINT);
158: }
159: }