From fa7bad27f00c63d4ca80c993c244db94f1644d0d Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sun, 9 Feb 2014 12:51:59 +0100 Subject: [PATCH] Adding Credits API and renaming the Credits Collection to CreditsCollection --- examples/collection/model/images.php | 22 ++ examples/credits/model/get.php | 22 ++ lib/Tmdb/Factory/CreditsFactory.php | 160 +++++++++++++++ .../{Credits.php => CreditsCollection.php} | 2 +- .../CombinedCredits.php | 6 +- .../MovieCredits.php | 6 +- .../TvCredits.php | 6 +- lib/Tmdb/Model/Credits.php | 194 ++++++++++++++++++ lib/Tmdb/Model/Credits/Media.php | 163 +++++++++++++++ lib/Tmdb/Model/Movie.php | 10 +- lib/Tmdb/Model/Person.php | 30 +-- lib/Tmdb/Model/Tv.php | 8 +- lib/Tmdb/Model/Tv/Episode.php | 4 +- lib/Tmdb/Model/Tv/Season.php | 6 +- lib/Tmdb/Repository/CollectionRepository.php | 31 +-- lib/Tmdb/Repository/CreditsRepository.php | 83 ++++++++ test/Tmdb/Tests/Factory/MovieFactoryTest.php | 2 +- test/Tmdb/Tests/Factory/PeopleFactoryTest.php | 8 +- .../Tests/Factory/TvEpisodeFactoryTest.php | 2 +- .../Tests/Factory/TvSeasonFactoryTest.php | 2 +- test/Tmdb/Tests/Model/MovieTest.php | 8 +- test/Tmdb/Tests/Model/PersonTest.php | 12 +- test/Tmdb/Tests/Model/Tv/EpisodeTest.php | 2 +- test/Tmdb/Tests/Model/Tv/SeasonTest.php | 2 +- test/Tmdb/Tests/Model/TvTest.php | 2 +- 25 files changed, 719 insertions(+), 74 deletions(-) create mode 100644 examples/collection/model/images.php create mode 100644 examples/credits/model/get.php create mode 100644 lib/Tmdb/Factory/CreditsFactory.php rename lib/Tmdb/Model/Collection/{Credits.php => CreditsCollection.php} (97%) rename lib/Tmdb/Model/Collection/{Credits => CreditsCollection}/CombinedCredits.php (69%) rename lib/Tmdb/Model/Collection/{Credits => CreditsCollection}/MovieCredits.php (70%) rename lib/Tmdb/Model/Collection/{Credits => CreditsCollection}/TvCredits.php (70%) create mode 100644 lib/Tmdb/Model/Credits.php create mode 100644 lib/Tmdb/Model/Credits/Media.php create mode 100644 lib/Tmdb/Repository/CreditsRepository.php diff --git a/examples/collection/model/images.php b/examples/collection/model/images.php new file mode 100644 index 00000000..1f8c844c --- /dev/null +++ b/examples/collection/model/images.php @@ -0,0 +1,22 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$repository = new \Tmdb\Repository\CollectionRepository($client); +$collection = $repository->load(10); + +var_dump($collection); \ No newline at end of file diff --git a/examples/credits/model/get.php b/examples/credits/model/get.php new file mode 100644 index 00000000..31b26985 --- /dev/null +++ b/examples/credits/model/get.php @@ -0,0 +1,22 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$repository = new \Tmdb\Repository\CreditsRepository($client); +$credits = $repository->load('52542282760ee313280017f9'); + +var_dump($credits); \ No newline at end of file diff --git a/lib/Tmdb/Factory/CreditsFactory.php b/lib/Tmdb/Factory/CreditsFactory.php new file mode 100644 index 00000000..3d7fcc7a --- /dev/null +++ b/lib/Tmdb/Factory/CreditsFactory.php @@ -0,0 +1,160 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Collection\Genres; +use Tmdb\Model\Genre; +use Tmdb\Model\Movie; +use Tmdb\Model\Credits as Credits; + +class CreditsFactory extends AbstractFactory +{ + /** + * @var TvSeasonFactory + */ + private $tvSeasonFactory; + + /** + * @var TvEpisodeFactory + */ + private $tvEpisodeFactory; + + /** + * @var PeopleFactory + */ + private $peopleFactory; + + public function __construct() + { + $this->tvSeasonFactory = new TvSeasonFactory(); + $this->tvEpisodeFactory = new TvEpisodeFactory(); + $this->peopleFactory = new PeopleFactory(); + } + + /** + * @param array $data + * + * @return Genre + */ + public function create(array $data = array()) + { + $credits = new Credits(); + + if (array_key_exists('media', $data)) { + + $credits->setMedia( + $this->hydrate($credits->getMedia(), $data['media']) + ); + + if (array_key_exists('seasons', $data['media'])) { + $episodes = $this->getTvSeasonFactory()->createCollection($data['media']['seasons']); + $credits->getMedia()->setSeasons($episodes); + } + + if (array_key_exists('episodes', $data['media'])) { + $episodes = $this->getTvEpisodeFactory()->createCollection($data['media']['episodes']); + $credits->getMedia()->setEpisodes($episodes); + } + } + + if (array_key_exists('person', $data)) { + $credits->setPerson( + $this->getPeopleFactory()->create($data['person']) + ); + } + + return $this->hydrate($credits, $data); + } + + /** + * @param array $data + * + * @return Movie + */ + public function createMovie(array $data = array()) + { + return $this->hydrate(new Movie(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new Genres(); + + if (array_key_exists('genres', $data)) { + $data = $data['genres']; + } + + foreach($data as $item) { + $collection->addGenre($this->create($item)); + } + + return $collection; + } + + /** + * @param \Tmdb\Factory\TvEpisodeFactory $tvEpisodeFactory + * @return $this + */ + public function setTvEpisodeFactory($tvEpisodeFactory) + { + $this->tvEpisodeFactory = $tvEpisodeFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\TvEpisodeFactory + */ + public function getTvEpisodeFactory() + { + return $this->tvEpisodeFactory; + } + + /** + * @param \Tmdb\Factory\TvSeasonFactory $tvSeasonFactory + * @return $this + */ + public function setTvSeasonFactory($tvSeasonFactory) + { + $this->tvSeasonFactory = $tvSeasonFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\TvSeasonFactory + */ + public function getTvSeasonFactory() + { + return $this->tvSeasonFactory; + } + + /** + * @param \Tmdb\Factory\PeopleFactory $peopleFactory + * @return $this + */ + public function setPeopleFactory($peopleFactory) + { + $this->peopleFactory = $peopleFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\PeopleFactory + */ + public function getPeopleFactory() + { + return $this->peopleFactory; + } +} diff --git a/lib/Tmdb/Model/Collection/Credits.php b/lib/Tmdb/Model/Collection/CreditsCollection.php similarity index 97% rename from lib/Tmdb/Model/Collection/Credits.php rename to lib/Tmdb/Model/Collection/CreditsCollection.php index 74ead142..2d7f5387 100644 --- a/lib/Tmdb/Model/Collection/Credits.php +++ b/lib/Tmdb/Model/Collection/CreditsCollection.php @@ -15,7 +15,7 @@ use Tmdb\Model\Collection\People\Cast; use Tmdb\Model\Collection\People\Crew; -class Credits { +class CreditsCollection { /** * @var Cast */ diff --git a/lib/Tmdb/Model/Collection/Credits/CombinedCredits.php b/lib/Tmdb/Model/Collection/CreditsCollection/CombinedCredits.php similarity index 69% rename from lib/Tmdb/Model/Collection/Credits/CombinedCredits.php rename to lib/Tmdb/Model/Collection/CreditsCollection/CombinedCredits.php index a94d8ace..413eafe8 100644 --- a/lib/Tmdb/Model/Collection/Credits/CombinedCredits.php +++ b/lib/Tmdb/Model/Collection/CreditsCollection/CombinedCredits.php @@ -10,8 +10,8 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Collection\Credits; +namespace Tmdb\Model\Collection\CreditsCollection; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; -class CombinedCredits extends Credits {} +class CombinedCredits extends CreditsCollection {} diff --git a/lib/Tmdb/Model/Collection/Credits/MovieCredits.php b/lib/Tmdb/Model/Collection/CreditsCollection/MovieCredits.php similarity index 70% rename from lib/Tmdb/Model/Collection/Credits/MovieCredits.php rename to lib/Tmdb/Model/Collection/CreditsCollection/MovieCredits.php index 2430ab43..6f79f005 100644 --- a/lib/Tmdb/Model/Collection/Credits/MovieCredits.php +++ b/lib/Tmdb/Model/Collection/CreditsCollection/MovieCredits.php @@ -10,8 +10,8 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Collection\Credits; +namespace Tmdb\Model\Collection\CreditsCollection; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; -class MovieCredits extends Credits {} +class MovieCredits extends CreditsCollection {} diff --git a/lib/Tmdb/Model/Collection/Credits/TvCredits.php b/lib/Tmdb/Model/Collection/CreditsCollection/TvCredits.php similarity index 70% rename from lib/Tmdb/Model/Collection/Credits/TvCredits.php rename to lib/Tmdb/Model/Collection/CreditsCollection/TvCredits.php index 70c2e852..f24ae5e4 100644 --- a/lib/Tmdb/Model/Collection/Credits/TvCredits.php +++ b/lib/Tmdb/Model/Collection/CreditsCollection/TvCredits.php @@ -10,8 +10,8 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Collection\Credits; +namespace Tmdb\Model\Collection\CreditsCollection; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; -class TvCredits extends Credits {} +class TvCredits extends CreditsCollection {} diff --git a/lib/Tmdb/Model/Credits.php b/lib/Tmdb/Model/Credits.php new file mode 100644 index 00000000..dd05dca3 --- /dev/null +++ b/lib/Tmdb/Model/Credits.php @@ -0,0 +1,194 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Credits\Media; + +class Credits extends AbstractModel { + /** + * @var string + */ + private $creditType; + + /** + * @var string + */ + private $department; + + /** + * @var string + */ + private $job; + + /** + * @var Media + */ + private $media; + + /** + * @var string + */ + private $mediaType; + + /** + * @var string + */ + private $id; + + /** + * @var Person + */ + private $person; + + /** + * @var array + */ + public static $_properties = array( + 'credit_type', + 'department', + 'job', + 'media_type', + 'id', + ); + + public function __construct() + { + $this->media = new Media(); + } + + /** + * @param string $creditType + * @return $this + */ + public function setCreditType($creditType) + { + $this->creditType = $creditType; + return $this; + } + + /** + * @return string + */ + public function getCreditType() + { + return $this->creditType; + } + + /** + * @param string $department + * @return $this + */ + public function setDepartment($department) + { + $this->department = $department; + return $this; + } + + /** + * @return string + */ + public function getDepartment() + { + return $this->department; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $job + * @return $this + */ + public function setJob($job) + { + $this->job = $job; + return $this; + } + + /** + * @return string + */ + public function getJob() + { + return $this->job; + } + + /** + * @param \Tmdb\Model\Credits\Media $media + * @return $this + */ + public function setMedia($media) + { + $this->media = $media; + return $this; + } + + /** + * @return \Tmdb\Model\Credits\Media + */ + public function getMedia() + { + return $this->media; + } + + /** + * @param string $mediaType + * @return $this + */ + public function setMediaType($mediaType) + { + $this->mediaType = $mediaType; + return $this; + } + + /** + * @return string + */ + public function getMediaType() + { + return $this->mediaType; + } + + /** + * @param \Tmdb\Model\Person $person + * @return $this + */ + public function setPerson($person) + { + $this->person = $person; + return $this; + } + + /** + * @return \Tmdb\Model\Person + */ + public function getPerson() + { + return $this->person; + } +} diff --git a/lib/Tmdb/Model/Credits/Media.php b/lib/Tmdb/Model/Credits/Media.php new file mode 100644 index 00000000..a3977591 --- /dev/null +++ b/lib/Tmdb/Model/Credits/Media.php @@ -0,0 +1,163 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Credits; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Common\GenericCollection; + +class Media extends AbstractModel { + /** + * @var integer + */ + private $id; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $originalName; + + /** + * @var string + */ + private $character; + + /** + * @var GenericCollection + */ + private $episodes; + + /** + * @var GenericCollection + */ + private $seasons; + + public static $_properties = array( + 'id', + 'name', + 'original_name', + 'character', + ); + + /** + * @param string $character + * @return $this + */ + public function setCharacter($character) + { + $this->character = $character; + return $this; + } + + /** + * @return string + */ + public function getCharacter() + { + return $this->character; + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $episodes + * @return $this + */ + public function setEpisodes($episodes) + { + $this->episodes = $episodes; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getEpisodes() + { + return $this->episodes; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $originalName + * @return $this + */ + public function setOriginalName($originalName) + { + $this->originalName = $originalName; + return $this; + } + + /** + * @return string + */ + public function getOriginalName() + { + return $this->originalName; + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $seasons + * @return $this + */ + public function setSeasons($seasons) + { + $this->seasons = $seasons; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getSeasons() + { + return $this->seasons; + } +} diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index 4861562a..867702e6 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -14,7 +14,7 @@ use Tmdb\Model\Collection\ResultCollection; use Tmdb\Model\Common\GenericCollection; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Collection\Genres; use Tmdb\Model\Collection\Images; use Tmdb\Model\Collection\People; @@ -252,7 +252,7 @@ public function __construct() $this->spokenLanguages = new GenericCollection(); $this->alternativeTitles = new GenericCollection(); $this->changes = new GenericCollection(); - $this->credits = new Credits(); + $this->credits = new CreditsCollection(); $this->images = new Images(); $this->keywords = new GenericCollection(); $this->lists = new GenericCollection(); @@ -735,17 +735,17 @@ public function getBudget() } /** - * @param Credits $credits + * @param CreditsCollection $credits * @return $this */ - public function setCredits(Credits $credits) + public function setCredits(CreditsCollection $credits) { $this->credits = $credits; return $this; } /** - * @return Credits + * @return CreditsCollection */ public function getCredits() { diff --git a/lib/Tmdb/Model/Person.php b/lib/Tmdb/Model/Person.php index adb9a357..91a647fc 100644 --- a/lib/Tmdb/Model/Person.php +++ b/lib/Tmdb/Model/Person.php @@ -12,7 +12,7 @@ */ namespace Tmdb\Model; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Common\ExternalIds; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Collection\Images; @@ -76,23 +76,23 @@ class Person extends AbstractModel implements PersonInterface { private $profile; /** - * @var Collection\Credits + * @var Collection\CreditsCollection * @deprecated */ protected $credits; /** - * @var Credits\MovieCredits + * @var CreditsCollection\MovieCredits */ protected $movieCredits; /** - * @var Credits\TvCredits + * @var CreditsCollection\TvCredits */ protected $tvCredits; /** - * @var Credits\CombinedCredits + * @var CreditsCollection\CombinedCredits */ protected $combinedCredits; @@ -133,10 +133,10 @@ class Person extends AbstractModel implements PersonInterface { */ public function __construct() { - $this->credits = new Credits(); - $this->movieCredits = new Credits\MovieCredits(); - $this->tvCredits = new Credits\TvCredits(); - $this->combinedCredits = new Credits\CombinedCredits(); + $this->credits = new CreditsCollection(); + $this->movieCredits = new CreditsCollection\MovieCredits(); + $this->tvCredits = new CreditsCollection\TvCredits(); + $this->combinedCredits = new CreditsCollection\CombinedCredits(); $this->images = new Images(); $this->changes = new GenericCollection(); $this->externalIds = new ExternalIds(); @@ -407,7 +407,7 @@ public function getProfileImage() } /** - * @param \Tmdb\Model\Collection\Credits\CombinedCredits $combinedCredits + * @param \Tmdb\Model\Collection\CreditsCollection\CombinedCredits $combinedCredits * @return $this */ public function setCombinedCredits($combinedCredits) @@ -417,7 +417,7 @@ public function setCombinedCredits($combinedCredits) } /** - * @return \Tmdb\Model\Collection\Credits\CombinedCredits + * @return \Tmdb\Model\Collection\CreditsCollection\CombinedCredits */ public function getCombinedCredits() { @@ -425,7 +425,7 @@ public function getCombinedCredits() } /** - * @param \Tmdb\Model\Collection\Credits\MovieCredits $movieCredits + * @param \Tmdb\Model\Collection\CreditsCollection\MovieCredits $movieCredits * @return $this */ public function setMovieCredits($movieCredits) @@ -435,7 +435,7 @@ public function setMovieCredits($movieCredits) } /** - * @return \Tmdb\Model\Collection\Credits\MovieCredits + * @return \Tmdb\Model\Collection\CreditsCollection\MovieCredits */ public function getMovieCredits() { @@ -443,7 +443,7 @@ public function getMovieCredits() } /** - * @param \Tmdb\Model\Collection\Credits\TvCredits $tvCredits + * @param \Tmdb\Model\Collection\CreditsCollection\TvCredits $tvCredits * @return $this */ public function setTvCredits($tvCredits) @@ -453,7 +453,7 @@ public function setTvCredits($tvCredits) } /** - * @return \Tmdb\Model\Collection\Credits\TvCredits + * @return \Tmdb\Model\Collection\CreditsCollection\TvCredits */ public function getTvCredits() { diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index 9a58b6ab..20818f00 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -13,7 +13,7 @@ namespace Tmdb\Model; use Tmdb\Model\Common\GenericCollection; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Collection\Genres; use Tmdb\Model\Collection\Images; use Tmdb\Model\Image\BackdropImage; @@ -221,7 +221,7 @@ public function __construct() $this->originCountry = new GenericCollection(); $this->seasons = new GenericCollection(); - $this->credits = new Credits(); + $this->credits = new CreditsCollection(); $this->externalIds = new ExternalIds(); $this->images = new Images(); $this->translations = new GenericCollection(); @@ -704,7 +704,7 @@ public function getExternalIds() } /** - * @param \Tmdb\Model\Collection\Credits $credits + * @param \Tmdb\Model\Collection\CreditsCollection $credits * @return $this */ public function setCredits($credits) @@ -714,7 +714,7 @@ public function setCredits($credits) } /** - * @return \Tmdb\Model\Collection\Credits + * @return \Tmdb\Model\Collection\CreditsCollection */ public function getCredits() { diff --git a/lib/Tmdb/Model/Tv/Episode.php b/lib/Tmdb/Model/Tv/Episode.php index 29c2450f..64130d43 100644 --- a/lib/Tmdb/Model/Tv/Episode.php +++ b/lib/Tmdb/Model/Tv/Episode.php @@ -13,7 +13,7 @@ namespace Tmdb\Model\Tv; use Tmdb\Model\AbstractModel; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Collection\Images; use Tmdb\Model\Common\ExternalIds; use Tmdb\Model\Image\StillImage; @@ -122,7 +122,7 @@ class Episode extends AbstractModel { */ public function __construct() { - $this->credits = new Credits(); + $this->credits = new CreditsCollection(); $this->externalIds = new ExternalIds(); $this->images = new Images(); } diff --git a/lib/Tmdb/Model/Tv/Season.php b/lib/Tmdb/Model/Tv/Season.php index f90c56fc..f9436fec 100644 --- a/lib/Tmdb/Model/Tv/Season.php +++ b/lib/Tmdb/Model/Tv/Season.php @@ -13,7 +13,7 @@ namespace Tmdb\Model\Tv; use Tmdb\Model\AbstractModel; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Collection\Images; use Tmdb\Model\Common\ExternalIds; use Tmdb\Model\Common\GenericCollection; @@ -103,7 +103,7 @@ class Season extends AbstractModel { */ public function __construct() { - $this->credits = new Credits(); + $this->credits = new CreditsCollection(); $this->externalIds = new ExternalIds(); $this->images = new Images(); $this->episodes = new GenericCollection(); @@ -246,7 +246,7 @@ public function setCredits($credits) } /** - * @return \Tmdb\Model\Collection\Credits + * @return \Tmdb\Model\Collection\CreditsCollection */ public function getCredits() { diff --git a/lib/Tmdb/Repository/CollectionRepository.php b/lib/Tmdb/Repository/CollectionRepository.php index 71df454e..002e00ed 100644 --- a/lib/Tmdb/Repository/CollectionRepository.php +++ b/lib/Tmdb/Repository/CollectionRepository.php @@ -54,6 +54,22 @@ public function load($id, array $parameters = array(), array $headers = array()) return $this->getFactory()->create($data); } + /** + * Get all of the images for a particular collection by collection id. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getImages($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getImages($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('images' => $data)); + + return $movie->getImages(); + } + /** * Return the Collection API Class * @@ -89,19 +105,4 @@ public function getImageFactory() { return $this->imageFactory; } - - /** - * Get all of the images for a particular collection by collection id. - * - * @param $id - * @param array $parameters - * @param array $headers - * @return ApiCollection\Images - */ - public function getImages($id, array $parameters = array(), array $headers = array()) - { - return $this->getImageFactory()->createCollection( - $this->getApi()->getImages($id, $parameters, $headers) - ); - } } diff --git a/lib/Tmdb/Repository/CreditsRepository.php b/lib/Tmdb/Repository/CreditsRepository.php new file mode 100644 index 00000000..d887f61c --- /dev/null +++ b/lib/Tmdb/Repository/CreditsRepository.php @@ -0,0 +1,83 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\CompanyFactory; +use Tmdb\Factory\CreditsFactory; +use Tmdb\Factory\TvFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Company; +use Tmdb\Model\Movie; + +class CreditsRepository extends AbstractRepository { + + /** + * Load a company with the given identifier + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Company + */ + public function load($id, array $parameters = array(), array $headers = array()) { + $data = $this->getApi()->getCredit($id, $this->parseQueryParameters($parameters), $headers); + + return $this->getFactory()->create($data); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Credits + */ + public function getApi() + { + return $this->getClient()->getCreditsApi(); + } + + /** + * @return CompanyFactory + */ + public function getFactory() + { + return new CreditsFactory(); + } + + /** + * @return TvFactory + */ + public function getTvFactory() + { + return new TvFactory(); + } + + /** + * Create an collection of an array + * + * @param $data + * @return Movie[] + */ + public function createMovieCollection($data){ + $collection = new GenericCollection(); + + if (array_key_exists('results', $data)) { + $data = $data['results']; + } + + foreach($data as $item) { + $collection->add(null, $this->getMovieFactory()->create($item)); + } + + return $collection; + } +} diff --git a/test/Tmdb/Tests/Factory/MovieFactoryTest.php b/test/Tmdb/Tests/Factory/MovieFactoryTest.php index 67aa297f..0762844b 100644 --- a/test/Tmdb/Tests/Factory/MovieFactoryTest.php +++ b/test/Tmdb/Tests/Factory/MovieFactoryTest.php @@ -97,7 +97,7 @@ public function shouldBeFunctional() $this->assertEquals(625, $this->movie->getVoteCount()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getAlternativeTitles()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getChanges()); - $this->assertInstanceOf('Tmdb\Model\Collection\Credits', $this->movie->getCredits()); + $this->assertInstanceOf('Tmdb\Model\Collection\CreditsCollection', $this->movie->getCredits()); $this->assertInstanceOf('Tmdb\Model\Collection\Images', $this->movie->getImages()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getKeywords()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getLists()); diff --git a/test/Tmdb/Tests/Factory/PeopleFactoryTest.php b/test/Tmdb/Tests/Factory/PeopleFactoryTest.php index 4150c73b..cbfdb333 100644 --- a/test/Tmdb/Tests/Factory/PeopleFactoryTest.php +++ b/test/Tmdb/Tests/Factory/PeopleFactoryTest.php @@ -68,7 +68,7 @@ public function shouldConstructCastAndCredits() $movie = $movieFactory->create($data); $credits = $movie->getCredits(); - $this->assertInstanceOf('Tmdb\Model\Collection\Credits', $credits); + $this->assertInstanceOf('Tmdb\Model\Collection\CreditsCollection', $credits); $cast = $credits->getCast(); $crew = $credits->getCrew(); @@ -131,9 +131,9 @@ public function shouldBeFunctional() $this->assertEquals('/h9YwlLHANaQzaTVkVwxnxLbvCY4.jpg', $this->person->getProfilePath()); $this->assertInstanceOf('Tmdb\Model\Collection\Images', $this->person->getImages()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->person->getChanges()); - $this->assertInstanceOf('Tmdb\Model\Collection\Credits\CombinedCredits', $this->person->getCombinedCredits()); - $this->assertInstanceOf('Tmdb\Model\Collection\Credits\MovieCredits', $this->person->getMovieCredits()); - $this->assertInstanceOf('Tmdb\Model\Collection\Credits\TvCredits', $this->person->getTvCredits()); + $this->assertInstanceOf('Tmdb\Model\Collection\CreditsCollection\CombinedCredits', $this->person->getCombinedCredits()); + $this->assertInstanceOf('Tmdb\Model\Collection\CreditsCollection\MovieCredits', $this->person->getMovieCredits()); + $this->assertInstanceOf('Tmdb\Model\Collection\CreditsCollection\TvCredits', $this->person->getTvCredits()); } /** diff --git a/test/Tmdb/Tests/Factory/TvEpisodeFactoryTest.php b/test/Tmdb/Tests/Factory/TvEpisodeFactoryTest.php index 1f28b000..36f1e4aa 100644 --- a/test/Tmdb/Tests/Factory/TvEpisodeFactoryTest.php +++ b/test/Tmdb/Tests/Factory/TvEpisodeFactoryTest.php @@ -45,7 +45,7 @@ public function shouldConstructTvEpisode() $this->assertInstanceOf('\DateTime', $this->episode->getAirDate()); - $this->assertInstanceOf('Tmdb\Model\Collection\Credits', $this->episode->getCredits()); + $this->assertInstanceOf('Tmdb\Model\Collection\CreditsCollection', $this->episode->getCredits()); $this->assertInstanceOf('Tmdb\Model\Common\ExternalIds', $this->episode->getExternalIds()); $this->assertInstanceOf('Tmdb\Model\Collection\Images', $this->episode->getImages()); $this->assertInstanceOf('Tmdb\Model\Image\StillImage', $this->episode->getStillImage()); diff --git a/test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php b/test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php index e3776ebc..1ea783ad 100644 --- a/test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php +++ b/test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php @@ -45,7 +45,7 @@ public function shouldConstructTvSeason() $this->assertInstanceOf('\DateTime', $this->season->getAirDate()); - $this->assertInstanceOf('Tmdb\Model\Collection\Credits', $this->season->getCredits()); + $this->assertInstanceOf('Tmdb\Model\Collection\CreditsCollection', $this->season->getCredits()); $this->assertInstanceOf('Tmdb\Model\Common\ExternalIds', $this->season->getExternalIds()); $this->assertInstanceOf('Tmdb\Model\Collection\Images', $this->season->getImages()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->season->getEpisodes()); diff --git a/test/Tmdb/Tests/Model/MovieTest.php b/test/Tmdb/Tests/Model/MovieTest.php index cf60ec2e..0c51b6a1 100644 --- a/test/Tmdb/Tests/Model/MovieTest.php +++ b/test/Tmdb/Tests/Model/MovieTest.php @@ -12,7 +12,7 @@ */ namespace Tmdb\Tests\Model; -use Tmdb\Model\Collection\Credits; +use Tmdb\Model\Collection\CreditsCollection; use Tmdb\Model\Collection\ResultCollection; use Tmdb\Model\Movie; @@ -35,7 +35,7 @@ public function shouldConstructMovie() 'getSpokenLanguages' => 'Tmdb\Model\Common\GenericCollection', 'getAlternativeTitles' => 'Tmdb\Model\Common\GenericCollection', 'getChanges' => 'Tmdb\Model\Common\GenericCollection', - 'getCredits' => 'Tmdb\Model\Collection\Credits', + 'getCredits' => 'Tmdb\Model\Collection\CreditsCollection', 'getImages' => 'Tmdb\Model\Collection\Images', 'getKeywords' => 'Tmdb\Model\Common\GenericCollection', 'getLists' => 'Tmdb\Model\Common\GenericCollection', @@ -61,7 +61,7 @@ public function shouldAllowOverridingDefaultCollectionObjects() $movie->setProductionCompanies($class); $movie->setProductionCountries($class); $movie->setSpokenLanguages($class); - $movie->setCredits(new Credits()); + $movie->setCredits(new CreditsCollection()); $movie->setLists($class); $this->assertInstancesOf( @@ -72,7 +72,7 @@ public function shouldAllowOverridingDefaultCollectionObjects() 'getProductionCompanies' => $className, 'getProductionCountries' => $className, 'getSpokenLanguages' => $className, - 'getCredits' => 'Tmdb\Model\Collection\Credits', + 'getCredits' => 'Tmdb\Model\Collection\CreditsCollection', 'getLists' => $className, ) ); diff --git a/test/Tmdb/Tests/Model/PersonTest.php b/test/Tmdb/Tests/Model/PersonTest.php index feedc3e0..26dc0961 100644 --- a/test/Tmdb/Tests/Model/PersonTest.php +++ b/test/Tmdb/Tests/Model/PersonTest.php @@ -15,24 +15,24 @@ use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Person; -class GenreTest extends TestCase +class PersonTest extends TestCase { /** * @test */ - public function shouldConstructGenres() + public function shouldConstructPersons() { $person = new Person(); $this->assertInstancesOf( $person, array( - 'getCredits' => 'Tmdb\Model\Collection\Credits', + 'getCredits' => 'Tmdb\Model\Collection\CreditsCollection', 'getImages' => 'Tmdb\Model\Collection\Images', 'getChanges' => 'Tmdb\Model\Common\GenericCollection', - 'getCombinedCredits' => 'Tmdb\Model\Collection\Credits\CombinedCredits', - 'getMovieCredits' => 'Tmdb\Model\Collection\Credits\MovieCredits', - 'getTvCredits' => 'Tmdb\Model\Collection\Credits\TvCredits', + 'getCombinedCredits' => 'Tmdb\Model\Collection\CreditsCollection\CombinedCredits', + 'getMovieCredits' => 'Tmdb\Model\Collection\CreditsCollection\MovieCredits', + 'getTvCredits' => 'Tmdb\Model\Collection\CreditsCollection\TvCredits', ) ); } diff --git a/test/Tmdb/Tests/Model/Tv/EpisodeTest.php b/test/Tmdb/Tests/Model/Tv/EpisodeTest.php index 3e934818..e64a9b3f 100644 --- a/test/Tmdb/Tests/Model/Tv/EpisodeTest.php +++ b/test/Tmdb/Tests/Model/Tv/EpisodeTest.php @@ -27,7 +27,7 @@ public function shouldConstructTvEpisode() $this->assertInstancesOf( $episode, array( - 'getCredits' => 'Tmdb\Model\Collection\Credits', + 'getCredits' => 'Tmdb\Model\Collection\CreditsCollection', 'getExternalIds' => 'Tmdb\Model\Common\ExternalIds', 'getImages' => 'Tmdb\Model\Collection\Images', ) diff --git a/test/Tmdb/Tests/Model/Tv/SeasonTest.php b/test/Tmdb/Tests/Model/Tv/SeasonTest.php index 208d6832..66740ff7 100644 --- a/test/Tmdb/Tests/Model/Tv/SeasonTest.php +++ b/test/Tmdb/Tests/Model/Tv/SeasonTest.php @@ -27,7 +27,7 @@ public function shouldConstructTvSeason() $this->assertInstancesOf( $season, array( - 'getCredits' => 'Tmdb\Model\Collection\Credits', + 'getCredits' => 'Tmdb\Model\Collection\CreditsCollection', 'getExternalIds' => 'Tmdb\Model\Common\ExternalIds', 'getImages' => 'Tmdb\Model\Collection\Images', 'getEpisodes' => 'Tmdb\Model\Common\GenericCollection', diff --git a/test/Tmdb/Tests/Model/TvTest.php b/test/Tmdb/Tests/Model/TvTest.php index 613c9427..e2cbaec8 100644 --- a/test/Tmdb/Tests/Model/TvTest.php +++ b/test/Tmdb/Tests/Model/TvTest.php @@ -33,7 +33,7 @@ public function shouldConstructMovie() 'getNetworks' => 'Tmdb\Model\Common\GenericCollection', 'getOriginCountry' => 'Tmdb\Model\Common\GenericCollection', 'getSeasons' => 'Tmdb\Model\Common\GenericCollection', - 'getCredits' => 'Tmdb\Model\Collection\Credits', + 'getCredits' => 'Tmdb\Model\Collection\CreditsCollection', 'getExternalIds' => 'Tmdb\Model\Common\ExternalIds', 'getImages' => 'Tmdb\Model\Collection\Images', 'getTranslations' => 'Tmdb\Model\Common\GenericCollection',