1: | <?php |
2: | namespace duyplus\tmdbapi\classes\data; |
3: | |
4: | use duyplus\tmdbapi\classes\roles\MovieRole; |
5: | use duyplus\tmdbapi\classes\roles\TVShowRole; |
6: | |
7: | /** |
8: | * This class handles all the data you can get from the api Configuration |
9: | * |
10: | * @package TMDB_V3_API_PHP |
11: | * @author Alvaro Octal |
12: | * @version 0.7 |
13: | * @date 20/01/2015 |
14: | * @updated 31/12/2024 |
15: | * @link https://github.com/duyplus/tmdbapi |
16: | * @copyright Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php) |
17: | */ |
18: | |
19: | class Person |
20: | { |
21: | //------------------------------------------------------------------------------ |
22: | // Class Constants |
23: | //------------------------------------------------------------------------------ |
24: | |
25: | const MEDIA_TYPE_PERSON = 'person'; |
26: | |
27: | const JOB_DIRECTOR = 'Director'; |
28: | |
29: | //------------------------------------------------------------------------------ |
30: | // Class Variables |
31: | //------------------------------------------------------------------------------ |
32: | |
33: | private $_data; |
34: | |
35: | /** |
36: | * Construct Class |
37: | * |
38: | * @param array $data An array with the data of the Person |
39: | */ |
40: | public function __construct($data) |
41: | { |
42: | $this->_data = $data; |
43: | } |
44: | |
45: | //------------------------------------------------------------------------------ |
46: | // Get Variables |
47: | //------------------------------------------------------------------------------ |
48: | |
49: | /** |
50: | * Get the Person's name |
51: | * |
52: | * @return string |
53: | */ |
54: | public function getName() |
55: | { |
56: | return $this->_data['name']; |
57: | } |
58: | |
59: | /** |
60: | * Get the Person's id |
61: | * |
62: | * @return int |
63: | */ |
64: | public function getID() |
65: | { |
66: | return $this->_data['id']; |
67: | } |
68: | |
69: | /** |
70: | * Get the Person's profile image |
71: | * |
72: | * @return string |
73: | */ |
74: | public function getProfile() |
75: | { |
76: | return $this->_data['profile_path']; |
77: | } |
78: | |
79: | /** |
80: | * Get the Person's birthday |
81: | * |
82: | * @return string |
83: | */ |
84: | public function getBirthday() |
85: | { |
86: | return $this->_data['birthday']; |
87: | } |
88: | |
89: | /** |
90: | * Get the Person's place of birth |
91: | * |
92: | * @return string |
93: | */ |
94: | public function getPlaceOfBirth() |
95: | { |
96: | return $this->_data['place_of_birth']; |
97: | } |
98: | |
99: | /** |
100: | * Get the Person's imdb id |
101: | * |
102: | * @return string |
103: | */ |
104: | public function getImbdID() |
105: | { |
106: | return $this->_data['imdb_id']; |
107: | } |
108: | |
109: | /** |
110: | * Get the Person's popularity |
111: | * |
112: | * @return int |
113: | */ |
114: | public function getPopularity() |
115: | { |
116: | return $this->_data['popularity']; |
117: | } |
118: | |
119: | /** |
120: | * Get the Person's popularity |
121: | * |
122: | * @return int |
123: | */ |
124: | public function getJob() |
125: | { |
126: | return $this->_data['job']; |
127: | } |
128: | |
129: | /** |
130: | * Get the Person's MovieRoles |
131: | * |
132: | * @return MovieRole[] |
133: | */ |
134: | public function getMovieRoles() |
135: | { |
136: | $movieRoles = array(); |
137: | foreach ($this->_data['movie_credits']['cast'] as $data) { |
138: | $movieRoles[] = new MovieRole($data, $this->getID()); |
139: | } |
140: | return $movieRoles; |
141: | } |
142: | |
143: | /** |
144: | * Get the Person's TVShowRoles |
145: | * |
146: | * @return TVShowRole[] |
147: | */ |
148: | public function getTVShowRoles() |
149: | { |
150: | $tvShowRole = array(); |
151: | foreach ($this->_data['tv_credits']['cast'] as $data) { |
152: | $tvShowRole[] = new TVShowRole($data, $this->getID()); |
153: | } |
154: | return $tvShowRole; |
155: | } |
156: | |
157: | /** |
158: | * Get Generic.<br> |
159: | * Get a item of the array, you should not get used to use this, better use specific get's. |
160: | * |
161: | * @param string $item The item of the $data array you want |
162: | * @return array |
163: | */ |
164: | public function get($item = '') |
165: | { |
166: | return (empty($item)) ? $this->_data : $this->_data[$item]; |
167: | } |
168: | |
169: | //------------------------------------------------------------------------------ |
170: | // Export |
171: | //------------------------------------------------------------------------------ |
172: | |
173: | /** |
174: | * Get the JSON representation of the Episode |
175: | * |
176: | * @return string |
177: | */ |
178: | public function getJSON() |
179: | { |
180: | return json_encode($this->_data, JSON_PRETTY_PRINT); |
181: | } |
182: | |
183: | |
184: | /** |
185: | * @return string |
186: | */ |
187: | public function getMediaType() |
188: | { |
189: | return self::MEDIA_TYPE_PERSON; |
190: | } |
191: | } |
192: | ?> |