diff --git a/examples/movies/model/get.php b/examples/movies/model/get.php index e9791d17..b2960f5d 100644 --- a/examples/movies/model/get.php +++ b/examples/movies/model/get.php @@ -30,27 +30,27 @@ \Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRANSLATIONS, )); -$movie = \Tmdb\Model\Movie::load($client, 87421, array($append)); +$movie = \Tmdb\Factory\MovieFactory::load($client, 87421, array($append)); echo $movie->getTitle() . "\n"; -//echo "Cast\n"; -// -//foreach($movie->credits->cast as $person) { -// printf(" - %s as %s\n", $person->getName(), $person->getCharacter()); -//} -// -//foreach($movie->getCredits()->getCrew() as $person) { -// printf(" - %s as %s\n", $person->getName(), $person->getJob()); -//} -// -//echo "Images\n"; -// -//foreach($movie->getImages() as $image) { -// printf(" - %s\n", $image->getFilePath()); -//} -// -//echo "Genres\n"; +echo "Cast\n"; + +foreach($movie->getCredits()->getCast() as $person) { + printf(" - %s as %s\n", $person->getName(), $person->getCharacter()); +} + +foreach($movie->getCredits()->getCrew() as $person) { + printf(" - %s as %s\n", $person->getName(), $person->getJob()); +} + +echo "Images\n"; + +foreach($movie->getImages() as $image) { + printf(" - %s\n", $image->getFilePath()); +} + +echo "Genres\n"; foreach($movie->getGenres() as $genre) { printf(" - %s\n", $genre->getName()); diff --git a/lib/Tmdb/Factory/People/PeopleFactory.php b/lib/Tmdb/Factory/People/PeopleFactory.php new file mode 100644 index 00000000..28b57220 --- /dev/null +++ b/lib/Tmdb/Factory/People/PeopleFactory.php @@ -0,0 +1,125 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Api\Movies; +use Tmdb\Client; +use Tmdb\Model\Common\Collection; +use Tmdb\Model\Movie; + +class MovieFactory extends AbstractFactory { + /** + * {@inheritdoc} + */ + public static function create(array $data = array()) + { + if (!$data) { + return null; + } + + $movie = new Movie(); + +// if (array_key_exists('alternative_titles', $data) && array_key_exists('titles', $data['alternative_titles'])) { +// $movie->setAlternativeTitles(Movie::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)) { + $casts = $data['casts']; + } + + if (array_key_exists('cast', $casts)) { + $credits->setCast($casts['cast']); + } + + if (array_key_exists('crew', $casts)) { + $credits->setCrew($casts['crew']); + } + + $movie->setCredits($credits); + + /** Genres */ + if (array_key_exists('genres', $data)) { + $movie->setGenres(GenreFactory::createCollection($data['genres'])); + } +// +// /** Images */ +// if (array_key_exists('images', $data)) { +// $movie->setImages(parent::collectImages($client, $data['images'])); +// } +// +// /** Keywords */ +// if (array_key_exists('keywords', $data)) { +// } +// +// if (array_key_exists('releases', $data)) { +// } +// +// if (array_key_exists('trailers', $data)) { +// } +// +// if (array_key_exists('translations', $data)) { +// } +// +// if (array_key_exists('similar_movies', $data)) { +// } +// +// if (array_key_exists('reviews', $data)) { +// } +// +// if (array_key_exists('lists', $data)) { +// } +// +// if (array_key_exists('changes', $data)) { +// } + + return parent::hydrate($movie, $data); + } + + /** + * {@inheritdoc} + */ + public static function createCollection(array $data = array()) + { + $collection = new Collection(); + + foreach($data as $item) { + $collection->add(null, self::create($item)); + } + + return $collection; + } + + + /** + * Load a movie with the given identifier + * + * @param Client $client + * @param $id + * @param $parameters + * @return $this + */ + public static function load(Client $client, $id, array $parameters = array()) { + $data = $client->api('movies')->getMovie($id, parent::parseQueryParameters($parameters)); + + return self::create($data); + } + +} \ No newline at end of file