From 5d2c9079ed8e49e346fd9598cdab64d2ac26c7f7 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sun, 9 Feb 2014 02:52:31 +0100 Subject: [PATCH] Adding missing methods for PersonRepository --- examples/people/model/combined_credits.php | 22 +++++++++ examples/people/model/movie_credits.php | 22 +++++++++ examples/people/model/tv_credits.php | 22 +++++++++ lib/Tmdb/Api/People.php | 47 ++++++++++++++++++- lib/Tmdb/Factory/PeopleFactory.php | 5 +- lib/Tmdb/Repository/PeopleRepository.php | 54 ++++++++++++++++++++++ 6 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 examples/people/model/combined_credits.php create mode 100644 examples/people/model/movie_credits.php create mode 100644 examples/people/model/tv_credits.php diff --git a/examples/people/model/combined_credits.php b/examples/people/model/combined_credits.php new file mode 100644 index 00000000..21f36725 --- /dev/null +++ b/examples/people/model/combined_credits.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\PeopleRepository($client); +$person = $repository->getCombinedCredits(33); + +var_dump($person); \ No newline at end of file diff --git a/examples/people/model/movie_credits.php b/examples/people/model/movie_credits.php new file mode 100644 index 00000000..cc5b1df2 --- /dev/null +++ b/examples/people/model/movie_credits.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\PeopleRepository($client); +$person = $repository->getMovieCredits(33); + +var_dump($person); \ No newline at end of file diff --git a/examples/people/model/tv_credits.php b/examples/people/model/tv_credits.php new file mode 100644 index 00000000..ab75c741 --- /dev/null +++ b/examples/people/model/tv_credits.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\PeopleRepository($client); +$person = $repository->getTvCredits(33); + +var_dump($person); \ No newline at end of file diff --git a/lib/Tmdb/Api/People.php b/lib/Tmdb/Api/People.php index 08be5c8e..eb1a2d13 100644 --- a/lib/Tmdb/Api/People.php +++ b/lib/Tmdb/Api/People.php @@ -38,7 +38,52 @@ public function getPerson($person_id, array $parameters = array(), array $header */ public function getCredits($person_id, array $parameters = array(), array $headers = array()) { - return $this->get('person/' . $person_id . '/credits', $parameters, $headers); + return $this->getCombinedCredits($person_id, $parameters, $headers); + } + + /** + * Get the movie credits for a specific person id. + * + * @param $person_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getMovieCredits($person_id, array $parameters = array(), array $headers = array()) + { + return $this->get('person/' . $person_id . '/movie_credits', $parameters, $headers); + } + + /** + * Get the TV credits for a specific person id. + * + * To get the expanded details for each record, call the /credit method with the provided credit_id. + * This will provide details about which episode and/or season the credit is for. + * + * @param $person_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getTvCredits($person_id, array $parameters = array(), array $headers = array()) + { + return $this->get('person/' . $person_id . '/tv_credits', $parameters, $headers); + } + + /** + * Get the combined (movie and TV) credits for a specific person id. + * + * To get the expanded details for each TV record, call the /credit method with the provided credit_id. + * This will provide details about which episode and/or season the credit is for. + * + * @param $person_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCombinedCredits($person_id, array $parameters = array(), array $headers = array()) + { + return $this->get('person/' . $person_id . '/combined_credits', $parameters, $headers); } /** diff --git a/lib/Tmdb/Factory/PeopleFactory.php b/lib/Tmdb/Factory/PeopleFactory.php index c61e2153..b71103bb 100644 --- a/lib/Tmdb/Factory/PeopleFactory.php +++ b/lib/Tmdb/Factory/PeopleFactory.php @@ -43,7 +43,10 @@ public function __construct() } /** - * {@inheritdoc} + * @param array $data + * @param Person\AbstractMember|null $person + * + * @return Person|CrewMember|CastMember */ public function create(array $data = array(), Person\AbstractMember $person = null) { diff --git a/lib/Tmdb/Repository/PeopleRepository.php b/lib/Tmdb/Repository/PeopleRepository.php index 33e803c9..716ca3ec 100644 --- a/lib/Tmdb/Repository/PeopleRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -47,6 +47,60 @@ public function load($id, array $parameters = array(), array $headers = array()) return $this->getFactory()->create($data); } + /** + * Get the movie credits for a specific person id. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getMovieCredits($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getMovieCredits($id, $this->parseQueryParameters($parameters), $headers); + $person = $this->getFactory()->create(array('movie_credits' => $data)); + + return $person->getMovieCredits(); + } + + /** + * Get the TV credits for a specific person id. + * + * To get the expanded details for each record, call the /credit method with the provided credit_id. + * This will provide details about which episode and/or season the credit is for. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getTvCredits($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getTvCredits($id, $this->parseQueryParameters($parameters), $headers); + $person = $this->getFactory()->create(array('tv_credits' => $data)); + + return $person->getTvCredits(); + } + + /** + * Get the combined (movie and TV) credits for a specific person id. + * + * To get the expanded details for each TV record, call the /credit method with the provided credit_id. + * This will provide details about which episode and/or season the credit is for. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getCombinedCredits($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getCombinedCredits($id, $this->parseQueryParameters($parameters), $headers); + $person = $this->getFactory()->create(array('combined_credits' => $data)); + + return $person->getCombinedCredits(); + } + /** * Return the related API class *