diff --git a/examples/movies/model/get.php b/examples/movies/model/get.php index 2fb7610a..cd96e907 100644 --- a/examples/movies/model/get.php +++ b/examples/movies/model/get.php @@ -30,18 +30,17 @@ \Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRANSLATIONS, )); -$movie = \Tmdb\Model\Movie::load($client, 87421, array($append, $language)); - +$movie = \Tmdb\Model\Movie::load($client, 87421, array($append)); echo $movie->getTitle() . "\n"; echo "Cast\n"; -foreach($movie->getCast() as $person) { +foreach($movie->credits->cast as $person) { printf(" - %s as %s\n", $person->getName(), $person->getCharacter()); } -foreach($movie->getCrew() as $person) { +foreach($movie->getCredits()->getCrew() as $person) { printf(" - %s as %s\n", $person->getName(), $person->getJob()); } diff --git a/lib/Tmdb/Model/AbstractModel.php b/lib/Tmdb/Model/AbstractModel.php index 664157b0..b7615184 100644 --- a/lib/Tmdb/Model/AbstractModel.php +++ b/lib/Tmdb/Model/AbstractModel.php @@ -15,12 +15,14 @@ use Tmdb\Client; use Tmdb\Exception\RuntimeException; -use Tmdb\Model\Common\Collection\Credits\Cast; -use Tmdb\Model\Common\Collection\Credits\Crew; -use Tmdb\Model\Common\Collection\Genres; +use Tmdb\Model\Collection\Credits\Cast; +use Tmdb\Model\Collection\Credits\Crew; +use Tmdb\Model\Collection\Genres; +use Tmdb\Model\Collection\People; + use Tmdb\Model\Common\Collection\Images; -use Tmdb\Model\Common\Collection\People; +use Tmdb\Model\Common\Collection; use Tmdb\Model\Common\QueryParameter\QueryParameterInterface; use Tmdb\Model\Person\CastMember; use Tmdb\Model\Person\CrewMember; @@ -124,7 +126,7 @@ protected function parseQueryParameters(array $parameters = array()) * * @param $client * @param array $collection - * @return Images + * @return Image[] */ protected function collectImages($client, array $collection = array()) { @@ -152,7 +154,7 @@ protected function collectImages($client, array $collection = array()) * * @param $client * @param array $collection - * @return People + * @return Person[] */ protected function collectPeople($client, array $collection = array()) { @@ -172,7 +174,7 @@ protected function collectPeople($client, array $collection = array()) * * @param $client * @param array $collection - * @return People + * @return CastMember[] */ protected function collectCast($client, array $collection = array()) { @@ -192,7 +194,7 @@ protected function collectCast($client, array $collection = array()) * * @param $client * @param array $collection - * @return People + * @return CrewMember[] */ protected function collectCrew($client, array $collection = array()) { @@ -212,7 +214,7 @@ protected function collectCrew($client, array $collection = array()) * * @param $client * @param array $collection - * @return People + * @return Genre[] */ protected function collectGenres($client, array $collection = array()) { @@ -226,6 +228,28 @@ protected function collectGenres($client, array $collection = array()) return $genres; } + /** + * Collect all genres from an array + * + * @param $client + * @param array $collection + * @param object $object + * @return Collection + */ + protected function collectGenericCollection($client, array $collection = array(), $object) + { + $collectionObject = new Collection(); + + foreach($collection as $item) { + $class = get_class($object); + $model = $class::fromArray($client, $item); + + $collectionObject->addObject($model); + } + + return $collectionObject; + } + /** * Transforms an under_scored_string to a camelCasedOne * diff --git a/lib/Tmdb/Model/Collection/Credits.php b/lib/Tmdb/Model/Collection/Credits.php index 9b90e63c..3368c8ec 100644 --- a/lib/Tmdb/Model/Collection/Credits.php +++ b/lib/Tmdb/Model/Collection/Credits.php @@ -19,13 +19,22 @@ class Credits { /** * @var Cast */ - private $cast; + public $cast; /** * @var Crew */ private $crew; + /** + * Constructor + */ + public function __construct() + { + $this->cast = new Cast(); + $this->crew = new Crew(); + } + /** * @param \Tmdb\Model\Collection\People\Cast $cast * @return $this diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index d44742d6..823d1585 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -18,14 +18,13 @@ use Tmdb\Model\Common\Collection\Images; use Tmdb\Model\Collection\Credits; -use Tmdb\Model\Collection\Credits\Cast; -use Tmdb\Model\Collection\Credits\Crew; use Tmdb\Model\Collection\Genres; use Tmdb\Model\Collection\People; use Tmdb\Model\Common\Country; use Tmdb\Model\Common\SpokenLanguage; +use Tmdb\Model\Movie\AlternativeTitle; class Movie extends AbstractModel { @@ -52,7 +51,7 @@ class Movie extends AbstractModel { /** * Genres * - * @var Common\Genres + * @var Genres */ private $genres; @@ -132,7 +131,7 @@ class Movie extends AbstractModel { private $tagline; /** - * @var title + * @var string */ private $title; @@ -159,14 +158,14 @@ class Movie extends AbstractModel { /** * Credits * - * @var Common\Collection\Credits + * @var Credits */ protected $credits; /** * Images * - * @var Common\Collection\Images + * @var Images */ protected $images; @@ -210,7 +209,7 @@ class Movie extends AbstractModel { 'backdrop_path', 'belongs_to_collection', 'budget', - 'genres', +// 'genres', // populated by the fromArray method 'homepage', 'id', 'imdb_id', @@ -218,27 +217,27 @@ class Movie extends AbstractModel { 'overview', 'popularity', 'poster_path', - 'production_companies', - 'production_countries', - 'release_date', +// 'production_companies', // populated by the fromArray method +// 'production_countries', // populated by the fromArray method +// 'release_date', // populated by the fromArray method 'revenue', 'runtime', - 'spoken_languages', +// 'spoken_languages', // populated by the fromArray method 'status', 'tagline', 'title', 'vote_average', 'vote_count', 'alternative_titles', - 'changes', +// 'changes', // populated by the fromArray method 'credits', - 'images', - 'keywords', - 'lists', - 'releases', - 'similar_movies', - 'trailers', - 'translations', +// 'images', // populated by the fromArray method +// 'keywords', // populated by the fromArray method +// 'lists', // populated by the fromArray method +// 'releases', // populated by the fromArray method +// 'similar_movies', // populated by the fromArray method +// 'trailers', // populated by the fromArray method +// 'translations', // populated by the fromArray method ); /** @@ -246,12 +245,9 @@ class Movie extends AbstractModel { */ public function __construct() { - $this->genres = new Common\Collection\Genres(); - $this->images = new Common\Collection\Images(); - $this->credits = new Common\Collection\Credits(); - - $this->credits->setCast(new Cast()); - $this->credits->setCrew(new Crew()); + $this->genres = new Genres(); + $this->images = new Images(); + $this->credits = new Credits(); } /** @@ -266,10 +262,18 @@ public static function fromArray(Client $client, array $data) $movie = new Movie($data['id']); //$movie->setClient($client); - $casts = array(); - if (array_key_exists('alternative_titles', $data)) { - $movie->setAlternativeTitles(parent::collectAlternativeTitles($client, $data['alternative_titles'])); + + if (array_key_exists('alternative_titles', $data) && array_key_exists('titles', $data['alternative_titles'])) { + $movie->setAlternativeTitles(parent::collectGenericCollection($client, $data['alternative_titles']['titles'], new AlternativeTitle())); + } + + $casts = array(); + $credits = $movie->getCredits(); + + /** Credits */ + if (array_key_exists('credits', $data)) { + $casts = $data['credits']; } if (array_key_exists('casts', $data)) { @@ -277,21 +281,26 @@ public static function fromArray(Client $client, array $data) } if (array_key_exists('cast', $casts)) { - $movie->setCast(parent::collectCast($client, $casts['cast'])); + $credits->setCast(parent::collectCast($client, $casts['cast'])); } if (array_key_exists('crew', $casts)) { - $movie->setCrew(parent::collectCrew($client, $casts['crew'])); + $credits->setCrew(parent::collectCrew($client, $casts['crew'])); } + $movie->setCredits($credits); + + /** Genres */ if (array_key_exists('genres', $data)) { $movie->setGenres(parent::collectGenres($client, $data['genres'])); } + /** Images */ if (array_key_exists('images', $data)) { $movie->setImages(parent::collectImages($client, $data['images'])); } + /** Keywords */ if (array_key_exists('keywords', $data)) { } @@ -771,7 +780,7 @@ public function getVoteCount() */ public function setCast(People $cast) { - $this->cast = $cast; + $this->credits->setCast($cast); return $this; } @@ -780,7 +789,7 @@ public function setCast(People $cast) */ public function getCast() { - return $this->cast; + return $this->credits->getCast(); } /** @@ -789,7 +798,7 @@ public function getCast() */ public function setCrew($crew) { - $this->crew = $crew; + $this->credits->setCrew($crew); return $this; } @@ -798,7 +807,168 @@ public function setCrew($crew) */ public function getCrew() { - return $this->crew; + return $this->credits->getCrew(); + } + + /** + * @param \Tmdb\Model\Common\Collection $alternativeTitles + * @return $this + */ + public function setAlternativeTitles($alternativeTitles) + { + $this->alternativeTitles = $alternativeTitles; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getAlternativeTitles() + { + return $this->alternativeTitles; + } + + /** + * @param int $budget + * @return $this + */ + public function setBudget($budget) + { + $this->budget = $budget; + return $this; + } + + /** + * @return int + */ + public function getBudget() + { + return $this->budget; + } + + /** + * @param Credits $credits + * @return $this + */ + public function setCredits($credits) + { + $this->credits = $credits; + return $this; + } + + /** + * @return Credits + */ + public function getCredits() + { + return $this->credits; + } + + /** + * @param \Tmdb\Model\Common\Collection $keywords + * @return $this + */ + public function setKeywords($keywords) + { + $this->keywords = $keywords; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * @param \Tmdb\Model\Common\Collection $lists + * @return $this + */ + public function setLists($lists) + { + $this->lists = $lists; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getLists() + { + return $this->lists; + } + + /** + * @param \Tmdb\Model\Common\Collection $releases + * @return $this + */ + public function setReleases($releases) + { + $this->releases = $releases; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getReleases() + { + return $this->releases; + } + + /** + * @param \Tmdb\Model\Common\Collection $similarMovies + * @return $this + */ + public function setSimilarMovies($similarMovies) + { + $this->similarMovies = $similarMovies; + return $this; } + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getSimilarMovies() + { + return $this->similarMovies; + } + + /** + * @param \Tmdb\Model\Common\Collection $trailers + * @return $this + */ + public function setTrailers($trailers) + { + $this->trailers = $trailers; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getTrailers() + { + return $this->trailers; + } + + /** + * @param \Tmdb\Model\Common\Collection $translations + * @return $this + */ + public function setTranslations($translations) + { + $this->translations = $translations; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getTranslations() + { + return $this->translations; + } } \ No newline at end of file diff --git a/lib/Tmdb/Model/Movie/AlternativeTitle.php b/lib/Tmdb/Model/Movie/AlternativeTitle.php index 808bf6cd..183cebff 100644 --- a/lib/Tmdb/Model/Movie/AlternativeTitle.php +++ b/lib/Tmdb/Model/Movie/AlternativeTitle.php @@ -10,18 +10,19 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model; +namespace Tmdb\Model\Movie; use Tmdb\Client; +use Tmdb\Model\AbstractModel; class AlternativeTitle extends AbstractModel { - private $id; - private $name; + private $iso31661; + private $title; protected static $_properties = array( - 'id', - 'name', + 'iso_3166_1', + 'title', ); /** @@ -40,39 +41,39 @@ public static function fromArray(Client $client, array $data) } /** - * @param mixed $id + * @param mixed $iso31661 * @return $this */ - public function setId($id) + public function setIso31661($iso31661) { - $this->id = (int) $id; + $this->iso31661 = $iso31661; return $this; } /** * @return mixed */ - public function getId() + public function getIso31661() { - return $this->id; + return $this->iso31661; } /** - * @param mixed $name + * @param mixed $title * @return $this */ - public function setName($name) + public function setTitle($title) { - $this->name = $name; + $this->title = $title; return $this; } /** * @return mixed */ - public function getName() + public function getTitle() { - return $this->name; + return $this->title; } diff --git a/lib/Tmdb/Model/Person/CastMember.php b/lib/Tmdb/Model/Person/CastMember.php index 86cf2f33..c248a93a 100644 --- a/lib/Tmdb/Model/Person/CastMember.php +++ b/lib/Tmdb/Model/Person/CastMember.php @@ -13,7 +13,7 @@ namespace Tmdb\Model\Person; use Tmdb\Client; -use Tmdb\Model\Common\People\PersonInterface; +use Tmdb\Model\Collection\People\PersonInterface; class CastMember extends AbstractMember implements PersonInterface { diff --git a/lib/Tmdb/Model/Person/CrewMember.php b/lib/Tmdb/Model/Person/CrewMember.php index af53e498..7a027bd5 100644 --- a/lib/Tmdb/Model/Person/CrewMember.php +++ b/lib/Tmdb/Model/Person/CrewMember.php @@ -13,7 +13,7 @@ namespace Tmdb\Model\Person; use Tmdb\Client; -use Tmdb\Model\Common\People\PersonInterface; +use Tmdb\Model\Collection\People\PersonInterface; class CrewMember extends AbstractMember implements PersonInterface {