diff --git a/README.md b/README.md index 316ccea1..156d5e54 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ I'm working extensively on finishing the models/repositories/factories, which sh | Changes | Done | | Collections | Done | | Companies | Done | -| Credits | **TODO** _added to tmdb recently_, available in API namespace. | +| Credits | Done | | Discover | Done | | Find | Done | | Genres | Done | diff --git a/examples/certifications/model/get.php b/examples/certifications/model/get.php new file mode 100644 index 00000000..83231228 --- /dev/null +++ b/examples/certifications/model/get.php @@ -0,0 +1,23 @@ + + * @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); + +$certificationRepository = new \Tmdb\Repository\CertificationRepository($client); +$certificationList = $certificationRepository->getMovieList(); + +var_dump($certificationList); + diff --git a/lib/Tmdb/Factory/CertificationFactory.php b/lib/Tmdb/Factory/CertificationFactory.php new file mode 100644 index 00000000..4eed09f5 --- /dev/null +++ b/lib/Tmdb/Factory/CertificationFactory.php @@ -0,0 +1,110 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Certification; +use Tmdb\Model\Common\GenericCollection; + +class CertificationFactory extends AbstractFactory +{ + /** + * @param array $data + * + * @return Certification + */ + public function create(array $data = array()) + { + return $this->hydrate(new Certification\CountryCertification(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + if (array_key_exists('certifications', $data)) { + $data = $data['certifications']; + } + + $collection = new GenericCollection(); + + foreach($data as $country => $certifications) { + $certification = new Certification(); + $certification->setCountry($country); + + foreach($certifications as $countryCertification) { + $object = $this->create($countryCertification); + + $certification->getCertifications()->add(null, $object); + } + + $collection->add(null, $certification); + } + + 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/Certification.php b/lib/Tmdb/Model/Certification.php new file mode 100644 index 00000000..338ae356 --- /dev/null +++ b/lib/Tmdb/Model/Certification.php @@ -0,0 +1,73 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Common\GenericCollection; + +class Certification extends AbstractModel { + + /** + * @var string + */ + private $country; + + /** + * @var GenericCollection + */ + private $certifications; + + public static $_properties = array( + 'country', + ); + + public function __construct() + { + $this->certifications = new GenericCollection(); + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $certifications + * @return $this + */ + public function setCertifications($certifications) + { + $this->certifications = $certifications; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getCertifications() + { + return $this->certifications; + } + + /** + * @param string $country + * @return $this + */ + public function setCountry($country) + { + $this->country = $country; + return $this; + } + + /** + * @return string + */ + public function getCountry() + { + return $this->country; + } +} diff --git a/lib/Tmdb/Model/Certification/CountryCertification.php b/lib/Tmdb/Model/Certification/CountryCertification.php new file mode 100644 index 00000000..089f7d93 --- /dev/null +++ b/lib/Tmdb/Model/Certification/CountryCertification.php @@ -0,0 +1,95 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Certification; + +use Tmdb\Model\AbstractModel; + +class CountryCertification extends AbstractModel { + + /** + * @var string + */ + private $certification; + + /** + * @var string + */ + private $meaning; + + /** + * @var integer + */ + private $order; + + public static $_properties = array( + 'certification', + 'meaning', + 'order', + ); + + /** + * @param string $certification + * @return $this + */ + public function setCertification($certification) + { + $this->certification = $certification; + return $this; + } + + /** + * @return string + */ + public function getCertification() + { + return $this->certification; + } + + /** + * @param string $meaning + * @return $this + */ + public function setMeaning($meaning) + { + $this->meaning = $meaning; + return $this; + } + + /** + * @return string + */ + public function getMeaning() + { + return $this->meaning; + } + + /** + * @param int $order + * @return $this + */ + public function setOrder($order) + { + $this->order = $order; + return $this; + } + + /** + * @return int + */ + public function getOrder() + { + return $this->order; + } + + +} diff --git a/lib/Tmdb/Repository/CertificationRepository.php b/lib/Tmdb/Repository/CertificationRepository.php new file mode 100644 index 00000000..1d646e5f --- /dev/null +++ b/lib/Tmdb/Repository/CertificationRepository.php @@ -0,0 +1,52 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\CertificationFactory; +use Tmdb\Model\Collection as ApiCollection; + +class CertificationRepository extends AbstractRepository { + + /** + * Get the list of supported certifications for movies. + * + * These can be used in conjunction with the certification_country and certification.lte parameters when using discover. + * + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getMovieList(array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getMovieList($this->parseQueryParameters($parameters), $headers); + return $this->getFactory()->createCollection($data); + } + + /** + * Return the Collection API Class + * + * @return \Tmdb\Api\Certifications + */ + public function getApi() + { + return $this->getClient()->getCertificationsApi(); + } + + /** + * @return CertificationFactory + */ + public function getFactory() + { + return new CertificationFactory(); + } +}