| 1: | <?php |
| 2: | namespace Duyplus\TMDBApi\Classes\Data; |
| 3: | |
| 4: | use Duyplus\TMDBApi\Classes\Data\Company; |
| 5: | use Duyplus\TMDBApi\Classes\Data\Genre; |
| 6: | use Duyplus\TMDBApi\Classes\Data\Person; |
| 7: | use Duyplus\TMDBApi\Classes\Data\Review; |
| 8: | |
| 9: | class Movie extends ApiBaseObject |
| 10: | { |
| 11: | // Media Type |
| 12: | const MEDIA_TYPE_MOVIE = 'movie'; |
| 13: | |
| 14: | /** |
| 15: | * Get the Movie's title |
| 16: | * |
| 17: | * @return string |
| 18: | */ |
| 19: | public function getTitle() |
| 20: | { |
| 21: | return $this->crawl['title']; |
| 22: | } |
| 23: | |
| 24: | /** |
| 25: | * Get the Movie's tagline |
| 26: | * |
| 27: | * @return string |
| 28: | */ |
| 29: | public function getTagline() |
| 30: | { |
| 31: | return $this->crawl['tagline']; |
| 32: | } |
| 33: | |
| 34: | /** |
| 35: | * Get the Movie Director's IDs |
| 36: | * |
| 37: | * @return array |
| 38: | */ |
| 39: | public function getDirectorIds() |
| 40: | { |
| 41: | $director_ids = []; |
| 42: | |
| 43: | $crew = $this->crawl['credits']['crew']; |
| 44: | |
| 45: | foreach ($crew as $crew_member) { |
| 46: | if ($crew_member['job'] === 'Director') { |
| 47: | $director_ids[] = $crew_member['id']; |
| 48: | } |
| 49: | } |
| 50: | |
| 51: | return $director_ids; |
| 52: | } |
| 53: | |
| 54: | /** |
| 55: | * Get the Trailers |
| 56: | * |
| 57: | * @return array |
| 58: | */ |
| 59: | public function getTrailers() |
| 60: | { |
| 61: | if (isset($this->crawl['trailers'])) { |
| 62: | return $this->crawl['trailers']; |
| 63: | } |
| 64: | |
| 65: | return []; |
| 66: | } |
| 67: | |
| 68: | /** |
| 69: | * Get the Trailer |
| 70: | * |
| 71: | * @return string |
| 72: | */ |
| 73: | public function getTrailer() |
| 74: | { |
| 75: | $trailers = $this->getTrailers(); |
| 76: | |
| 77: | if (count($trailers) > 0) { |
| 78: | $trailer = $trailers[0]; |
| 79: | return $trailer['url']; |
| 80: | } |
| 81: | |
| 82: | return ''; |
| 83: | } |
| 84: | |
| 85: | /** |
| 86: | * Get the Movie's Genres |
| 87: | * |
| 88: | * @return Genre[] |
| 89: | */ |
| 90: | public function getGenres() |
| 91: | { |
| 92: | $genres = []; |
| 93: | |
| 94: | foreach ($this->crawl['genres'] as $data) { |
| 95: | $genres[] = new Genre($data); |
| 96: | } |
| 97: | |
| 98: | return $genres; |
| 99: | } |
| 100: | |
| 101: | /** |
| 102: | * Get the Movie's Reviews |
| 103: | * |
| 104: | * @return Review[] |
| 105: | */ |
| 106: | public function getReviews() |
| 107: | { |
| 108: | $reviews = []; |
| 109: | |
| 110: | if (!empty($this->crawl['reviews']['results'])) { |
| 111: | foreach ($this->crawl['reviews']['results'] as $data) { |
| 112: | $reviews[] = new Review($data); |
| 113: | } |
| 114: | } |
| 115: | |
| 116: | return $reviews; |
| 117: | } |
| 118: | |
| 119: | /** |
| 120: | * Get the Movie's Companies |
| 121: | * |
| 122: | * @return Company[] |
| 123: | */ |
| 124: | public function getCompanies() |
| 125: | { |
| 126: | $companies = []; |
| 127: | |
| 128: | if (!empty($this->crawl['production_companies'])) { |
| 129: | foreach ($this->crawl['production_companies'] as $data) { |
| 130: | $companies[] = new Company($data); |
| 131: | } |
| 132: | } |
| 133: | |
| 134: | return $companies; |
| 135: | } |
| 136: | |
| 137: | /** |
| 138: | * Set the TMDB API |
| 139: | * |
| 140: | * @param \Duyplus\TMDBApi\TMDB $tmdb TMDB API Object |
| 141: | */ |
| 142: | public function setAPI($tmdb) |
| 143: | { |
| 144: | $this->_tmdb = $tmdb; |
| 145: | } |
| 146: | |
| 147: | /** |
| 148: | * Get the Movie's Cast |
| 149: | * |
| 150: | * @return Person[] |
| 151: | */ |
| 152: | public function getCast() |
| 153: | { |
| 154: | $cast = []; |
| 155: | |
| 156: | foreach ($this->crawl['credits']['cast'] as $data) { |
| 157: | $cast[] = new Person($data); |
| 158: | } |
| 159: | |
| 160: | return $cast; |
| 161: | } |
| 162: | |
| 163: | /** |
| 164: | * Get the JSON representation of the Movie |
| 165: | * |
| 166: | * @return string |
| 167: | */ |
| 168: | public function getJSON() |
| 169: | { |
| 170: | return json_encode($this->crawl, JSON_PRETTY_PRINT); |
| 171: | } |
| 172: | |
| 173: | /** |
| 174: | * Get the Media Type |
| 175: | * |
| 176: | * @return string |
| 177: | */ |
| 178: | public function getMediaType() |
| 179: | { |
| 180: | return self::MEDIA_TYPE_MOVIE; |
| 181: | } |
| 182: | } |