From d43d291def02485d956e71506dcd1f1565ac175b Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Mon, 20 Jan 2014 01:20:40 +0100 Subject: [PATCH] Updating Models --- lib/Tmdb/Model/Company.php | 50 +++++++++-------------- lib/Tmdb/Model/Configuration.php | 13 +++--- lib/Tmdb/Model/Person.php | 2 +- lib/Tmdb/Repository/CompanyRepository.php | 38 +++++++++++++++++ 4 files changed, 65 insertions(+), 38 deletions(-) diff --git a/lib/Tmdb/Model/Company.php b/lib/Tmdb/Model/Company.php index 53e25e43..67b3c312 100644 --- a/lib/Tmdb/Model/Company.php +++ b/lib/Tmdb/Model/Company.php @@ -12,7 +12,7 @@ */ namespace Tmdb\Model; -use Tmdb\Client; +use Tmdb\Model\Image\LogoImage; class Company extends AbstractModel { @@ -20,6 +20,7 @@ class Company extends AbstractModel { private $headquarters; private $homepage; private $id; + private $logo; private $logoPath; private $name; private $parentCompany; @@ -34,35 +35,6 @@ class Company extends AbstractModel { 'parent_company' ); - /** - * Convert an array to an hydrated object - * - * @param Client $client - * @param array $data - * @return $this - */ - public static function fromArray(Client $client, array $data) - { - $genre = new Company($data['id']); - //$genre->setClient($client); - - return $genre->hydrate($data); - } - - /** - * Load a company with the given identifier - * - * @param Client $client - * @param $id - * @param $options - * @return $this - */ - public static function load(Client $client, $id, array $options = array()) { - $data = $client->api('companies')->getCompany($id, $options); - - return Company::fromArray($client, $data); - } - /** * @param mixed $description * @return $this @@ -135,6 +107,24 @@ public function getId() return $this->id; } + /** + * @param LogoImage $logo + * @return $this + */ + public function setLogo(LogoImage $logo) + { + $this->logo = $logo; + return $this; + } + + /** + * @return LogoImage + */ + public function getLogo() + { + return $this->logo; + } + /** * @param mixed $logoPath * @return $this diff --git a/lib/Tmdb/Model/Configuration.php b/lib/Tmdb/Model/Configuration.php index b2f60d43..32cda1c1 100644 --- a/lib/Tmdb/Model/Configuration.php +++ b/lib/Tmdb/Model/Configuration.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Model; -use Tmdb\Client; use Tmdb\Model\Common\GenericCollection; class Configuration extends AbstractModel { @@ -33,17 +32,17 @@ class Configuration extends AbstractModel { ); /** - * @param \Tmdb\Model\Common\Collection $change_keys + * @param GenericCollection $change_keys * @return $this */ - public function setChangeKeys($change_keys) + public function setChangeKeys(GenericCollection $change_keys) { $this->change_keys = $change_keys; return $this; } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getChangeKeys() { @@ -51,17 +50,17 @@ public function getChangeKeys() } /** - * @param \Tmdb\Model\Common\Collection $images + * @param GenericCollection $images * @return $this */ - public function setImages($images) + public function setImages(GenericCollection $images) { $this->images = $images; return $this; } /** - * @return \Tmdb\Model\Common\Collection + * @return GenericCollection */ public function getImages() { diff --git a/lib/Tmdb/Model/Person.php b/lib/Tmdb/Model/Person.php index b2d6cb07..44609f6f 100644 --- a/lib/Tmdb/Model/Person.php +++ b/lib/Tmdb/Model/Person.php @@ -339,7 +339,7 @@ public function getJob() * @param ProfileImage $profile * @return $this */ - public function setProfile($profile) + public function setProfile(ProfileImage $profile) { $this->profile = $profile; return $this; diff --git a/lib/Tmdb/Repository/CompanyRepository.php b/lib/Tmdb/Repository/CompanyRepository.php index b81e30b2..fc063693 100644 --- a/lib/Tmdb/Repository/CompanyRepository.php +++ b/lib/Tmdb/Repository/CompanyRepository.php @@ -13,8 +13,10 @@ namespace Tmdb\Repository; use Tmdb\Factory\CompanyFactory; +use Tmdb\Factory\MovieFactory; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Company; +use Tmdb\Model\Movie; class CompanyRepository extends AbstractRepository { /** @@ -31,6 +33,22 @@ public function load($id, array $parameters = array(), array $headers = array()) return CompanyFactory::create($data); } + + /** + * Get the list of movies associated with a particular company. + * + * @param integer $id + * @param array $parameters + * @param array $headers + * @return Movie[] + */ + public function getMovies($id, array $parameters = array(), array $headers = array()) + { + return $this->createMovieCollection( + $this->getApi()->getMovies($id, $this->parseQueryParameters($parameters), $this->parseHeaders($headers)) + ); + } + /** * Return the related API class * @@ -40,4 +58,24 @@ public function getApi() { return $this->getClient()->getCompaniesApi(); } + + /** + * Create an collection of an array + * + * @param $data + * @return Movie[] + */ + private function createMovieCollection($data){ + $collection = new GenericCollection(); + + if (array_key_exists('results', $data)) { + $data = $data['results']; + } + + foreach($data as $item) { + $collection->add(null, MovieFactory::create($item)); + } + + return $collection; + } } \ No newline at end of file