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: class Person
8: {
9: // Media Type
10: const MEDIA_TYPE_PERSON = 'person';
11:
12: //------------------------------------------------------------------------------
13: // Class Variables
14: //------------------------------------------------------------------------------
15:
16: private $crawl;
17:
18: /**
19: * Construct Class
20: *
21: * @param array $data An array with the data of the Person
22: */
23: public function __construct($data)
24: {
25: $this->crawl = $data;
26: }
27:
28: //------------------------------------------------------------------------------
29: // Get Variables
30: //------------------------------------------------------------------------------
31:
32: /**
33: * Get the Person's name
34: *
35: * @return string
36: */
37: public function getName()
38: {
39: return $this->crawl['name'];
40: }
41:
42: /**
43: * Get the Person's id
44: *
45: * @return int
46: */
47: public function getID()
48: {
49: return $this->crawl['id'];
50: }
51:
52: /**
53: * Get the Person's profile image
54: *
55: * @return string
56: */
57: public function getProfile()
58: {
59: return $this->crawl['profile_path'];
60: }
61:
62: /**
63: * Get the Person's birthday
64: *
65: * @return string
66: */
67: public function getBirthday()
68: {
69: return $this->crawl['birthday'];
70: }
71:
72: /**
73: * Get the Person's place of birth
74: *
75: * @return string
76: */
77: public function getPlaceOfBirth()
78: {
79: return $this->crawl['place_of_birth'];
80: }
81:
82: /**
83: * Get the Person's imdb id
84: *
85: * @return string
86: */
87: public function getImbdID()
88: {
89: return $this->crawl['imdb_id'];
90: }
91:
92: /**
93: * Get the Person's popularity
94: *
95: * @return int
96: */
97: public function getPopularity()
98: {
99: return $this->crawl['popularity'];
100: }
101:
102: /**
103: * Get the Person's job
104: *
105: * @return string
106: */
107: public function getJob()
108: {
109: return $this->crawl['job'];
110: }
111:
112: /**
113: * Get the Person's movie roles
114: *
115: * @return MovieRole[]
116: */
117: public function getMovieRoles()
118: {
119: $movieRoles = array();
120:
121: foreach ($this->crawl['movie_credits']['cast'] as $data) {
122: $movieRoles[] = new MovieRole($data);
123: }
124:
125: return $movieRoles;
126: }
127:
128: /**
129: * Get the Person's TV show roles
130: *
131: * @return TVShowRole[]
132: */
133: public function getTVShowRoles()
134: {
135: $tvShowRole = array();
136:
137: foreach ($this->crawl['tv_credits']['cast'] as $data) {
138: $tvShowRole[] = new TVShowRole($data);
139: }
140:
141: return $tvShowRole;
142: }
143:
144: /**
145: * Get Generic.
146: * Get a item of the array, you should not get used to use this, better use specific get's.
147: *
148: * @param string $item The item of the $data array you want
149: * @return array|mixed|null Returns the entire data array, a specific item, or null if the item does not exist.
150: */
151: public function get($item = '')
152: {
153: if (empty($item)) {
154: return $this->crawl;
155: }
156: if (array_key_exists($item, $this->crawl)) {
157: return $this->crawl[$item];
158: }
159: return null;
160: }
161:
162: /**
163: * Get the JSON representation of the Episode
164: *
165: * @return string
166: */
167: public function getJSON()
168: {
169: return json_encode($this->crawl, JSON_PRETTY_PRINT);
170: }
171:
172: /**
173: * Get the Media Type
174: *
175: * @return string
176: */
177: public function getMediaType()
178: {
179: return self::MEDIA_TYPE_PERSON;
180: }
181: }