From 3a6ce542292e71842c4abe67b223c770ed76cc93 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 18 Jan 2014 22:26:16 +0100 Subject: [PATCH] Adding the implementation of Collection, this caused some disturbance and decided to rename the generic collection object to GenericCollection to avoid confusion with the Collection api method --- examples/collection/model/all.php | 22 ++ examples/people/model/all.php | 2 +- lib/Tmdb/Factory/CollectionFactory.php | 59 +++++ .../Common/GenericCollectionFactory.php | 4 +- lib/Tmdb/Factory/CompanyFactory.php | 4 +- lib/Tmdb/Factory/ConfigurationFactory.php | 4 +- .../Factory/Movie/AlternativeTitleFactory.php | 4 +- lib/Tmdb/Factory/MovieFactory.php | 4 +- lib/Tmdb/Factory/People/PeopleFactory.php | 4 +- lib/Tmdb/Factory/TvEpisodeFactory.php | 4 +- lib/Tmdb/Factory/TvFactory.php | 4 +- lib/Tmdb/Factory/TvSeasonFactory.php | 4 +- lib/Tmdb/Model/Changes.php | 6 +- lib/Tmdb/Model/Collection.php | 220 ++++++++++++++++++ lib/Tmdb/Model/Collection/Changes.php | 4 +- lib/Tmdb/Model/Collection/Genres.php | 4 +- lib/Tmdb/Model/Collection/Images.php | 4 +- lib/Tmdb/Model/Collection/Keywords.php | 4 +- lib/Tmdb/Model/Collection/People.php | 4 +- .../QueryParameter/AppendToResponse.php | 19 ++ lib/Tmdb/Model/Common/DataCollector.php | 4 +- .../{Collection.php => GenericCollection.php} | 26 +-- .../Type/CollectionToCommaSeperatedString.php | 4 +- lib/Tmdb/Model/Company.php | 2 +- lib/Tmdb/Model/Configuration.php | 2 +- lib/Tmdb/Model/Movie.php | 58 ++--- lib/Tmdb/Model/Person.php | 25 +- lib/Tmdb/Model/Query/Changes.php | 6 +- lib/Tmdb/Model/Query/Discover.php | 6 +- lib/Tmdb/Model/Tv.php | 18 +- lib/Tmdb/Model/Tv/Episode.php | 2 +- lib/Tmdb/Model/Tv/Season.php | 8 +- lib/Tmdb/Repository/ChangesRepository.php | 48 ++-- lib/Tmdb/Repository/CollectionRepository.php | 71 ++++++ lib/Tmdb/Repository/CompanyRepository.php | 2 +- lib/Tmdb/Repository/GenreRepository.php | 8 +- lib/Tmdb/Repository/MovieRepository.php | 14 +- lib/Tmdb/Repository/TvEpisodeRepository.php | 6 +- lib/Tmdb/Repository/TvRepository.php | 10 +- lib/Tmdb/Repository/TvSeasonRepository.php | 6 +- 40 files changed, 568 insertions(+), 142 deletions(-) create mode 100644 examples/collection/model/all.php create mode 100644 lib/Tmdb/Factory/CollectionFactory.php create mode 100644 lib/Tmdb/Model/Collection.php create mode 100644 lib/Tmdb/Model/Collection/QueryParameter/AppendToResponse.php rename lib/Tmdb/Model/Common/{Collection.php => GenericCollection.php} (92%) create mode 100644 lib/Tmdb/Repository/CollectionRepository.php diff --git a/examples/collection/model/all.php b/examples/collection/model/all.php new file mode 100644 index 00000000..1f8c844c --- /dev/null +++ b/examples/collection/model/all.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/people/model/all.php b/examples/people/model/all.php index 11c08e70..62700185 100644 --- a/examples/people/model/all.php +++ b/examples/people/model/all.php @@ -16,7 +16,7 @@ $token = new \Tmdb\ApiToken(TMDB_API_KEY); $client = new \Tmdb\Client($token); -$repository = new \Tmdb\Repository\PersonRepository($client); +$repository = new \Tmdb\Repository\PeopleRepository($client); $person = $repository->load(33); var_dump($person); \ No newline at end of file diff --git a/lib/Tmdb/Factory/CollectionFactory.php b/lib/Tmdb/Factory/CollectionFactory.php new file mode 100644 index 00000000..6be0d83f --- /dev/null +++ b/lib/Tmdb/Factory/CollectionFactory.php @@ -0,0 +1,59 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +class CollectionFactory extends AbstractFactory +{ + /** + * {@inheritdoc} + * @return \Tmdb\Model\Collection + */ + public static function create(array $data = array()) + { + $collection = new \Tmdb\Model\Collection(); + + if (array_key_exists('parts', $data)) { + $collection->setParts( + MovieFactory::createCollection($data['parts']) + ); + } + + if (array_key_exists('backdrop_path', $data)) { + $collection->setBackdrop(ImageFactory::createFromPath($data['backdrop_path'], 'backdrop_path')); + } + + if (array_key_exists('images', $data)) { + $collection->setImages(ImageFactory::createCollectionFromMovie($data['images'])); + } + + if (array_key_exists('poster_path', $data)) { + $collection->setPoster(ImageFactory::createFromPath($data['poster_path'], 'poster_path')); + } + + return parent::hydrate($collection, $data); + } + + /** + * {@inheritdoc} + */ + public static function createCollection(array $data = array()) + { + $collection = new \Tmdb\Model\Common\Collection(); + + foreach($data as $item) { + $collection->add(null, self::create($item)); + } + + return $collection; + } +} \ No newline at end of file diff --git a/lib/Tmdb/Factory/Common/GenericCollectionFactory.php b/lib/Tmdb/Factory/Common/GenericCollectionFactory.php index a0a4fc72..2dcab652 100644 --- a/lib/Tmdb/Factory/Common/GenericCollectionFactory.php +++ b/lib/Tmdb/Factory/Common/GenericCollectionFactory.php @@ -13,7 +13,7 @@ namespace Tmdb\Factory\Common; use Tmdb\Common\ObjectHydrator; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; class GenericCollectionFactory { /** @@ -33,7 +33,7 @@ public static function createCollection(array $data = array(), $class) $class = get_class($class); } - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, ObjectHydrator::hydrate(new $class(), $item)); diff --git a/lib/Tmdb/Factory/CompanyFactory.php b/lib/Tmdb/Factory/CompanyFactory.php index 667d7123..90472e6f 100644 --- a/lib/Tmdb/Factory/CompanyFactory.php +++ b/lib/Tmdb/Factory/CompanyFactory.php @@ -12,7 +12,7 @@ */ namespace Tmdb\Factory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Company; class CompanyFactory extends AbstractFactory @@ -30,7 +30,7 @@ public static function create(array $data = array()) */ public static function createCollection(array $data = array()) { - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, self::create($item)); diff --git a/lib/Tmdb/Factory/ConfigurationFactory.php b/lib/Tmdb/Factory/ConfigurationFactory.php index 7cf37246..341c2822 100644 --- a/lib/Tmdb/Factory/ConfigurationFactory.php +++ b/lib/Tmdb/Factory/ConfigurationFactory.php @@ -12,7 +12,7 @@ */ namespace Tmdb\Factory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Configuration; class ConfigurationFactory extends AbstractFactory @@ -32,7 +32,7 @@ public static function create(array $data = array()) */ public static function createCollection(array $data = array()) { - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, self::create($item)); diff --git a/lib/Tmdb/Factory/Movie/AlternativeTitleFactory.php b/lib/Tmdb/Factory/Movie/AlternativeTitleFactory.php index bf107a99..b8417afd 100644 --- a/lib/Tmdb/Factory/Movie/AlternativeTitleFactory.php +++ b/lib/Tmdb/Factory/Movie/AlternativeTitleFactory.php @@ -13,7 +13,7 @@ namespace Tmdb\Factory\Movie; use Tmdb\Factory\AbstractFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Movie\AlternativeTitle; class AlternativeTitleFactory extends AbstractFactory @@ -33,7 +33,7 @@ public static function create(array $data = array()) */ public static function createCollection(array $data = array()) { - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, self::create($item)); diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 774a7b9d..e8f367c3 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -15,7 +15,7 @@ use Tmdb\Factory\Common\GenericCollectionFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\Trailer\Youtube; use Tmdb\Model\Common\Translation; use Tmdb\Model\Movie; @@ -107,7 +107,7 @@ public static function create(array $data = array()) */ public static function createCollection(array $data = array()) { - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, self::create($item)); diff --git a/lib/Tmdb/Factory/People/PeopleFactory.php b/lib/Tmdb/Factory/People/PeopleFactory.php index 6d559c67..568c69ac 100644 --- a/lib/Tmdb/Factory/People/PeopleFactory.php +++ b/lib/Tmdb/Factory/People/PeopleFactory.php @@ -15,7 +15,7 @@ use Tmdb\Factory\AbstractFactory; use Tmdb\Factory\ImageFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Person\CastMember; use Tmdb\Model\Person\CrewMember; use Tmdb\Model\Person; @@ -57,7 +57,7 @@ public static function create(array $data = array(), Person\AbstractMember $pers */ public static function createCollection(array $data = array(), Person\AbstractMember $person = null) { - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, self::create($item, $person)); diff --git a/lib/Tmdb/Factory/TvEpisodeFactory.php b/lib/Tmdb/Factory/TvEpisodeFactory.php index 164870a6..f18a2b81 100644 --- a/lib/Tmdb/Factory/TvEpisodeFactory.php +++ b/lib/Tmdb/Factory/TvEpisodeFactory.php @@ -15,7 +15,7 @@ use Tmdb\Factory\Common\GenericCollectionFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Tv\ExternalIds; use Tmdb\Model\Tv\Person\CastMember; @@ -64,7 +64,7 @@ public static function create(array $data = array()) */ public static function createCollection(array $data = array()) { - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, self::create($item)); diff --git a/lib/Tmdb/Factory/TvFactory.php b/lib/Tmdb/Factory/TvFactory.php index 70d9ed36..3ee5f22a 100644 --- a/lib/Tmdb/Factory/TvFactory.php +++ b/lib/Tmdb/Factory/TvFactory.php @@ -16,7 +16,7 @@ use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\Translation; use Tmdb\Model\Tv\ExternalIds; @@ -84,7 +84,7 @@ public static function create(array $data = array()) */ public static function createCollection(array $data = array()) { - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, self::create($item)); diff --git a/lib/Tmdb/Factory/TvSeasonFactory.php b/lib/Tmdb/Factory/TvSeasonFactory.php index 02eae115..c8d75caf 100644 --- a/lib/Tmdb/Factory/TvSeasonFactory.php +++ b/lib/Tmdb/Factory/TvSeasonFactory.php @@ -15,7 +15,7 @@ use Tmdb\Factory\Common\GenericCollectionFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Tv\Episode; use Tmdb\Model\Tv\ExternalIds; @@ -70,7 +70,7 @@ public static function create(array $data = array()) */ public static function createCollection(array $data = array()) { - $collection = new Collection(); + $collection = new GenericCollection(); foreach($data as $item) { $collection->add(null, self::create($item)); diff --git a/lib/Tmdb/Model/Changes.php b/lib/Tmdb/Model/Changes.php index 3cb6879e..98dad5b9 100644 --- a/lib/Tmdb/Model/Changes.php +++ b/lib/Tmdb/Model/Changes.php @@ -13,7 +13,7 @@ namespace Tmdb\Model; use Tmdb\Model\Changes\Change; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; class Changes extends AbstractModel { @@ -62,11 +62,11 @@ public function page($page = 1) { /** * Execute the current state * - * @return Collection + * @return GenericCollection */ public function execute() { - $collection = new Collection(); + $collection = new GenericCollection(); $response = $this->getClient()->api('changes')->getMovieChanges(array( 'from' => $this->from, diff --git a/lib/Tmdb/Model/Collection.php b/lib/Tmdb/Model/Collection.php new file mode 100644 index 00000000..3e5b1cfe --- /dev/null +++ b/lib/Tmdb/Model/Collection.php @@ -0,0 +1,220 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Collection\Images; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Image\BackdropImage; +use Tmdb\Model\Image\PosterImage; + +class Collection extends AbstractModel { + + /** + * @var string + */ + private $backdropPath; + + /** + * @var BackdropImage + */ + private $backdrop; + + /** + * @var integer + */ + private $id; + + /** + * @var Images + */ + private $images; + + /** + * @var string + */ + private $name; + + /** + * @var Common\GenericCollection + */ + private $parts; + + /** + * @var string + */ + private $posterPath; + + /** + * @var PosterImage + */ + private $poster; + + public static $_properties = array( + 'backdrop_path', + 'id', + 'name', + 'poster_path', + ); + + public function __construct() + { + $this->parts = new GenericCollection(); + $this->iamges = new Images(); + } + + /** + * @param \Tmdb\Model\Image\BackdropImage $backdrop + * @return $this + */ + public function setBackdrop($backdrop) + { + $this->backdrop = $backdrop; + return $this; + } + + /** + * @return \Tmdb\Model\Image\BackdropImage + */ + public function getBackdrop() + { + return $this->backdrop; + } + + /** + * @param string $backdropPath + * @return $this + */ + public function setBackdropPath($backdropPath) + { + $this->backdropPath = $backdropPath; + return $this; + } + + /** + * @return string + */ + public function getBackdropPath() + { + return $this->backdropPath; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param \Tmdb\Model\Collection\Images $images + * @return $this + */ + public function setImages($images) + { + $this->images = $images; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\Images + */ + public function getImages() + { + return $this->images; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param \Tmdb\Model\Common\Collection $parts + * @return $this + */ + public function setParts($parts) + { + $this->parts = $parts; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getParts() + { + return $this->parts; + } + + /** + * @param \Tmdb\Model\Image\PosterImage $poster + * @return $this + */ + public function setPoster($poster) + { + $this->poster = $poster; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPoster() + { + return $this->poster; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } + + +} \ No newline at end of file diff --git a/lib/Tmdb/Model/Collection/Changes.php b/lib/Tmdb/Model/Collection/Changes.php index e2922baa..20ab17aa 100644 --- a/lib/Tmdb/Model/Collection/Changes.php +++ b/lib/Tmdb/Model/Collection/Changes.php @@ -12,8 +12,8 @@ */ namespace Tmdb\Model\Common\Collection; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; -class Images extends Collection { +class Images extends GenericCollection { } \ No newline at end of file diff --git a/lib/Tmdb/Model/Collection/Genres.php b/lib/Tmdb/Model/Collection/Genres.php index b7bb1038..904649b6 100644 --- a/lib/Tmdb/Model/Collection/Genres.php +++ b/lib/Tmdb/Model/Collection/Genres.php @@ -12,10 +12,10 @@ */ namespace Tmdb\Model\Collection; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Genre; -class Genres extends Collection { +class Genres extends GenericCollection { /** * Returns all genres diff --git a/lib/Tmdb/Model/Collection/Images.php b/lib/Tmdb/Model/Collection/Images.php index bafaaeea..b8bd784c 100644 --- a/lib/Tmdb/Model/Collection/Images.php +++ b/lib/Tmdb/Model/Collection/Images.php @@ -13,12 +13,12 @@ namespace Tmdb\Model\Collection; use Tmdb\Factory\ImageFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Filter\ImageFilter; use Tmdb\Model\Image; -class Images extends Collection { +class Images extends GenericCollection { /** * Returns all images diff --git a/lib/Tmdb/Model/Collection/Keywords.php b/lib/Tmdb/Model/Collection/Keywords.php index 7386c0d1..5d6ddcea 100644 --- a/lib/Tmdb/Model/Collection/Keywords.php +++ b/lib/Tmdb/Model/Collection/Keywords.php @@ -12,11 +12,11 @@ */ namespace Tmdb\Model\Common\Collection; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Keyword; -class Keywords extends Collection { +class Keywords extends GenericCollection { /** * Returns all keywords diff --git a/lib/Tmdb/Model/Collection/People.php b/lib/Tmdb/Model/Collection/People.php index 5b1349b7..786215e0 100644 --- a/lib/Tmdb/Model/Collection/People.php +++ b/lib/Tmdb/Model/Collection/People.php @@ -12,12 +12,12 @@ */ namespace Tmdb\Model\Collection; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Collection\People\PersonInterface; use Tmdb\Model\Person; -class People extends Collection { +class People extends GenericCollection { /** * Returns all people diff --git a/lib/Tmdb/Model/Collection/QueryParameter/AppendToResponse.php b/lib/Tmdb/Model/Collection/QueryParameter/AppendToResponse.php new file mode 100644 index 00000000..740bf138 --- /dev/null +++ b/lib/Tmdb/Model/Collection/QueryParameter/AppendToResponse.php @@ -0,0 +1,19 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection\QueryParameter; + +use Tmdb\Model\Common\QueryParameter\AppendToResponse as BaseAppendToResponse; + +final class AppendToResponse extends BaseAppendToResponse { + const IMAGES = 'images'; +} \ No newline at end of file diff --git a/lib/Tmdb/Model/Common/DataCollector.php b/lib/Tmdb/Model/Common/DataCollector.php index 5c598aa8..34d9c8f2 100644 --- a/lib/Tmdb/Model/Common/DataCollector.php +++ b/lib/Tmdb/Model/Common/DataCollector.php @@ -134,11 +134,11 @@ public function collectGenres($client, array $collection = array()) * @param $client * @param array $collection * @param object $object - * @return Collection + * @return GenericCollection */ public function collectGenericCollection($client, array $collection = array(), $object) { - $collectionObject = new Collection(); + $collectionObject = new GenericCollection(); foreach($collection as $item) { $class = get_class($object); diff --git a/lib/Tmdb/Model/Common/Collection.php b/lib/Tmdb/Model/Common/GenericCollection.php similarity index 92% rename from lib/Tmdb/Model/Common/Collection.php rename to lib/Tmdb/Model/Common/GenericCollection.php index 683644b6..18a961da 100644 --- a/lib/Tmdb/Model/Common/Collection.php +++ b/lib/Tmdb/Model/Common/GenericCollection.php @@ -19,7 +19,7 @@ use Tmdb\Model\Filter\CountryFilter; use Tmdb\Model\Filter\LanguageFilter; -class Collection implements \ArrayAccess, \IteratorAggregate, \Countable { +class GenericCollection implements \ArrayAccess, \IteratorAggregate, \Countable { /** @var array Data associated with the object. */ protected $data = array(); @@ -58,7 +58,7 @@ public function toArray() /** * Removes all key value pairs * - * @return Collection + * @return GenericCollection */ public function clear() { @@ -101,7 +101,7 @@ public function get($key) * @param string $key Key to set * @param mixed $value Value to set * - * @return Collection Returns a reference to the object + * @return GenericCollection Returns a reference to the object */ public function set($key, $value) { @@ -120,7 +120,7 @@ public function set($key, $value) * @param string $key Key to add * @param mixed $value Value to add to the key * - * @return Collection Returns a reference to the object. + * @return GenericCollection Returns a reference to the object. */ public function add($key, $value) { @@ -144,7 +144,7 @@ public function add($key, $value) * * @param string $key A key to remove * - * @return Collection + * @return GenericCollection */ public function remove($key) { @@ -214,7 +214,7 @@ public function hasValue($value) * * @param array $data Associative array of data * - * @return Collection Returns a reference to the object + * @return GenericCollection Returns a reference to the object */ public function replace(array $data) { @@ -226,9 +226,9 @@ public function replace(array $data) /** * Add and merge in a Collection or array of key value pair data. * - * @param Collection|array $data Associative array of key value pair data + * @param GenericCollection|array $data Associative array of key value pair data * - * @return Collection Returns a reference to the object. + * @return GenericCollection Returns a reference to the object. */ public function merge($data) { @@ -248,7 +248,7 @@ public function merge($data) * @param array $context Context to pass to the closure * @param bool $static Set to TRUE to use the same class as the return rather than returning a Collection * - * @return Collection + * @return GenericCollection */ public function map(\Closure $closure, array $context = array(), $static = true) { @@ -268,7 +268,7 @@ public function map(\Closure $closure, array $context = array(), $static = true) * @param \Closure $closure Closure evaluation function * @param bool $static Set to TRUE to use the same class as the return rather than returning a Collection * - * @return Collection + * @return GenericCollection */ public function filter(\Closure $closure, $static = true) { @@ -306,7 +306,7 @@ public function offsetUnset($offset) * Filter by language ISO 639-1 code. * * @param string $language - * @return Collection + * @return GenericCollection */ public function filterLanguage($language = 'en') { @@ -321,7 +321,7 @@ function($key, $value) use ($language) { * Filter by country ISO 3166-1 code. * * @param string $country - * @return Collection + * @return GenericCollection */ public function filterCountry($country = 'US') { @@ -336,7 +336,7 @@ function($key, $value) use ($country) { * Filter by adult content * * @param boolean $adult - * @return Collection + * @return GenericCollection */ public function filterAdult($adult = false) { diff --git a/lib/Tmdb/Model/Common/QueryParameter/Type/CollectionToCommaSeperatedString.php b/lib/Tmdb/Model/Common/QueryParameter/Type/CollectionToCommaSeperatedString.php index 623f7a09..ec86e5da 100644 --- a/lib/Tmdb/Model/Common/QueryParameter/Type/CollectionToCommaSeperatedString.php +++ b/lib/Tmdb/Model/Common/QueryParameter/Type/CollectionToCommaSeperatedString.php @@ -12,10 +12,10 @@ */ namespace Tmdb\Model\Common\QueryParameter\Type; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\QueryParameter\QueryParameterInterface; -abstract class CollectionToCommaSeperatedString extends Collection implements QueryParameterInterface { +abstract class CollectionToCommaSeperatedString extends GenericCollection implements QueryParameterInterface { /** * @param array $collection */ diff --git a/lib/Tmdb/Model/Company.php b/lib/Tmdb/Model/Company.php index e5b78588..53e25e43 100644 --- a/lib/Tmdb/Model/Company.php +++ b/lib/Tmdb/Model/Company.php @@ -24,7 +24,7 @@ class Company extends AbstractModel { private $name; private $parentCompany; - protected static $_properties = array( + public static $_properties = array( 'description', 'headquarters', 'homepage', diff --git a/lib/Tmdb/Model/Configuration.php b/lib/Tmdb/Model/Configuration.php index d59f39b9..b2f60d43 100644 --- a/lib/Tmdb/Model/Configuration.php +++ b/lib/Tmdb/Model/Configuration.php @@ -13,7 +13,7 @@ namespace Tmdb\Model; use Tmdb\Client; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; class Configuration extends AbstractModel { diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index ffdd98af..3ce9de32 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -12,7 +12,7 @@ */ namespace Tmdb\Model; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Collection\Credits; use Tmdb\Model\Collection\Genres; @@ -246,19 +246,19 @@ class Movie extends AbstractModel { public function __construct() { $this->genres = new Genres(); - $this->productionCompanies = new Collection(); - $this->productionCountries = new Collection(); - $this->spokenLanguages = new Collection(); - $this->alternativeTitles = new Collection(); - $this->changes = new Collection(); + $this->productionCompanies = new GenericCollection(); + $this->productionCountries = new GenericCollection(); + $this->spokenLanguages = new GenericCollection(); + $this->alternativeTitles = new GenericCollection(); + $this->changes = new GenericCollection(); $this->credits = new Credits(); $this->images = new Images(); - $this->keywords = new Collection(); - $this->lists = new Collection(); - $this->releases = new Collection(); - $this->similarMovies = new Collection(); - $this->trailers = new Collection(); - $this->translations = new Collection(); + $this->keywords = new GenericCollection(); + $this->lists = new GenericCollection(); + $this->releases = new GenericCollection(); + $this->similarMovies = new GenericCollection(); + $this->trailers = new GenericCollection(); + $this->translations = new GenericCollection(); } /** @@ -316,10 +316,10 @@ public function getBelongsToCollection() } /** - * @param Collection $changes + * @param GenericCollection $changes * @return $this */ - public function setChanges(Collection $changes) + public function setChanges(GenericCollection $changes) { $this->changes = $changes; return $this; @@ -496,10 +496,10 @@ public function getPosterPath() } /** - * @param Collection $productionCompanies + * @param GenericCollection $productionCompanies * @return $this */ - public function setProductionCompanies(Collection $productionCompanies) + public function setProductionCompanies(GenericCollection $productionCompanies) { $this->productionCompanies = $productionCompanies; return $this; @@ -514,10 +514,10 @@ public function getProductionCompanies() } /** - * @param Collection $productionCountries + * @param GenericCollection $productionCountries * @return $this */ - public function setProductionCountries(Collection $productionCountries) + public function setProductionCountries(GenericCollection $productionCountries) { $this->productionCountries = $productionCountries; return $this; @@ -586,10 +586,10 @@ public function getRuntime() } /** - * @param Collection $spokenLanguages + * @param GenericCollection $spokenLanguages * @return $this */ - public function setSpokenLanguages(Collection $spokenLanguages) + public function setSpokenLanguages(GenericCollection $spokenLanguages) { $this->spokenLanguages = $spokenLanguages; return $this; @@ -730,7 +730,7 @@ public function getCrew() } /** - * @param Collection $alternativeTitles + * @param GenericCollection $alternativeTitles * @return $this */ public function setAlternativeTitles($alternativeTitles) @@ -784,7 +784,7 @@ public function getCredits() } /** - * @param Collection $keywords + * @param GenericCollection $keywords * @return $this */ public function setKeywords($keywords) @@ -802,7 +802,7 @@ public function getKeywords() } /** - * @param Collection $lists + * @param GenericCollection $lists * @return $this */ public function setLists($lists) @@ -812,7 +812,7 @@ public function setLists($lists) } /** - * @return Collection + * @return GenericCollection */ public function getLists() { @@ -820,10 +820,10 @@ public function getLists() } /** - * @param Collection $releases + * @param GenericCollection $releases * @return $this */ - public function setReleases(Collection $releases) + public function setReleases(GenericCollection $releases) { $this->releases = $releases; return $this; @@ -838,7 +838,7 @@ public function getReleases() } /** - * @param Collection $similarMovies + * @param GenericCollection $similarMovies * @return $this */ public function setSimilarMovies($similarMovies) @@ -856,7 +856,7 @@ public function getSimilarMovies() } /** - * @param Collection $trailers + * @param GenericCollection $trailers * @return $this */ public function setTrailers($trailers) @@ -876,7 +876,7 @@ public function getTrailers() } /** - * @param Collection $translations + * @param GenericCollection $translations * @return $this */ public function setTranslations($translations) diff --git a/lib/Tmdb/Model/Person.php b/lib/Tmdb/Model/Person.php index 7ca08cd6..b2d6cb07 100644 --- a/lib/Tmdb/Model/Person.php +++ b/lib/Tmdb/Model/Person.php @@ -14,10 +14,11 @@ use Tmdb\Model\Collection\Credits; -use Tmdb\Model\Common\Collection; -use Tmdb\Model\Common\Collection\Images; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Collection\Images; use Tmdb\Model\Collection\People\PersonInterface; +use Tmdb\Model\Image\ProfileImage; class Person extends AbstractModel implements PersonInterface { @@ -33,6 +34,7 @@ class Person extends AbstractModel implements PersonInterface { private $job; private $placeOfBirth; private $profilePath; + private $profile; protected $credits; protected $images; @@ -60,7 +62,7 @@ public function __construct() { $this->credits = new Credits(); $this->images = new Images(); - $this->changes = new Collection(); + $this->changes = new GenericCollection(); } /** @@ -333,4 +335,21 @@ public function getJob() return $this->job; } + /** + * @param ProfileImage $profile + * @return $this + */ + public function setProfile($profile) + { + $this->profile = $profile; + return $this; + } + + /** + * @return ProfileImage + */ + public function getProfile() + { + return $this->profile; + } } \ No newline at end of file diff --git a/lib/Tmdb/Model/Query/Changes.php b/lib/Tmdb/Model/Query/Changes.php index eddf1a51..74d1a0fc 100644 --- a/lib/Tmdb/Model/Query/Changes.php +++ b/lib/Tmdb/Model/Query/Changes.php @@ -13,7 +13,7 @@ namespace Tmdb\Model; use Tmdb\Model\Changes\Change; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; class Changes extends AbstractQuery { @@ -62,11 +62,11 @@ public function page($page = 1) { /** * Execute the current state * - * @return Collection + * @return GenericCollection */ public function execute() { - $collection = new Collection(); + $collection = new GenericCollection(); $response = $this->getClient()->getChangesApi()->getMovieChanges(array( 'from' => $this->from, diff --git a/lib/Tmdb/Model/Query/Discover.php b/lib/Tmdb/Model/Query/Discover.php index ccd852da..6b2fcc67 100644 --- a/lib/Tmdb/Model/Query/Discover.php +++ b/lib/Tmdb/Model/Query/Discover.php @@ -14,7 +14,7 @@ use Tmdb\Model\AbstractQuery; use Tmdb\Model\Changes\Change; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; class Discover extends AbstractQuery { @@ -63,11 +63,11 @@ public function page($page = 1) { /** * Execute the current state * - * @return Collection + * @return GenericCollection */ public function execute() { - $collection = new Collection(); + $collection = new GenericCollection(); $response = $this->getClient()->api('changes')->getMovieChanges(array( 'from' => $this->from, diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index dd402e85..3608b267 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -12,7 +12,7 @@ */ namespace Tmdb\Model; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Collection\Credits; use Tmdb\Model\Collection\Genres; @@ -210,17 +210,17 @@ class Tv extends AbstractModel { public function __construct() { $this->createdBy = new Images(); - $this->episodeRunTime = new Collection(); - $this->genres = new Collection(); - $this->languages = new Collection(); - $this->networks = new Collection(); - $this->originCountry = new Collection(); - $this->seasons = new Collection(); + $this->episodeRunTime = new GenericCollection(); + $this->genres = new GenericCollection(); + $this->languages = new GenericCollection(); + $this->networks = new GenericCollection(); + $this->originCountry = new GenericCollection(); + $this->seasons = new GenericCollection(); $this->credits = new Credits(); $this->externalIds = new ExternalIds(); $this->images = new Images(); - $this->translations = new Collection(); + $this->translations = new GenericCollection(); } /** @@ -422,7 +422,7 @@ public function getName() } /** - * @param Collection $networks + * @param GenericCollection $networks * @return $this */ public function setNetworks($networks) diff --git a/lib/Tmdb/Model/Tv/Episode.php b/lib/Tmdb/Model/Tv/Episode.php index f3c2ce86..edbaae5a 100644 --- a/lib/Tmdb/Model/Tv/Episode.php +++ b/lib/Tmdb/Model/Tv/Episode.php @@ -15,7 +15,7 @@ use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\Credits; use Tmdb\Model\Collection\Images; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; class Episode extends AbstractModel { diff --git a/lib/Tmdb/Model/Tv/Season.php b/lib/Tmdb/Model/Tv/Season.php index f3a1742e..86e81f04 100644 --- a/lib/Tmdb/Model/Tv/Season.php +++ b/lib/Tmdb/Model/Tv/Season.php @@ -15,7 +15,7 @@ use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\Credits; use Tmdb\Model\Collection\Images; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; class Season extends AbstractModel { @@ -99,7 +99,7 @@ public function __construct() $this->credits = new Credits(); $this->externalIds = new ExternalIds(); $this->images = new Images(); - $this->episodes = new Collection(); + $this->episodes = new GenericCollection(); } /** @@ -121,7 +121,7 @@ public function getAirDate() } /** - * @param Collection $episodes + * @param GenericCollection $episodes * @return $this */ public function setEpisodes($episodes) @@ -229,7 +229,7 @@ public function getSeasonNumber() } /** - * @param Collection $credits + * @param GenericCollection $credits * @return $this */ public function setCredits($credits) diff --git a/lib/Tmdb/Repository/ChangesRepository.php b/lib/Tmdb/Repository/ChangesRepository.php index 7011744a..00affd21 100644 --- a/lib/Tmdb/Repository/ChangesRepository.php +++ b/lib/Tmdb/Repository/ChangesRepository.php @@ -12,44 +12,60 @@ */ namespace Tmdb\Repository; -use Tmdb\Factory\CompanyFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Factory\MovieFactory; +use Tmdb\Factory\People\PeopleFactory; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Company; +use Tmdb\Model\Movie; -class CompanyRepository extends AbstractRepository { +class ChangesRepository extends AbstractRepository { /** - * Load a company with the given identifier + * Get a list of movie ids that have been edited. + * + * By default we show the last 24 hours and only 100 items per page. + * The maximum number of days that can be returned in a single request is 14. + * + * You can then use the movie changes API to get the actual data that has been changed. + * Please note that the change log system to support this was changed on October 5, 2012 + * and will only show movies that have been edited since. * - * @param $id * @param array $parameters * @param array $headers - * @return Company + * @return GenericCollection */ - public function load($id, array $parameters = array(), array $headers = array()) { - $data = $this->getApi()->getCompany($id, $this->parseQueryParameters($parameters), $this->parseHeaders($headers)); + public function getMovieChanges(array $parameters = array(), array $headers = array()) { + $data = $this->getApi()->getMovieChanges($this->parseQueryParameters($parameters), $this->parseHeaders($headers)); - return CompanyFactory::create($data); + return MovieFactory::createCollection($data); } /** - * If you obtained an person model which is not completely hydrated, you can use this function. + * Get a list of people ids that have been edited. + * + * By default we show the last 24 hours and only 100 items per page. + * The maximum number of days that can be returned in a single request is 14. + * + * You can then use the person changes API to get the actual data that has been changed. + * Please note that the change log system to support this was changed on October 5, 2012 + * and will only show people that have been edited since. * - * @param Company $company * @param array $parameters * @param array $headers - * @return Company + * @return GenericCollection */ - public function refresh(Company $company, array $parameters = array(), array $headers = array()) { - return $this->load($company->getId(), $parameters, $headers); + public function getPeopleChanges(array $parameters = array(), array $headers = array()) { + $data = $this->getApi()->getPeopleChanges($this->parseQueryParameters($parameters), $this->parseHeaders($headers)); + + return PeopleFactory::createCollection($data); } /** * Return the related API class * - * @return \Tmdb\Api\Companies + * @return \Tmdb\Api\Changes */ public function getApi() { - return $this->getClient()->getCompaniesApi(); + return $this->getClient()->getChangesApi(); } } \ No newline at end of file diff --git a/lib/Tmdb/Repository/CollectionRepository.php b/lib/Tmdb/Repository/CollectionRepository.php new file mode 100644 index 00000000..d4eda989 --- /dev/null +++ b/lib/Tmdb/Repository/CollectionRepository.php @@ -0,0 +1,71 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\CollectionFactory; +use Tmdb\Factory\ImageFactory; +use Tmdb\Model\Collection as ApiCollection; + +use \Tmdb\Model\Collection\QueryParameter\AppendToResponse; + +class CollectionRepository extends AbstractRepository { + + /** + * Load a collection with the given identifier + * + * If you want to optimize the result set/bandwidth you should define the AppendToResponse parameter + * + * @param $id + * @param $parameters + * @param $headers + * @return ApiCollection + */ + public function load($id, array $parameters = array(), array $headers = array()) + { + if (empty($parameters)) { + $parameters = array( + new AppendToResponse(array( + AppendToResponse::IMAGES, + )) + ); + } + + $data = $this->getApi()->getCollection($id, $this->parseQueryParameters($parameters), $this->parseHeaders($headers)); + return CollectionFactory::create($data); + } + + /** + * Return the Collection API Class + * + * @return \Tmdb\Api\Collections + */ + public function getApi() + { + return $this->getClient()->getCollectionsApi(); + } + + /** + * Get all of the images for a particular collection by collection id. + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Images + */ + public function getImages($id, array $parameters = array(), array $headers = array()) + { + return ImageFactory::createCollection( + $this->getApi()->getImages($id, $parameters, $headers) + ); + } +} \ No newline at end of file diff --git a/lib/Tmdb/Repository/CompanyRepository.php b/lib/Tmdb/Repository/CompanyRepository.php index 7011744a..f2316f64 100644 --- a/lib/Tmdb/Repository/CompanyRepository.php +++ b/lib/Tmdb/Repository/CompanyRepository.php @@ -13,7 +13,7 @@ namespace Tmdb\Repository; use Tmdb\Factory\CompanyFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Company; class CompanyRepository extends AbstractRepository { diff --git a/lib/Tmdb/Repository/GenreRepository.php b/lib/Tmdb/Repository/GenreRepository.php index 32b5fc19..58a6848f 100644 --- a/lib/Tmdb/Repository/GenreRepository.php +++ b/lib/Tmdb/Repository/GenreRepository.php @@ -13,7 +13,7 @@ namespace Tmdb\Repository; use Tmdb\Factory\GenreFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Genre; class GenreRepository extends AbstractRepository { @@ -47,7 +47,7 @@ public function refresh(Genre $genre, array $parameters = array(), array $header * Get the list of genres. * * @param array $options - * @return Collection + * @return GenericCollection */ public function loadCollection(array $options = array()) { @@ -60,10 +60,10 @@ public function loadCollection(array $options = array()) * Create an collection of an array * * @param $data - * @return Collection + * @return GenericCollection */ private function createCollection($data){ - $collection = new Collection(); + $collection = new GenericCollection(); if (array_key_exists('genres', $data)) { $data = $data['genres']; diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index f67a51e2..71826fd5 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -13,7 +13,7 @@ namespace Tmdb\Repository; use Tmdb\Factory\MovieFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Movie; use \Tmdb\Model\Movie\QueryParameter\AppendToResponse; @@ -98,7 +98,7 @@ public function getLatest(array $options = array()) * Get the list of upcoming movies. This list refreshes every day. The maximum number of items this list will include is 100. * * @param array $options - * @return Collection + * @return GenericCollection */ public function getUpcoming(array $options = array()) { @@ -111,7 +111,7 @@ public function getUpcoming(array $options = array()) * Get the list of movies playing in theatres. This list refreshes every day. The maximum number of items this list will include is 100. * * @param array $options - * @return Collection + * @return GenericCollection */ public function getNowPlaying(array $options = array()) { @@ -124,7 +124,7 @@ public function getNowPlaying(array $options = array()) * Get the list of popular movies on The Movie Database. This list refreshes every day. * * @param array $options - * @return Collection + * @return GenericCollection */ public function getPopular(array $options = array()) { @@ -137,7 +137,7 @@ public function getPopular(array $options = array()) * Get the list of top rated movies. By default, this list will only include movies that have 10 or more votes. This list refreshes every day. * * @param array $options - * @return Collection + * @return GenericCollection */ public function getTopRated(array $options = array()) { @@ -152,10 +152,10 @@ public function getTopRated(array $options = array()) * @todo Allow an array of Movie objects to pass ( custom collection ) * * @param $data - * @return Collection + * @return GenericCollection */ private function createCollection($data){ - $collection = new Collection(); + $collection = new GenericCollection(); if (array_key_exists('results', $data)) { $data = $data['results']; diff --git a/lib/Tmdb/Repository/TvEpisodeRepository.php b/lib/Tmdb/Repository/TvEpisodeRepository.php index 11cc4214..8d8d6ddd 100644 --- a/lib/Tmdb/Repository/TvEpisodeRepository.php +++ b/lib/Tmdb/Repository/TvEpisodeRepository.php @@ -14,7 +14,7 @@ use \RuntimeException; use Tmdb\Factory\TvEpisodeFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use \Tmdb\Model\Tv\Episode\QueryParameter\AppendToResponse; @@ -97,10 +97,10 @@ public function getApi() * Create an collection of an array * * @param $data - * @return Collection + * @return GenericCollection */ private function createCollection($data){ - $collection = new Collection(); + $collection = new GenericCollection(); if (array_key_exists('results', $data)) { $data = $data['results']; diff --git a/lib/Tmdb/Repository/TvRepository.php b/lib/Tmdb/Repository/TvRepository.php index e537603f..64740f4e 100644 --- a/lib/Tmdb/Repository/TvRepository.php +++ b/lib/Tmdb/Repository/TvRepository.php @@ -13,7 +13,7 @@ namespace Tmdb\Repository; use Tmdb\Factory\TvFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Tv; use \Tmdb\Model\Tv\QueryParameter\AppendToResponse; @@ -79,7 +79,7 @@ public function getApi() * Get the list of popular tvs on The Tv Database. This list refreshes every day. * * @param array $options - * @return Collection + * @return GenericCollection */ public function getPopular(array $options = array()) { @@ -92,7 +92,7 @@ public function getPopular(array $options = array()) * 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 Collection + * @return GenericCollection */ public function getTopRated(array $options = array()) { @@ -107,10 +107,10 @@ public function getTopRated(array $options = array()) * @todo Allow an array of Tv objects to pass ( custom collection ) * * @param $data - * @return Collection + * @return GenericCollection */ private function createCollection($data){ - $collection = new Collection(); + $collection = new GenericCollection(); if (array_key_exists('results', $data)) { $data = $data['results']; diff --git a/lib/Tmdb/Repository/TvSeasonRepository.php b/lib/Tmdb/Repository/TvSeasonRepository.php index 74d3c7d1..26670469 100644 --- a/lib/Tmdb/Repository/TvSeasonRepository.php +++ b/lib/Tmdb/Repository/TvSeasonRepository.php @@ -15,7 +15,7 @@ use \RuntimeException; use Tmdb\Factory\TvSeasonFactory; -use Tmdb\Model\Common\Collection; +use Tmdb\Model\Common\GenericCollection; use \Tmdb\Model\Tv\Season\QueryParameter\AppendToResponse; use Tmdb\Model\Tv\Season; @@ -93,10 +93,10 @@ public function getApi() * @todo Allow an array of Season objects to pass ( custom collection ) * * @param $data - * @return Collection + * @return GenericCollection */ private function createCollection($data){ - $collection = new Collection(); + $collection = new GenericCollection(); if (array_key_exists('results', $data)) { $data = $data['results'];