diff --git a/lib/Tmdb/Factory/PeopleFactory.php b/lib/Tmdb/Factory/PeopleFactory.php index b71103bb..61332812 100644 --- a/lib/Tmdb/Factory/PeopleFactory.php +++ b/lib/Tmdb/Factory/PeopleFactory.php @@ -107,24 +107,39 @@ protected function applyCredits(array $data = array(), Person $person) { $method = $hydrator->camelize(sprintf('get_%s', $type)); if (array_key_exists('cast', $data[$type])) { - $person->$method()->setCast($this->createCollection( + $cast = $this->createGenericCollection( $data[$type]['cast'], - new CastMember(), - new Cast()) + new Person\MovieCredit() ); + + foreach($cast as $member) { + $member->setPosterImage($member->getPosterPath()); + } + + $person->$method()->setCast($cast); } if (array_key_exists('crew', $data[$type])) { - $person->$method()->setCrew($this->createCollection( + $crew = $this->createGenericCollection( $data[$type]['crew'], - new CrewMember(), - new Crew()) + new Person\MovieCredit() ); + + foreach($crew as $member) { + $member->setPosterImage($member->getPosterPath()); + } + + $person->$method()->setCrew($crew); } } } } + protected function getPosterImageForCredit($posterPath) + { + return $this->getImageFactory()->createFromPath($posterPath, 'poster_path'); + } + /** * {@inheritdoc} */ @@ -138,10 +153,11 @@ public function createCollection(array $data = array(), Person\AbstractMember $p $data = $data['results']; } + $class = get_class($person); + foreach($data as $item) { - $collection->add(null, $this->create($item, $person)); + $collection->add(null, $this->create($item, new $class())); } - return $collection; } diff --git a/lib/Tmdb/Model/Collection/CreditsCollection.php b/lib/Tmdb/Model/Collection/CreditsCollection.php index 2d7f5387..55ff55d2 100644 --- a/lib/Tmdb/Model/Collection/CreditsCollection.php +++ b/lib/Tmdb/Model/Collection/CreditsCollection.php @@ -14,6 +14,7 @@ use Tmdb\Model\Collection\People\Cast; use Tmdb\Model\Collection\People\Crew; +use Tmdb\Model\Common\GenericCollection; class CreditsCollection { /** @@ -36,10 +37,10 @@ public function __construct() } /** - * @param Cast $cast + * @param Cast|GenericCollection $cast * @return $this */ - public function setCast(Cast $cast) + public function setCast(GenericCollection $cast) { $this->cast = $cast; return $this; @@ -54,10 +55,10 @@ public function getCast() } /** - * @param Crew $crew + * @param Crew|GenericCollection $crew * @return $this */ - public function setCrew(Crew $crew) + public function setCrew(GenericCollection $crew) { $this->crew = $crew; return $this; diff --git a/lib/Tmdb/Model/Person/MovieCredit.php b/lib/Tmdb/Model/Person/MovieCredit.php new file mode 100644 index 00000000..6740df95 --- /dev/null +++ b/lib/Tmdb/Model/Person/MovieCredit.php @@ -0,0 +1,243 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Person; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image\PosterImage; + +class MovieCredit extends AbstractModel { + + /** + * @var bool + */ + private $adult; + + /** + * @var string + */ + private $character; + + /** + * @var string + */ + private $creditId; + + /** + * @var int + */ + private $id; + + /** + * @var string + */ + private $originalTitle; + + /** + * @var string + */ + private $posterPath; + + /** + * @var \DateTime + */ + private $releaseDate; + + /** + * @var string + */ + private $title; + + /** + * @var PosterImage + */ + private $posterImage; + + public static $_properties = array( + 'adult', + 'character', + 'credit_id', + 'id', + 'original_title', + 'poster_path', + 'release_date', + 'title' + ); + + /** + * @param boolean $adult + * @return $this + */ + public function setAdult($adult) + { + $this->adult = $adult; + return $this; + } + + /** + * @return boolean + */ + public function getAdult() + { + return $this->adult; + } + + /** + * @param string $character + * @return $this + */ + public function setCharacter($character) + { + $this->character = $character; + return $this; + } + + /** + * @return string + */ + public function getCharacter() + { + return $this->character; + } + + /** + * @param string $creditId + * @return $this + */ + public function setCreditId($creditId) + { + $this->creditId = $creditId; + return $this; + } + + /** + * @return string + */ + public function getCreditId() + { + return $this->creditId; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $originalTitle + * @return $this + */ + public function setOriginalTitle($originalTitle) + { + $this->originalTitle = $originalTitle; + return $this; + } + + /** + * @return string + */ + public function getOriginalTitle() + { + return $this->originalTitle; + } + + /** + * @param \Tmdb\Model\Image\PosterImage $posterImage + * @return $this + */ + public function setPosterImage($posterImage) + { + $this->posterImage = $posterImage; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->posterImage; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } + + /** + * @param \DateTime $releaseDate + * @return $this + */ + public function setReleaseDate($releaseDate) + { + if (!$releaseDate instanceof \DateTime) { + $releaseDate = new \DateTime($releaseDate); + } + + $this->releaseDate = $releaseDate; + return $this; + } + + /** + * @return \DateTime + */ + public function getReleaseDate() + { + return $this->releaseDate; + } + + /** + * @param string $title + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + +} diff --git a/lib/Tmdb/Repository/PeopleRepository.php b/lib/Tmdb/Repository/PeopleRepository.php index 716ca3ec..0e1c285d 100644 --- a/lib/Tmdb/Repository/PeopleRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -43,7 +43,6 @@ public function load($id, array $parameters = array(), array $headers = array()) } $data = $this->getApi()->getPerson($id, $this->parseQueryParameters($parameters), $headers); - return $this->getFactory()->create($data); }