diff --git a/examples/tv/model/tv/credits.php b/examples/tv/model/tv/credits.php new file mode 100644 index 00000000..497c6161 --- /dev/null +++ b/examples/tv/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\TvRepository($client); +$tvShow = $repository->getCredits(1396); + +var_dump($tvShow); \ No newline at end of file diff --git a/examples/tv/model/tv/external_ids.php b/examples/tv/model/tv/external_ids.php new file mode 100644 index 00000000..8ee689ae --- /dev/null +++ b/examples/tv/model/tv/external_ids.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\TvRepository($client); +$tvShow = $repository->getExternalIds(1396); + +var_dump($tvShow); \ No newline at end of file diff --git a/examples/tv/model/tv/images.php b/examples/tv/model/tv/images.php new file mode 100644 index 00000000..fea43b3a --- /dev/null +++ b/examples/tv/model/tv/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\TvRepository($client); +$tvShow = $repository->getImages(1396); + +var_dump($tvShow); \ No newline at end of file diff --git a/examples/tv/model/tv/on_the_air.php b/examples/tv/model/tv/on_the_air.php new file mode 100644 index 00000000..fb8bd45d --- /dev/null +++ b/examples/tv/model/tv/on_the_air.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\TvRepository($client); +$tvShow = $repository->getOnTheAir(); + +var_dump($tvShow); \ No newline at end of file diff --git a/examples/tv/model/tv/translations.php b/examples/tv/model/tv/translations.php new file mode 100644 index 00000000..c69304ac --- /dev/null +++ b/examples/tv/model/tv/translations.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\TvRepository($client); +$tvShow = $repository->getTranslations(1396); + +var_dump($tvShow); \ No newline at end of file diff --git a/lib/Tmdb/Api/Tv.php b/lib/Tmdb/Api/Tv.php index 3745525e..09576c4d 100644 --- a/lib/Tmdb/Api/Tv.php +++ b/lib/Tmdb/Api/Tv.php @@ -95,4 +95,19 @@ public function getTopRated(array $parameters = array(), array $headers = array( return $this->get('tv/top_rated', $parameters, $headers); } + /** + * Get the list of translations that exist for a TV series. + * + * These translations cascade down to the episode level. + * + * @param int $tvshow_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getTranslations($tvshow_id, array $parameters = array(), array $headers = array()) + { + $this->get('tv/' . $tvshow_id . '/translations', $parameters, $headers); + } + } diff --git a/lib/Tmdb/Factory/TvFactory.php b/lib/Tmdb/Factory/TvFactory.php index 06b12923..9f5af617 100644 --- a/lib/Tmdb/Factory/TvFactory.php +++ b/lib/Tmdb/Factory/TvFactory.php @@ -66,7 +66,9 @@ public function __construct() } /** - * {@inheritdoc} + * @param array $data + * + * @return Tv */ public function create(array $data = array()) { @@ -112,7 +114,7 @@ public function create(array $data = array()) } /** Translations */ - if (array_key_exists('translations', $data)) { + if (array_key_exists('translations', $data) && null !== $data['translations']) { $tvShow->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation())); } diff --git a/lib/Tmdb/Repository/TvRepository.php b/lib/Tmdb/Repository/TvRepository.php index ee4bdb91..3252b730 100644 --- a/lib/Tmdb/Repository/TvRepository.php +++ b/lib/Tmdb/Repository/TvRepository.php @@ -13,7 +13,6 @@ namespace Tmdb\Repository; use Tmdb\Factory\TvFactory; -use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Tv; use Tmdb\Model\Tv\QueryParameter\AppendToResponse; @@ -48,6 +47,74 @@ public function load($id, array $parameters = array(), array $headers = array()) return $this->getFactory()->create($data); } + /** + * Get the cast & crew information about a TV series. + * + * Just like the website, we pull this information from the last season of the series. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getCredits($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getCredits($id, $this->parseQueryParameters($parameters), $headers); + $tv = $this->getFactory()->create(array('credits' => $data)); + + return $tv->getCredits(); + } + + /** + * Get the external ids that we have stored for a TV series. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getExternalIds($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getExternalIds($id, $this->parseQueryParameters($parameters), $headers); + $tv = $this->getFactory()->create(array('external_ids' => $data)); + + return $tv->getExternalIds(); + } + + /** + * Get the images (posters and backdrops) for a TV series. + * + * @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); + $tv = $this->getFactory()->create(array('images' => $data)); + + return $tv->getImages(); + } + + /** + * Get the list of translations that exist for a TV series. + * + * These translations cascade down to the episode level. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getTranslations($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getTranslations($id, $this->parseQueryParameters($parameters), $headers); + $tv = $this->getFactory()->create(array('translations' => $data)); + + return $tv->getTranslations(); + } + /** * Return the Tvs API Class * @@ -74,7 +141,7 @@ public function getFactory() */ public function getPopular(array $options = array()) { - return $this->createCollection( + return $this->getFactory()->createResultCollection( $this->getApi()->getPopular($options) ); } @@ -87,7 +154,20 @@ public function getPopular(array $options = array()) */ public function getTopRated(array $options = array()) { - return $this->createCollection( + return $this->getFactory()->createResultCollection( + $this->getApi()->getTopRated($options) + ); + } + + /** + * Get the list of top rated tvs. By default, this list will only include tvs that have 10 or more votes. This list refreshes every day. + * + * @param array $options + * @return Tv[] + */ + public function getOnTheAir(array $options = array()) + { + return $this->getFactory()->createResultCollection( $this->getApi()->getTopRated($options) ); }