1: | <?php |
2: | namespace Duyplus\TMDBApi\Classes\Data; |
3: | |
4: | use Duyplus\TMDBApi\Classes\Data\Person; |
5: | |
6: | class ApiBaseObject |
7: | { |
8: | //------------------------------------------------------------------------------ |
9: | // Class Constants |
10: | //------------------------------------------------------------------------------ |
11: | |
12: | const MEDIA_TYPE_MOVIE = 'movie'; |
13: | const CREDITS_TYPE_CAST = 'cast'; |
14: | const CREDITS_TYPE_CREW = 'crew'; |
15: | const MEDIA_TYPE_TV = 'tv'; |
16: | |
17: | //------------------------------------------------------------------------------ |
18: | // Class Variables |
19: | //------------------------------------------------------------------------------ |
20: | |
21: | protected $crawl; |
22: | |
23: | /** |
24: | * Construct Class |
25: | * |
26: | * @param array $data An array with the data of the ApiObject |
27: | */ |
28: | public function __construct($data) |
29: | { |
30: | $this->crawl = $data; |
31: | } |
32: | |
33: | /** |
34: | * Get the ApiObject id |
35: | * |
36: | * @return int |
37: | */ |
38: | public function getID() |
39: | { |
40: | return $this->crawl['id']; |
41: | } |
42: | |
43: | /** |
44: | * Get the ApiObject Poster |
45: | * |
46: | * @return string |
47: | */ |
48: | public function getPoster() |
49: | { |
50: | return $this->crawl['poster_path']; |
51: | } |
52: | |
53: | /** |
54: | * Get the ApiObjects vote average |
55: | * |
56: | * @return int |
57: | */ |
58: | public function getVoteAverage() |
59: | { |
60: | return $this->crawl['vote_average']; |
61: | } |
62: | |
63: | /** |
64: | * Get the ApiObjects vote count |
65: | * |
66: | * @return int |
67: | */ |
68: | public function getVoteCount() |
69: | { |
70: | return $this->crawl['vote_count']; |
71: | } |
72: | |
73: | /** |
74: | * Get the ApiObjects Cast |
75: | * @return array of Person |
76: | */ |
77: | public function getCast() |
78: | { |
79: | return $this->getCredits(self::CREDITS_TYPE_CAST); |
80: | } |
81: | |
82: | /** |
83: | * Get the Cast or the Crew of an ApiObject |
84: | * @param string $key |
85: | * @return array of Person |
86: | */ |
87: | protected function getCredits($key) |
88: | { |
89: | $persons = []; |
90: | foreach ($this->crawl['credits'][$key] as $data) { |
91: | $persons[] = new Person($data); |
92: | } |
93: | return $persons; |
94: | } |
95: | |
96: | /** |
97: | * Get the ApiObject crew |
98: | * @return array of Person |
99: | */ |
100: | public function getCrew() |
101: | { |
102: | return $this->getCredits(self::CREDITS_TYPE_CREW); |
103: | } |
104: | |
105: | /** |
106: | * Get Generic. |
107: | * Get a item of the array, you should not get used to use this, better use specific get's. |
108: | * |
109: | * @param string $item The item of the $data array you want |
110: | * @return array|mixed|null Returns the entire data array, a specific item, or null if the item does not exist. |
111: | */ |
112: | public function get($item = '') |
113: | { |
114: | if (empty($item)) { |
115: | return $this->crawl; |
116: | } |
117: | if (array_key_exists($item, $this->crawl)) { |
118: | return $this->crawl[$item]; |
119: | } |
120: | return null; |
121: | } |
122: | } |