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