1: <?php
2: namespace duyplus\tmdbapi\classes\data;
3:
4: use duyplus\tmdbapi\classes\data\Episode;
5:
6: /**
7: * This class handles all the data you can get from the api Configuration
8: *
9: * @package TMDB_V3_API_PHP
10: * @author Alvaro Octal
11: * @version 0.7
12: * @date 20/01/2015
13: * @updated 31/12/2024
14: * @link https://github.com/duyplus/tmdbapi
15: * @copyright Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php)
16: */
17:
18: class Season
19: {
20: //------------------------------------------------------------------------------
21: // Class Variables
22: //------------------------------------------------------------------------------
23:
24: private $_data;
25: private $_idTVShow;
26:
27: /**
28: * Construct Class
29: *
30: * @param array $data An array with the data of the Season
31: */
32: public function __construct($data, $idTVShow = 0)
33: {
34: $this->_data = $data;
35: $this->_data['tvshow_id'] = $idTVShow;
36: }
37:
38: //------------------------------------------------------------------------------
39: // Get Variables
40: //------------------------------------------------------------------------------
41:
42: /**
43: * Get the Season's id
44: *
45: * @return int
46: */
47: public function getID()
48: {
49: return $this->_data['id'];
50: }
51:
52: /**
53: * Get the Season's name
54: *
55: * @return string
56: */
57: public function getName()
58: {
59: return $this->_data['name'];
60: }
61:
62: /**
63: * Get the Season's TVShow id
64: *
65: * @return int
66: */
67: public function getTVShowID()
68: {
69: return $this->_data['tvshow_id'];
70: }
71:
72: /**
73: * Get the Season's number
74: *
75: * @return int
76: */
77: public function getSeasonNumber()
78: {
79: return $this->_data['season_number'];
80: }
81:
82: /**
83: * Get the Season's number of episodes
84: *
85: * @return int
86: */
87: public function getNumEpisodes()
88: {
89: return count($this->_data['episodes']);
90: }
91:
92: /**
93: * Get a Seasons's Episode
94: *
95: * @param int $numEpisode The episode number
96: * @return int
97: */
98: public function getEpisode($numEpisode)
99: {
100: return new Episode($this->_data['episodes'][$numEpisode]);
101: }
102:
103: /**
104: * Get the Season's Episodes
105: *
106: * @return Episode[]
107: */
108: public function getEpisodes()
109: {
110: $episodes = array();
111: foreach ($this->_data['episodes'] as $data) {
112: $episodes[] = new Episode($data, $this->getTVShowID());
113: }
114: return $episodes;
115: }
116:
117: /**
118: * Get the Seasons's Poster
119: *
120: * @return string
121: */
122: public function getPoster()
123: {
124: return $this->_data['poster_path'];
125: }
126:
127: /**
128: * Get the Season's AirDate
129: *
130: * @return string
131: */
132: public function getAirDate()
133: {
134: return $this->_data['air_date'];
135: }
136:
137: /**
138: * Get Generic.<br>
139: * Get a item of the array, you should not get used to use this, better use specific get's.
140: *
141: * @param string $item The item of the $data array you want
142: * @return array
143: */
144: public function get($item = '')
145: {
146: return (empty($item)) ? $this->_data : $this->_data[$item];
147: }
148:
149: //------------------------------------------------------------------------------
150: // Export
151: //------------------------------------------------------------------------------
152:
153: /**
154: * Get the JSON representation of the Season
155: *
156: * @return string
157: */
158: public function getJSON()
159: {
160: return json_encode($this->_data, JSON_PRETTY_PRINT);
161: }
162: }
163: ?>