From d5d84d6462bde3fc91870c46935f99ef2de1e582 Mon Sep 17 00:00:00 2001 From: Afterster Date: Tue, 17 Jun 2014 19:10:43 +0200 Subject: [PATCH] Add php-tmdb-api module --- README.md | 3 +- modules/Tmdb/Api/AbstractApi.php | 169 ++++ modules/Tmdb/Api/Account.php | 118 +++ modules/Tmdb/Api/ApiInterface.php | 20 + modules/Tmdb/Api/Authentication.php | 93 ++ modules/Tmdb/Api/Certifications.php | 36 + modules/Tmdb/Api/Changes.php | 62 ++ modules/Tmdb/Api/Collections.php | 54 + modules/Tmdb/Api/Companies.php | 48 + modules/Tmdb/Api/Configuration.php | 48 + modules/Tmdb/Api/Credits.php | 42 + modules/Tmdb/Api/Discover.php | 46 + modules/Tmdb/Api/Find.php | 45 + modules/Tmdb/Api/Genres.php | 81 ++ modules/Tmdb/Api/Jobs.php | 34 + modules/Tmdb/Api/Keywords.php | 48 + modules/Tmdb/Api/Lists.php | 102 ++ modules/Tmdb/Api/Movies.php | 262 +++++ modules/Tmdb/Api/Networks.php | 38 + modules/Tmdb/Api/People.php | 160 +++ modules/Tmdb/Api/Reviews.php | 35 + modules/Tmdb/Api/Search.php | 127 +++ modules/Tmdb/Api/Tv.php | 118 +++ modules/Tmdb/Api/TvEpisode.php | 82 ++ modules/Tmdb/Api/TvSeason.php | 78 ++ modules/Tmdb/ApiToken.php | 49 + modules/Tmdb/Client.php | 355 +++++++ modules/Tmdb/Common/ObjectHydrator.php | 81 ++ .../Exception/InvalidArgumentException.php | 21 + .../Exception/MissingArgumentException.php | 21 + .../Exception/NotImplementedException.php | 21 + modules/Tmdb/Exception/RuntimeException.php | 21 + .../UnauthorizedRequestTokenException.php | 21 + modules/Tmdb/Factory/AbstractFactory.php | 110 +++ modules/Tmdb/Factory/AccountFactory.php | 131 +++ .../Tmdb/Factory/AuthenticationFactory.php | 117 +++ modules/Tmdb/Factory/CertificationFactory.php | 60 ++ modules/Tmdb/Factory/ChangesFactory.php | 62 ++ modules/Tmdb/Factory/CollectionFactory.php | 121 +++ modules/Tmdb/Factory/Common/ChangeFactory.php | 75 ++ .../Common/GenericCollectionFactory.php | 55 ++ modules/Tmdb/Factory/CompanyFactory.php | 75 ++ modules/Tmdb/Factory/ConfigurationFactory.php | 40 + modules/Tmdb/Factory/CreditsFactory.php | 144 +++ modules/Tmdb/Factory/FindFactory.php | 134 +++ modules/Tmdb/Factory/GenreFactory.php | 52 + modules/Tmdb/Factory/ImageFactory.php | 202 ++++ modules/Tmdb/Factory/JobsFactory.php | 49 + modules/Tmdb/Factory/KeywordFactory.php | 52 + modules/Tmdb/Factory/ListFactory.php | 145 +++ .../Tmdb/Factory/Lists/ListItemFactory.php | 92 ++ .../Factory/Movie/AlternativeTitleFactory.php | 48 + .../Tmdb/Factory/Movie/ListItemFactory.php | 71 ++ modules/Tmdb/Factory/MovieFactory.php | 370 +++++++ modules/Tmdb/Factory/NetworkFactory.php | 52 + modules/Tmdb/Factory/People/CastFactory.php | 53 + modules/Tmdb/Factory/People/CrewFactory.php | 53 + modules/Tmdb/Factory/PeopleFactory.php | 206 ++++ modules/Tmdb/Factory/ReviewFactory.php | 40 + modules/Tmdb/Factory/TvEpisodeFactory.php | 166 ++++ modules/Tmdb/Factory/TvFactory.php | 263 +++++ modules/Tmdb/Factory/TvSeasonFactory.php | 189 ++++ modules/Tmdb/Helper/ImageHelper.php | 93 ++ modules/Tmdb/HttpClient/HttpClient.php | 204 ++++ .../Tmdb/HttpClient/HttpClientInterface.php | 103 ++ .../Plugin/AcceptJsonHeaderPlugin.php | 33 + .../HttpClient/Plugin/AdultFilterPlugin.php | 44 + .../Tmdb/HttpClient/Plugin/ApiTokenPlugin.php | 48 + .../Plugin/LanguageFilterPlugin.php | 44 + .../HttpClient/Plugin/SessionTokenPlugin.php | 48 + modules/Tmdb/Model/AbstractModel.php | 27 + modules/Tmdb/Model/Account.php | 171 ++++ modules/Tmdb/Model/Account/ListItem.php | 243 +++++ modules/Tmdb/Model/Certification.php | 77 ++ .../Certification/CountryCertification.php | 99 ++ modules/Tmdb/Model/Change.php | 73 ++ modules/Tmdb/Model/Collection.php | 246 +++++ modules/Tmdb/Model/Collection/Changes.php | 19 + .../Model/Collection/CreditsCollection.php | 78 ++ .../CreditsCollection/CombinedCredits.php | 21 + .../CreditsCollection/MovieCredits.php | 21 + .../CreditsCollection/TvCredits.php | 21 + modules/Tmdb/Model/Collection/Genres.php | 59 ++ modules/Tmdb/Model/Collection/Images.php | 193 ++++ modules/Tmdb/Model/Collection/Jobs.php | 94 ++ modules/Tmdb/Model/Collection/Keywords.php | 53 + modules/Tmdb/Model/Collection/People.php | 54 + modules/Tmdb/Model/Collection/People/Cast.php | 42 + modules/Tmdb/Model/Collection/People/Crew.php | 42 + .../Collection/People/PersonInterface.php | 26 + .../QueryParameter/AppendToResponse.php | 23 + .../Collection/QueryParametersCollection.php | 21 + .../Model/Collection/ResultCollection.php | 99 ++ modules/Tmdb/Model/Common/AbstractTrailer.php | 28 + modules/Tmdb/Model/Common/Change.php | 79 ++ modules/Tmdb/Model/Common/Change/Item.php | 128 +++ modules/Tmdb/Model/Common/Country.php | 67 ++ modules/Tmdb/Model/Common/ExternalIds.php | 146 +++ .../Tmdb/Model/Common/GenericCollection.php | 374 +++++++ .../Model/Common/QueryParameter/Adult.php | 43 + .../QueryParameter/AppendToResponse.php | 29 + .../Model/Common/QueryParameter/Language.php | 43 + .../QueryParameterInterface.php | 29 + .../Type/CollectionToCommaSeperatedString.php | 44 + modules/Tmdb/Model/Common/SpokenLanguage.php | 67 ++ modules/Tmdb/Model/Common/Trailer/Youtube.php | 120 +++ modules/Tmdb/Model/Common/Translation.php | 48 + modules/Tmdb/Model/Company.php | 185 ++++ modules/Tmdb/Model/Configuration.php | 71 ++ modules/Tmdb/Model/Credits.php | 198 ++++ modules/Tmdb/Model/Credits/Media.php | 167 ++++ modules/Tmdb/Model/Filter/AdultFilter.php | 21 + modules/Tmdb/Model/Filter/CountryFilter.php | 25 + modules/Tmdb/Model/Filter/ImageFilter.php | 20 + modules/Tmdb/Model/Filter/LanguageFilter.php | 21 + modules/Tmdb/Model/Find.php | 94 ++ modules/Tmdb/Model/Genre.php | 64 ++ modules/Tmdb/Model/Image.php | 197 ++++ modules/Tmdb/Model/Image/BackdropImage.php | 21 + modules/Tmdb/Model/Image/LogoImage.php | 21 + modules/Tmdb/Model/Image/PosterImage.php | 21 + modules/Tmdb/Model/Image/ProfileImage.php | 21 + modules/Tmdb/Model/Image/StillImage.php | 21 + modules/Tmdb/Model/Job.php | 69 ++ modules/Tmdb/Model/Keyword.php | 64 ++ modules/Tmdb/Model/Lists.php | 269 +++++ modules/Tmdb/Model/Lists/ItemStatus.php | 75 ++ modules/Tmdb/Model/Lists/ListItem.php | 267 +++++ modules/Tmdb/Model/Lists/Result.php | 75 ++ modules/Tmdb/Model/Lists/ResultWithListId.php | 51 + modules/Tmdb/Model/Movie.php | 919 ++++++++++++++++++ modules/Tmdb/Model/Movie/AccountStates.php | 120 +++ modules/Tmdb/Model/Movie/AlternativeTitle.php | 67 ++ modules/Tmdb/Model/Movie/ListItem.php | 219 +++++ .../Movie/QueryParameter/AppendToResponse.php | 33 + modules/Tmdb/Model/Movie/Rating.php | 49 + modules/Tmdb/Model/Movie/Release.php | 91 ++ modules/Tmdb/Model/Network.php | 64 ++ modules/Tmdb/Model/Person.php | 484 +++++++++ modules/Tmdb/Model/Person/AbstractMember.php | 131 +++ modules/Tmdb/Model/Person/CastMember.php | 100 ++ modules/Tmdb/Model/Person/CrewMember.php | 76 ++ modules/Tmdb/Model/Person/MovieCredit.php | 247 +++++ .../QueryParameter/AppendToResponse.php | 28 + modules/Tmdb/Model/Query/ChangesQuery.php | 60 ++ .../Query/Discover/DiscoverMoviesQuery.php | 278 ++++++ .../Model/Query/Discover/DiscoverTvQuery.php | 219 +++++ modules/Tmdb/Model/Query/FindQuery.php | 24 + modules/Tmdb/Model/Review.php | 186 ++++ modules/Tmdb/Model/Search/SearchQuery.php | 47 + .../SearchQuery/CollectionSearchQuery.php | 34 + .../Search/SearchQuery/CompanySearchQuery.php | 21 + .../Search/SearchQuery/KeywordSearchQuery.php | 21 + .../Search/SearchQuery/ListSearchQuery.php | 35 + .../Search/SearchQuery/MovieSearchQuery.php | 95 ++ .../Search/SearchQuery/PersonSearchQuery.php | 53 + .../Search/SearchQuery/TvSearchQuery.php | 69 ++ modules/Tmdb/Model/Tv.php | 763 +++++++++++++++ modules/Tmdb/Model/Tv/Episode.php | 389 ++++++++ .../QueryParameter/AppendToResponse.php | 25 + modules/Tmdb/Model/Tv/Network.php | 80 ++ .../Tv/QueryParameter/AppendToResponse.php | 26 + modules/Tmdb/Model/Tv/Season.php | 313 ++++++ .../QueryParameter/AppendToResponse.php | 25 + .../Tmdb/Repository/AbstractRepository.php | 88 ++ modules/Tmdb/Repository/AccountRepository.php | 147 +++ .../Repository/AuthenticationRepository.php | 99 ++ .../Repository/CertificationRepository.php | 57 ++ modules/Tmdb/Repository/ChangesRepository.php | 83 ++ .../Tmdb/Repository/CollectionRepository.php | 112 +++ modules/Tmdb/Repository/CompanyRepository.php | 103 ++ .../Repository/ConfigurationRepository.php | 54 + modules/Tmdb/Repository/CreditsRepository.php | 58 ++ .../Tmdb/Repository/DiscoverRepository.php | 99 ++ modules/Tmdb/Repository/FindRepository.php | 55 ++ modules/Tmdb/Repository/GenreRepository.php | 93 ++ modules/Tmdb/Repository/JobsRepository.php | 75 ++ modules/Tmdb/Repository/KeywordRepository.php | 71 ++ modules/Tmdb/Repository/ListRepository.php | 129 +++ modules/Tmdb/Repository/MovieRepository.php | 441 +++++++++ modules/Tmdb/Repository/NetworkRepository.php | 58 ++ modules/Tmdb/Repository/PeopleRepository.php | 202 ++++ modules/Tmdb/Repository/ReviewRepository.php | 55 ++ modules/Tmdb/Repository/SearchRepository.php | 345 +++++++ .../Tmdb/Repository/TvEpisodeRepository.php | 184 ++++ modules/Tmdb/Repository/TvRepository.php | 179 ++++ .../Tmdb/Repository/TvSeasonRepository.php | 165 ++++ modules/Tmdb/RequestToken.php | 106 ++ modules/Tmdb/SessionToken.php | 102 ++ 189 files changed, 20018 insertions(+), 1 deletion(-) create mode 100644 modules/Tmdb/Api/AbstractApi.php create mode 100644 modules/Tmdb/Api/Account.php create mode 100644 modules/Tmdb/Api/ApiInterface.php create mode 100644 modules/Tmdb/Api/Authentication.php create mode 100644 modules/Tmdb/Api/Certifications.php create mode 100644 modules/Tmdb/Api/Changes.php create mode 100644 modules/Tmdb/Api/Collections.php create mode 100644 modules/Tmdb/Api/Companies.php create mode 100644 modules/Tmdb/Api/Configuration.php create mode 100644 modules/Tmdb/Api/Credits.php create mode 100644 modules/Tmdb/Api/Discover.php create mode 100644 modules/Tmdb/Api/Find.php create mode 100644 modules/Tmdb/Api/Genres.php create mode 100644 modules/Tmdb/Api/Jobs.php create mode 100644 modules/Tmdb/Api/Keywords.php create mode 100644 modules/Tmdb/Api/Lists.php create mode 100644 modules/Tmdb/Api/Movies.php create mode 100644 modules/Tmdb/Api/Networks.php create mode 100644 modules/Tmdb/Api/People.php create mode 100644 modules/Tmdb/Api/Reviews.php create mode 100644 modules/Tmdb/Api/Search.php create mode 100644 modules/Tmdb/Api/Tv.php create mode 100644 modules/Tmdb/Api/TvEpisode.php create mode 100644 modules/Tmdb/Api/TvSeason.php create mode 100644 modules/Tmdb/ApiToken.php create mode 100644 modules/Tmdb/Client.php create mode 100644 modules/Tmdb/Common/ObjectHydrator.php create mode 100644 modules/Tmdb/Exception/InvalidArgumentException.php create mode 100644 modules/Tmdb/Exception/MissingArgumentException.php create mode 100644 modules/Tmdb/Exception/NotImplementedException.php create mode 100644 modules/Tmdb/Exception/RuntimeException.php create mode 100644 modules/Tmdb/Exception/UnauthorizedRequestTokenException.php create mode 100644 modules/Tmdb/Factory/AbstractFactory.php create mode 100644 modules/Tmdb/Factory/AccountFactory.php create mode 100644 modules/Tmdb/Factory/AuthenticationFactory.php create mode 100644 modules/Tmdb/Factory/CertificationFactory.php create mode 100644 modules/Tmdb/Factory/ChangesFactory.php create mode 100644 modules/Tmdb/Factory/CollectionFactory.php create mode 100644 modules/Tmdb/Factory/Common/ChangeFactory.php create mode 100644 modules/Tmdb/Factory/Common/GenericCollectionFactory.php create mode 100644 modules/Tmdb/Factory/CompanyFactory.php create mode 100644 modules/Tmdb/Factory/ConfigurationFactory.php create mode 100644 modules/Tmdb/Factory/CreditsFactory.php create mode 100644 modules/Tmdb/Factory/FindFactory.php create mode 100644 modules/Tmdb/Factory/GenreFactory.php create mode 100644 modules/Tmdb/Factory/ImageFactory.php create mode 100644 modules/Tmdb/Factory/JobsFactory.php create mode 100644 modules/Tmdb/Factory/KeywordFactory.php create mode 100644 modules/Tmdb/Factory/ListFactory.php create mode 100644 modules/Tmdb/Factory/Lists/ListItemFactory.php create mode 100644 modules/Tmdb/Factory/Movie/AlternativeTitleFactory.php create mode 100644 modules/Tmdb/Factory/Movie/ListItemFactory.php create mode 100644 modules/Tmdb/Factory/MovieFactory.php create mode 100644 modules/Tmdb/Factory/NetworkFactory.php create mode 100644 modules/Tmdb/Factory/People/CastFactory.php create mode 100644 modules/Tmdb/Factory/People/CrewFactory.php create mode 100644 modules/Tmdb/Factory/PeopleFactory.php create mode 100644 modules/Tmdb/Factory/ReviewFactory.php create mode 100644 modules/Tmdb/Factory/TvEpisodeFactory.php create mode 100644 modules/Tmdb/Factory/TvFactory.php create mode 100644 modules/Tmdb/Factory/TvSeasonFactory.php create mode 100644 modules/Tmdb/Helper/ImageHelper.php create mode 100644 modules/Tmdb/HttpClient/HttpClient.php create mode 100644 modules/Tmdb/HttpClient/HttpClientInterface.php create mode 100644 modules/Tmdb/HttpClient/Plugin/AcceptJsonHeaderPlugin.php create mode 100644 modules/Tmdb/HttpClient/Plugin/AdultFilterPlugin.php create mode 100644 modules/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php create mode 100644 modules/Tmdb/HttpClient/Plugin/LanguageFilterPlugin.php create mode 100644 modules/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php create mode 100644 modules/Tmdb/Model/AbstractModel.php create mode 100644 modules/Tmdb/Model/Account.php create mode 100644 modules/Tmdb/Model/Account/ListItem.php create mode 100644 modules/Tmdb/Model/Certification.php create mode 100644 modules/Tmdb/Model/Certification/CountryCertification.php create mode 100644 modules/Tmdb/Model/Change.php create mode 100644 modules/Tmdb/Model/Collection.php create mode 100644 modules/Tmdb/Model/Collection/Changes.php create mode 100644 modules/Tmdb/Model/Collection/CreditsCollection.php create mode 100644 modules/Tmdb/Model/Collection/CreditsCollection/CombinedCredits.php create mode 100644 modules/Tmdb/Model/Collection/CreditsCollection/MovieCredits.php create mode 100644 modules/Tmdb/Model/Collection/CreditsCollection/TvCredits.php create mode 100644 modules/Tmdb/Model/Collection/Genres.php create mode 100644 modules/Tmdb/Model/Collection/Images.php create mode 100644 modules/Tmdb/Model/Collection/Jobs.php create mode 100644 modules/Tmdb/Model/Collection/Keywords.php create mode 100644 modules/Tmdb/Model/Collection/People.php create mode 100644 modules/Tmdb/Model/Collection/People/Cast.php create mode 100644 modules/Tmdb/Model/Collection/People/Crew.php create mode 100644 modules/Tmdb/Model/Collection/People/PersonInterface.php create mode 100644 modules/Tmdb/Model/Collection/QueryParameter/AppendToResponse.php create mode 100644 modules/Tmdb/Model/Collection/QueryParametersCollection.php create mode 100644 modules/Tmdb/Model/Collection/ResultCollection.php create mode 100644 modules/Tmdb/Model/Common/AbstractTrailer.php create mode 100644 modules/Tmdb/Model/Common/Change.php create mode 100644 modules/Tmdb/Model/Common/Change/Item.php create mode 100644 modules/Tmdb/Model/Common/Country.php create mode 100644 modules/Tmdb/Model/Common/ExternalIds.php create mode 100644 modules/Tmdb/Model/Common/GenericCollection.php create mode 100644 modules/Tmdb/Model/Common/QueryParameter/Adult.php create mode 100644 modules/Tmdb/Model/Common/QueryParameter/AppendToResponse.php create mode 100644 modules/Tmdb/Model/Common/QueryParameter/Language.php create mode 100644 modules/Tmdb/Model/Common/QueryParameter/QueryParameterInterface.php create mode 100644 modules/Tmdb/Model/Common/QueryParameter/Type/CollectionToCommaSeperatedString.php create mode 100644 modules/Tmdb/Model/Common/SpokenLanguage.php create mode 100644 modules/Tmdb/Model/Common/Trailer/Youtube.php create mode 100644 modules/Tmdb/Model/Common/Translation.php create mode 100644 modules/Tmdb/Model/Company.php create mode 100644 modules/Tmdb/Model/Configuration.php create mode 100644 modules/Tmdb/Model/Credits.php create mode 100644 modules/Tmdb/Model/Credits/Media.php create mode 100644 modules/Tmdb/Model/Filter/AdultFilter.php create mode 100644 modules/Tmdb/Model/Filter/CountryFilter.php create mode 100644 modules/Tmdb/Model/Filter/ImageFilter.php create mode 100644 modules/Tmdb/Model/Filter/LanguageFilter.php create mode 100644 modules/Tmdb/Model/Find.php create mode 100644 modules/Tmdb/Model/Genre.php create mode 100644 modules/Tmdb/Model/Image.php create mode 100644 modules/Tmdb/Model/Image/BackdropImage.php create mode 100644 modules/Tmdb/Model/Image/LogoImage.php create mode 100644 modules/Tmdb/Model/Image/PosterImage.php create mode 100644 modules/Tmdb/Model/Image/ProfileImage.php create mode 100644 modules/Tmdb/Model/Image/StillImage.php create mode 100644 modules/Tmdb/Model/Job.php create mode 100644 modules/Tmdb/Model/Keyword.php create mode 100644 modules/Tmdb/Model/Lists.php create mode 100644 modules/Tmdb/Model/Lists/ItemStatus.php create mode 100644 modules/Tmdb/Model/Lists/ListItem.php create mode 100644 modules/Tmdb/Model/Lists/Result.php create mode 100644 modules/Tmdb/Model/Lists/ResultWithListId.php create mode 100644 modules/Tmdb/Model/Movie.php create mode 100644 modules/Tmdb/Model/Movie/AccountStates.php create mode 100644 modules/Tmdb/Model/Movie/AlternativeTitle.php create mode 100644 modules/Tmdb/Model/Movie/ListItem.php create mode 100644 modules/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php create mode 100644 modules/Tmdb/Model/Movie/Rating.php create mode 100644 modules/Tmdb/Model/Movie/Release.php create mode 100644 modules/Tmdb/Model/Network.php create mode 100644 modules/Tmdb/Model/Person.php create mode 100644 modules/Tmdb/Model/Person/AbstractMember.php create mode 100644 modules/Tmdb/Model/Person/CastMember.php create mode 100644 modules/Tmdb/Model/Person/CrewMember.php create mode 100644 modules/Tmdb/Model/Person/MovieCredit.php create mode 100644 modules/Tmdb/Model/Person/QueryParameter/AppendToResponse.php create mode 100644 modules/Tmdb/Model/Query/ChangesQuery.php create mode 100644 modules/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php create mode 100644 modules/Tmdb/Model/Query/Discover/DiscoverTvQuery.php create mode 100644 modules/Tmdb/Model/Query/FindQuery.php create mode 100644 modules/Tmdb/Model/Review.php create mode 100644 modules/Tmdb/Model/Search/SearchQuery.php create mode 100644 modules/Tmdb/Model/Search/SearchQuery/CollectionSearchQuery.php create mode 100644 modules/Tmdb/Model/Search/SearchQuery/CompanySearchQuery.php create mode 100644 modules/Tmdb/Model/Search/SearchQuery/KeywordSearchQuery.php create mode 100644 modules/Tmdb/Model/Search/SearchQuery/ListSearchQuery.php create mode 100644 modules/Tmdb/Model/Search/SearchQuery/MovieSearchQuery.php create mode 100644 modules/Tmdb/Model/Search/SearchQuery/PersonSearchQuery.php create mode 100644 modules/Tmdb/Model/Search/SearchQuery/TvSearchQuery.php create mode 100644 modules/Tmdb/Model/Tv.php create mode 100644 modules/Tmdb/Model/Tv/Episode.php create mode 100644 modules/Tmdb/Model/Tv/Episode/QueryParameter/AppendToResponse.php create mode 100644 modules/Tmdb/Model/Tv/Network.php create mode 100644 modules/Tmdb/Model/Tv/QueryParameter/AppendToResponse.php create mode 100644 modules/Tmdb/Model/Tv/Season.php create mode 100644 modules/Tmdb/Model/Tv/Season/QueryParameter/AppendToResponse.php create mode 100644 modules/Tmdb/Repository/AbstractRepository.php create mode 100644 modules/Tmdb/Repository/AccountRepository.php create mode 100644 modules/Tmdb/Repository/AuthenticationRepository.php create mode 100644 modules/Tmdb/Repository/CertificationRepository.php create mode 100644 modules/Tmdb/Repository/ChangesRepository.php create mode 100644 modules/Tmdb/Repository/CollectionRepository.php create mode 100644 modules/Tmdb/Repository/CompanyRepository.php create mode 100644 modules/Tmdb/Repository/ConfigurationRepository.php create mode 100644 modules/Tmdb/Repository/CreditsRepository.php create mode 100644 modules/Tmdb/Repository/DiscoverRepository.php create mode 100644 modules/Tmdb/Repository/FindRepository.php create mode 100644 modules/Tmdb/Repository/GenreRepository.php create mode 100644 modules/Tmdb/Repository/JobsRepository.php create mode 100644 modules/Tmdb/Repository/KeywordRepository.php create mode 100644 modules/Tmdb/Repository/ListRepository.php create mode 100644 modules/Tmdb/Repository/MovieRepository.php create mode 100644 modules/Tmdb/Repository/NetworkRepository.php create mode 100644 modules/Tmdb/Repository/PeopleRepository.php create mode 100644 modules/Tmdb/Repository/ReviewRepository.php create mode 100644 modules/Tmdb/Repository/SearchRepository.php create mode 100644 modules/Tmdb/Repository/TvEpisodeRepository.php create mode 100644 modules/Tmdb/Repository/TvRepository.php create mode 100644 modules/Tmdb/Repository/TvSeasonRepository.php create mode 100644 modules/Tmdb/RequestToken.php create mode 100644 modules/Tmdb/SessionToken.php diff --git a/README.md b/README.md index 237b5bc9..14c0bfd2 100755 --- a/README.md +++ b/README.md @@ -101,7 +101,8 @@ Ampache includes some external modules that carry their own licensing. * [Bootstrap] (http://getbootstrap.com): MIT * [jQuery Knob] (https://github.com/aterrien/jQuery-Knob): MIT * [jQuery File Upload] (https://github.com/blueimp/jQuery-File-Upload): MIT -* [jsTree] (http://www.jstree.com/): MIT +* [jsTree] (http://www.jstree.com): MIT +* [php-tmdb-api] (https://github.com/wtfzdotnet/php-tmdb-api) : MIT Translations diff --git a/modules/Tmdb/Api/AbstractApi.php b/modules/Tmdb/Api/AbstractApi.php new file mode 100644 index 00000000..3e4f2437 --- /dev/null +++ b/modules/Tmdb/Api/AbstractApi.php @@ -0,0 +1,169 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +use Guzzle\Http\Message\Response; +use Tmdb\Client; + +/** + * Class AbstractApi + * @package Tmdb\Api + */ +abstract class AbstractApi + implements ApiInterface +{ + /** + * The client + * + * @var Client + */ + protected $client; + + /** + * Constructor + * + * @param Client $client + */ + public function __construct(Client $client) + { + $this->client = $client; + } + + /** + * Send a GET request + * + * @param string $path + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function get($path, array $parameters = array(), $headers = array()) + { + /** + * @var Response $response + */ + $response = $this->client->getHttpClient()->get($path, $parameters, $headers); + return $response->json(); + } + + /** + * Send a HEAD request + * + * @param $path + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function head($path, array $parameters = array(), $headers = array()) + { + /** + * @var Response $response + */ + $response = $this->client->getHttpClient()->head($path, $parameters, $headers); + return $response->json(); + } + + /** + * Send a POST request + * + * @param $path + * @param null $postBody + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function post($path, $postBody = null, array $parameters = array(), $headers = array()) + { + /** + * @var Response $response + */ + $response = $this->client->getHttpClient()->post($path, $postBody, $parameters, $headers); + return $response->json(); + } + + /** + * Send a POST request but json_encode the post body in the request + * + * @param $path + * @param null $postBody + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function postJson($path, $postBody = null, array $parameters = array(), $headers = array()) + { + /** + * @var Response $response + */ + if (is_array($postBody)) { + $postBody = json_encode($postBody); + } + + $response = $this->client->getHttpClient()->postJson($path, $postBody, $parameters, $headers); + return $response->json(); + } + + /** + * Send a PUT request + * + * @param $path + * @param null $body + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function put($path, $body = null, array $parameters = array(), $headers = array()) + { + /** + * @var Response $response + */ + $response = $this->client->getHttpClient()->put($path, $body, $parameters, $headers); + return $response->json(); + } + + /** + * Send a DELETE request + * + * @param $path + * @param null $body + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function delete($path, $body = null, array $parameters = array(), $headers = array()) + { + /** + * @var Response $response + */ + $response = $this->client->getHttpClient()->delete($path, $body, $parameters, $headers); + return $response->json(); + } + + /** + * Send a PATCH request + * + * @param $path + * @param null $body + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function patch($path, $body = null, array $parameters = array(), $headers = array()) + { + /** + * @var Response $response + */ + $response = $this->client->getHttpClient()->patch($path, $body, $parameters, $headers); + return $response->json(); + } +} diff --git a/modules/Tmdb/Api/Account.php b/modules/Tmdb/Api/Account.php new file mode 100644 index 00000000..2bf4f5f5 --- /dev/null +++ b/modules/Tmdb/Api/Account.php @@ -0,0 +1,118 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Account + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#account + */ +class Account + extends AbstractApi +{ + /** + * Get the basic information for an account. You will need to have a valid session id. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getAccount(array $parameters = array(), array $headers = array()) + { + return $this->get('account', $parameters, $headers); + } + + /** + * Get the lists that you have created and marked as a favorite. + * + * @param integer $accountId + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getLists($accountId, array $parameters = array(), array $headers = array()) + { + return $this->get('account/' . $accountId . '/lists', $parameters, $headers); + } + + /** + * Get the list of favorite movies for an account. + * + * @param integer $accountId + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getFavoriteMovies($accountId, array $parameters = array(), array $headers = array()) + { + return $this->get('account/' . $accountId . '/favorite_movies', $parameters, $headers); + } + + /** + * Add or remove a movie to an accounts favorite list. + * + * @param integer $accountId + * @param integer $movieId + * @param boolean $isFavorite + * @return mixed + */ + public function favorite($accountId, $movieId, $isFavorite = true) + { + return $this->postJson('account/' . $accountId . '/favorite', array( + 'movie_id' => $movieId, + 'favorite' => $isFavorite + )); + } + + /** + * Get the list of rated movies (and associated rating) for an account. + * + * @param integer $accountId + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getRatedMovies($accountId, array $parameters = array(), array $headers = array()) + { + return $this->get('account/' . $accountId . '/rated_movies', $parameters, $headers); + } + + /** + * Get the list of movies on an accounts watchlist. + * + * @param integer $accountId + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getMovieWatchlist($accountId, array $parameters = array(), array $headers = array()) + { + return $this->get('account/' . $accountId . '/movie_watchlist', $parameters, $headers); + } + + /** + * Add or remove a movie to an accounts watch list. + * + * @param integer $accountId + * @param integer $movieId + * @param boolean $isOnWatchlist + * @return mixed + */ + public function watchlist($accountId, $movieId, $isOnWatchlist = true) + { + return $this->postJson('account/' . $accountId . '/movie_watchlist', array( + 'movie_id' => $movieId, + 'movie_watchlist' => $isOnWatchlist + )); + } +} diff --git a/modules/Tmdb/Api/ApiInterface.php b/modules/Tmdb/Api/ApiInterface.php new file mode 100644 index 00000000..5719777c --- /dev/null +++ b/modules/Tmdb/Api/ApiInterface.php @@ -0,0 +1,20 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Interface ApiInterface + * @package Tmdb\Api + */ +interface ApiInterface { +} diff --git a/modules/Tmdb/Api/Authentication.php b/modules/Tmdb/Api/Authentication.php new file mode 100644 index 00000000..f7c32607 --- /dev/null +++ b/modules/Tmdb/Api/Authentication.php @@ -0,0 +1,93 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +use Symfony\Component\Yaml\Exception\RuntimeException; +use Tmdb\Exception\UnauthorizedRequestTokenException; + +/** + * Class Authentication + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#authentication + */ +class Authentication + extends AbstractApi +{ + const REQUEST_TOKEN_URI = 'https://www.themoviedb.org/authenticate'; + + /** + * This method is used to generate a valid request token for user based authentication. + * A request token is required in order to request a session id. + * + * You can generate any number of request tokens but they will expire after 60 minutes. + * As soon as a valid session id has been created the token will be destroyed. + * + * @return mixed + */ + public function getNewToken() + { + return $this->get('authentication/token/new'); + } + + /** + * Redirect the user to authenticate the request token + * + * @param $token + */ + public function authenticateRequestToken($token) + { + header(sprintf( + 'Location: %s/%s', + self::REQUEST_TOKEN_URI, + $token + )); + } + + /** + * This method is used to generate a session id for user based authentication. + * A session id is required in order to use any of the write methods. + * + * @param string $requestToken + * @throws UnauthorizedRequestTokenException + * @return mixed + */ + public function getNewSession($requestToken) + { + try { + return $this->get('authentication/session/new', array('request_token' => $requestToken)); + } + catch(\Exception $e) { + if ($e->getCode() == 401) { + throw new UnauthorizedRequestTokenException("The request token has not been validated yet."); + } + } + } + + /** + * This method is used to generate a guest session id. + * + * A guest session can be used to rate movies without having a registered TMDb user account. + * You should only generate a single guest session per user (or device) + * as you will be able to attach the ratings to a TMDb user account in the future. + * + * There is also IP limits in place so you should always make sure it's the end user doing the guest session actions. + * + * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. + * + * @return mixed + */ + public function getNewGuestSession() + { + return $this->get('authentication/guest_session/new'); + } +} diff --git a/modules/Tmdb/Api/Certifications.php b/modules/Tmdb/Api/Certifications.php new file mode 100644 index 00000000..30bff9be --- /dev/null +++ b/modules/Tmdb/Api/Certifications.php @@ -0,0 +1,36 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Certifications + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#certifications + */ +class Certifications + extends AbstractApi +{ + /** + * 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 array $parameters + * @param array $headers + * @return mixed + */ + public function getMovieList(array $parameters = array(), array $headers = array()) + { + return $this->get('certification/movie/list', $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Changes.php b/modules/Tmdb/Api/Changes.php new file mode 100644 index 00000000..0ae9093a --- /dev/null +++ b/modules/Tmdb/Api/Changes.php @@ -0,0 +1,62 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Changes + * @package Tmdb\Api + * http://docs.themoviedb.apiary.io/#changes + */ +class Changes + extends AbstractApi +{ + /** + * 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 array $parameters + * @param array $headers + * @return mixed + */ + public function getMovieChanges(array $parameters = array(), array $headers = array()) + { + return $this->get('movie/changes', $parameters, $headers); + } + + /** + * 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 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 array $parameters + * @param array $headers + * @return mixed + */ + public function getPersonChanges(array $parameters = array(), array $headers = array()) + { + return $this->get('person/changes', $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Collections.php b/modules/Tmdb/Api/Collections.php new file mode 100644 index 00000000..e297484d --- /dev/null +++ b/modules/Tmdb/Api/Collections.php @@ -0,0 +1,54 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Collections + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#collections + */ +class Collections + extends AbstractApi +{ + /** + * Get the basic collection information for a specific collection id. + * + * You can get the ID needed for this method by making a /movie/{id} request + * and paying attention to the belongs_to_collection hash. + * + * Movie parts are not sorted in any particular order. + * If you would like to sort them yourself you can use the provided release_date. + * + * @param $collection_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCollection($collection_id, array $parameters = array(), array $headers = array()) + { + return $this->get('collection/' . $collection_id, $parameters, $headers); + } + + /** + * Get all of the images for a particular collection by collection id. + * + * @param $collection_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getImages($collection_id, array $parameters = array(), array $headers = array()) + { + return $this->get('collection/' . $collection_id . '/images', $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Companies.php b/modules/Tmdb/Api/Companies.php new file mode 100644 index 00000000..2f8d1696 --- /dev/null +++ b/modules/Tmdb/Api/Companies.php @@ -0,0 +1,48 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Companies + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#companies + */ +class Companies + extends AbstractApi +{ + /** + * This method is used to retrieve all of the basic information about a company. + * + * @param $company_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCompany($company_id, array $parameters = array(), array $headers = array()) + { + return $this->get('company/' . $company_id, $parameters, $headers); + } + + /** + * Get the list of movies associated with a particular company. + * + * @param integer $company_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getMovies($company_id, array $parameters = array(), array $headers = array()) + { + return $this->get('company/' . $company_id . '/movies', $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Configuration.php b/modules/Tmdb/Api/Configuration.php new file mode 100644 index 00000000..f73986c0 --- /dev/null +++ b/modules/Tmdb/Api/Configuration.php @@ -0,0 +1,48 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Configuration + * @package Tmdb\Api + * + * @see http://docs.themoviedb.apiary.io/#configuration + */ +class Configuration + extends AbstractApi +{ + /** + * Get the system wide configuration information. + * + * Some elements of the API require some knowledge of this configuration data. + * + * The purpose of this is to try and keep the actual API responses as light as possible. + * It is recommended you store this data within your application and check for updates every so often. + * + * This method currently holds the data relevant to building image URLs as well as the change key map. + * + * To build an image URL, you will need 3 pieces of data. + * The base_url, size and file_path. + * + * Simply combine them all and you will have a fully qualified URL. Here’s an example URL: + * + * http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg + * + * @param array $headers + * @return mixed + */ + public function getConfiguration(array $headers = array()) + { + return $this->get('configuration', array(), $headers); + } +} diff --git a/modules/Tmdb/Api/Credits.php b/modules/Tmdb/Api/Credits.php new file mode 100644 index 00000000..d82372a1 --- /dev/null +++ b/modules/Tmdb/Api/Credits.php @@ -0,0 +1,42 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Credits + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#credits + */ +class Credits + extends AbstractApi +{ + /** + * Get the detailed information about a particular credit record. This is currently only supported with the new credit model found in TV. + * These ids can be found from any TV credit response as well as the tv_credits and combined_credits methods for people. + * + * The episodes object returns a list of episodes and are generally going to be guest stars. + * The season array will return a list of season numbers. + * + * Season credits are credits that were marked with the "add to every season" option in the editing interface + * and are assumed to be "season regulars". + * + * @param $credit_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCredit($credit_id, array $parameters = array(), array $headers = array()) + { + return $this->get('credit/' . $credit_id, $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Discover.php b/modules/Tmdb/Api/Discover.php new file mode 100644 index 00000000..69d236cc --- /dev/null +++ b/modules/Tmdb/Api/Discover.php @@ -0,0 +1,46 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Discover + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#discover + */ +class Discover + extends AbstractApi +{ + /** + * Discover movies by different types of data like average rating, number of votes, genres and certifications. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function discoverMovies(array $parameters = array(), array $headers = array()) + { + return $this->get('discover/movie', $parameters, $headers); + } + + /** + * Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function discoverTv(array $parameters = array(), array $headers = array()) + { + return $this->get('discover/tv', $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Find.php b/modules/Tmdb/Api/Find.php new file mode 100644 index 00000000..8f783fa1 --- /dev/null +++ b/modules/Tmdb/Api/Find.php @@ -0,0 +1,45 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Find + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#find + */ +class Find + extends AbstractApi +{ + /** + * The find method makes it easy to search for objects in our database by an external id. For instance, an IMDB ID. This will search all objects (movies, TV shows and people) and return the results in a single response. TV season and TV episode searches will be supported shortly. + * + * The supported external sources for each object are as follows: + * + * Movies: imdb_id + * People: imdb_id, freebase_mid, freebase_id, tvrage_id + * TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_id + * + * @param string $id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function find($id, array $parameters = array(), array $headers = array()) + { + return $this->get( + sprintf('find/%s', $id), + $parameters, + $headers + ); + } +} diff --git a/modules/Tmdb/Api/Genres.php b/modules/Tmdb/Api/Genres.php new file mode 100644 index 00000000..789c96e6 --- /dev/null +++ b/modules/Tmdb/Api/Genres.php @@ -0,0 +1,81 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Genres + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#genres + */ +class Genres + extends AbstractApi +{ + /** + * Get the list of genres, and return one by id + * + * @param integer $id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getGenre($id, array $parameters = array(), array $headers = array()) + { + $response = $this->getGenres($parameters, $headers); + + if (array_key_exists('genres', $response)) { + return $this->extractGenreByIdFromResponse($id, $response['genres']); + } + + return null; + } + + /** + * Get the list of genres. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getGenres(array $parameters = array(), array $headers = array()) + { + return $this->get('genre/list', $parameters, $headers); + } + + /** + * Get the list of movies for a particular genre by id. By default, only movies with 10 or more votes are included. + * + * @param $genre_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getMovies($genre_id, array $parameters = array(), array $headers = array()) + { + return $this->get('genre/' . $genre_id . '/movies', $parameters, $headers); + } + + /** + * @param integer $id + * @param array $data + * @return mixed + */ + private function extractGenreByIdFromResponse($id, array $data = array()) + { + foreach($data as $genre) { + if ($id == $genre['id']) + return $genre; + } + + return null; + } +} diff --git a/modules/Tmdb/Api/Jobs.php b/modules/Tmdb/Api/Jobs.php new file mode 100644 index 00000000..5afed498 --- /dev/null +++ b/modules/Tmdb/Api/Jobs.php @@ -0,0 +1,34 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Jobs + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#jobs + */ +class Jobs + extends AbstractApi +{ + /** + * Get a list of valid jobs. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getJobs(array $parameters = array(), array $headers = array()) + { + return $this->get('job/list', $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Keywords.php b/modules/Tmdb/Api/Keywords.php new file mode 100644 index 00000000..80ed4f80 --- /dev/null +++ b/modules/Tmdb/Api/Keywords.php @@ -0,0 +1,48 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Keywords + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#keywords + */ +class Keywords + extends AbstractApi +{ + /** + * Get the basic information for a specific keyword id. + * + * @param int $keyword_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getKeyword($keyword_id, array $parameters = array(), array $headers = array()) + { + return $this->get('keyword/' . $keyword_id, $parameters, $headers); + } + + /** + * Get the list of movies for a particular keyword by id. + * + * @param int $keyword_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getMovies($keyword_id, array $parameters = array(), array $headers = array()) + { + return $this->get('keyword/' . $keyword_id . '/movies', $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Lists.php b/modules/Tmdb/Api/Lists.php new file mode 100644 index 00000000..1aa3b3f5 --- /dev/null +++ b/modules/Tmdb/Api/Lists.php @@ -0,0 +1,102 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Lists + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#lists + */ +class Lists + extends AbstractApi +{ + /** + * Get a list by id. + * + * @param $list_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getList($list_id, array $parameters = array(), array $headers = array()) + { + return $this->get('list/' . $list_id, $parameters, $headers); + } + + /** + * This method lets users create a new list. A valid session id is required. + * + * @param string $name + * @param string $description + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function createList($name, $description, array $parameters = array(), array $headers = array()) + { + return $this->postJson('list', array('name' => $name, 'description' => $description), $parameters, $headers); + } + + /** + * Check to see if a movie ID is already added to a list. + * + * @param string $id + * @param int $movieId + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getItemStatus($id, $movieId, array $parameters = array(), array $headers = array()) + { + return $this->get( + 'list/' . $id . '/item_status', + array_merge($parameters, array('movie_id' => $movieId)), + $headers + ); + } + + /** + * This method lets users add new movies to a list that they created. A valid session id is required. + * + * @param string $id + * @param string $mediaId + * @return mixed + */ + public function addMediaToList($id, $mediaId) + { + return $this->postJson('list/' . $id . '/add_item', array('media_id' => $mediaId)); + } + + /** + * This method lets users delete movies from a list that they created. A valid session id is required. + * + * @param string $id + * @param string $mediaId + * @return mixed + */ + public function removeMediaFromList($id, $mediaId) + { + return $this->postJson('list/' . $id . '/remove_item', array('media_id' => $mediaId)); + } + + /** + * This method lets users delete a list that they created. A valid session id is required. + * + * @param string $id + * @return mixed + */ + public function deleteList($id) + { + return $this->delete('list/' . $id); + } +} diff --git a/modules/Tmdb/Api/Movies.php b/modules/Tmdb/Api/Movies.php new file mode 100644 index 00000000..960da006 --- /dev/null +++ b/modules/Tmdb/Api/Movies.php @@ -0,0 +1,262 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Movies + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#movies + */ +class Movies + extends AbstractApi +{ + /** + * Get the basic movie information for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getMovie($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id, $parameters, $headers); + } + + /** + * Get the alternative titles for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getAlternativeTitles($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/alternative_titles', $parameters, $headers); + } + + /** + * Get the cast and crew information for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCredits($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/credits', $parameters, $headers); + } + + /** + * Get the images (posters and backdrops) for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getImages($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/images', $parameters, $headers); + } + + /** + * Get the plot keywords for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getKeywords($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/keywords', $parameters, $headers); + } + + /** + * Get the release date by country for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getReleases($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/releases', $parameters, $headers); + } + + /** + * Get the trailers for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getTrailers($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/trailers', $parameters, $headers); + } + + /** + * Get the translations for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getTranslations($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/translations', $parameters, $headers); + } + + /** + * Get the similar movies for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getSimilarMovies($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/similar_movies', $parameters, $headers); + } + + /** + * Get the reviews for a particular movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getReviews($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/reviews', $parameters, $headers); + } + + /** + * Get the lists that the movie belongs to. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getLists($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/lists', $parameters, $headers); + } + + /** + * Get the changes for a specific movie id. + * + * @param $movie_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getChanges($movie_id, array $parameters = array(), array $headers = array()) + { + return $this->get('movie/' . $movie_id . '/changes', $parameters, $headers); + } + + /** + * Get the latest movie id. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getLatest(array $parameters = array(), array $headers = array()) + { + return $this->get('movie/latest', $parameters, $headers); + } + + /** + * Get the list of upcoming movies. This list refreshes every day. The maximum number of items this list will include is 100. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getUpcoming(array $parameters = array(), array $headers = array()) + { + return $this->get('movie/upcoming', $parameters, $headers); + } + + /** + * 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 $parameters + * @param array $headers + * @return mixed + */ + public function getNowPlaying(array $parameters = array(), array $headers = array()) + { + return $this->get('movie/now_playing', $parameters, $headers); + } + + /** + * Get the list of popular movies on The Movie Database. This list refreshes every day. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getPopular(array $parameters = array(), array $headers = array()) + { + return $this->get('movie/popular', $parameters, $headers); + } + + /** + * 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 $parameters + * @param array $headers + * @return mixed + */ + public function getTopRated(array $parameters = array(), array $headers = array()) + { + return $this->get('movie/top_rated', $parameters, $headers); + } + + /** + * This method lets users get the status of whether or not the movie has been rated or added to their favourite or watch lists. + * + * A valid session id is required. + * + * @throws \Tmdb\Exception\NotImplementedException + */ + public function getAccountStates($id) + { + return $this->get('movie/' . $id . '/account_states'); + } + + /** + * TThis method lets users rate a movie. + * + * A valid session id or guest session id is required. + * + * @throws \Tmdb\Exception\NotImplementedException + */ + public function rateMovie($id, $rating) + { + return $this->postJson('movie/' . $id . '/rating', array('value' => (float) $rating)); + } +} diff --git a/modules/Tmdb/Api/Networks.php b/modules/Tmdb/Api/Networks.php new file mode 100644 index 00000000..347aade3 --- /dev/null +++ b/modules/Tmdb/Api/Networks.php @@ -0,0 +1,38 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Networks + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#networks + */ +class Networks + extends AbstractApi +{ + /** + * This method is used to retrieve the basic information about a TV network. + * + * You can use this ID to search for TV shows with the discover. + * At this time we don't have much but this will be fleshed out over time. + * + * @param int $network_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getNetwork($network_id, array $parameters = array(), array $headers = array()) + { + return $this->get('network/' . $network_id, $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/People.php b/modules/Tmdb/Api/People.php new file mode 100644 index 00000000..466e2220 --- /dev/null +++ b/modules/Tmdb/Api/People.php @@ -0,0 +1,160 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class People + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#people + */ +class People + extends AbstractApi +{ + /** + * Get the general person information for a specific id. + * + * @param $person_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getPerson($person_id, array $parameters = array(), array $headers = array()) + { + return $this->get('person/' . $person_id, $parameters, $headers); + } + + /** + * Get the credits for a specific person id. + * + * @param $person_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCredits($person_id, array $parameters = array(), array $headers = array()) + { + 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); + } + + /** + * Get the images for a specific person id. + * + * @param $person_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getImages($person_id, array $parameters = array(), array $headers = array()) + { + return $this->get('person/' . $person_id . '/images', $parameters, $headers); + } + + /** + * Get the changes for a specific person id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * By default, only the last 24 hours of changes are returned. + * The maximum number of days that can be returned in a single request is 14. + * The language is present on fields that are translatable. + * + * @param $person_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getChanges($person_id, array $parameters = array(), array $headers = array()) + { + return $this->get('person/' . $person_id . '/changes', $parameters, $headers); + } + + /** + * Get the external ids for a specific person id. + * + * @param $person_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getExternalIds($person_id, array $parameters = array(), array $headers = array()) + { + return $this->get('person/' . $person_id . '/external_ids', $parameters, $headers); + } + + /** + * Get the list of popular people on The Movie Database. This list refreshes every day. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getPopular(array $parameters = array(), array $headers = array()) + { + return $this->get('person/popular', $parameters, $headers); + } + + /** + * Get the latest person id. + * + * @return mixed + */ + public function getLatest() + { + return $this->get('person/latest'); + } +} diff --git a/modules/Tmdb/Api/Reviews.php b/modules/Tmdb/Api/Reviews.php new file mode 100644 index 00000000..11b0f1d6 --- /dev/null +++ b/modules/Tmdb/Api/Reviews.php @@ -0,0 +1,35 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Reviews + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#reviews + */ +class Reviews + extends AbstractApi +{ + /** + * Get the full details of a review by ID. + * + * @param $review_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getReview($review_id, array $parameters = array(), array $headers = array()) + { + return $this->get('review/' . $review_id, $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/Search.php b/modules/Tmdb/Api/Search.php new file mode 100644 index 00000000..539f3f1b --- /dev/null +++ b/modules/Tmdb/Api/Search.php @@ -0,0 +1,127 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Search + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#search + */ +class Search + extends AbstractApi +{ + /** + * Search for movies by title. + * + * @param $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchMovies($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/movie', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } + + /** + * Search for collections by name. + * + * @param $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchCollection($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/collection', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } + + /** + * Search for TV shows by title. + * + * @param $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchTv($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/tv', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } + + /** + * Search for people by name. + * + * @param $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchPersons($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/person', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } + + /** + * Search for lists by name and description. + * + * @param $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchList($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/list', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } + + /** + * Search for companies by name. + * + * @param $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchCompany($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/company', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } + + /** + * Search for companies by name. + * + * @param $query + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function searchKeyword($query, array $parameters = array(), array $headers = array()) + { + return $this->get('search/keyword', array_merge($parameters, array( + 'query' => urlencode($query) + ), $headers)); + } +} diff --git a/modules/Tmdb/Api/Tv.php b/modules/Tmdb/Api/Tv.php new file mode 100644 index 00000000..40a4e27c --- /dev/null +++ b/modules/Tmdb/Api/Tv.php @@ -0,0 +1,118 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class Tv + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#tv + */ +class Tv + extends AbstractApi +{ + /** + * Get the primary information about a TV series by id. + * + * @param integer $tvshow_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getTvshow($tvshow_id, array $parameters = array(), array $headers = array()) + { + return $this->get('tv/' . $tvshow_id, $parameters, $headers); + } + + /** + * 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 $tvshow_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCredits($tvshow_id, array $parameters = array(), array $headers = array()) + { + return $this->get('tv/' . $tvshow_id . '/credits', $parameters, $headers); + } + + /** + * Get the external ids that we have stored for a TV series. + * + * @param $tvshow_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getExternalIds($tvshow_id, array $parameters = array(), array $headers = array()) + { + return $this->get('tv/' . $tvshow_id . '/external_ids', $parameters, $headers); + } + + /** + * Get the images (posters and backdrops) for a TV series. + * + * @param $tvshow_id + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getImages($tvshow_id, array $parameters = array(), array $headers = array()) + { + return $this->get('tv/' . $tvshow_id . '/images', $parameters, $headers); + } + + /** + * Get the list of popular TV shows. This list refreshes every day. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getPopular(array $parameters = array(), array $headers = array()) + { + return $this->get('tv/popular', $parameters, $headers); + } + + /** + * Get the list of top rated TV shows. + * + * By default, this list will only include TV shows that have 2 or more votes. + * This list refreshes every day. + * + * @param array $parameters + * @param array $headers + * @return mixed + */ + 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/modules/Tmdb/Api/TvEpisode.php b/modules/Tmdb/Api/TvEpisode.php new file mode 100644 index 00000000..3c09594d --- /dev/null +++ b/modules/Tmdb/Api/TvEpisode.php @@ -0,0 +1,82 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class TvEpisode + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#tvepisodes + */ +class TvEpisode + extends AbstractApi +{ + /** + * Get the primary information about a TV episode by combination of a season and episode number. + * + * @param $tvshow_id + * @param $season_number + * @param $episode_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getEpisode($tvshow_id, $season_number, $episode_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s/episode/%s', $tvshow_id, $season_number,$episode_number), $parameters, $headers); + } + + /** + * Get the TV episode credits by combination of season and episode number. + * + * @param $tvshow_id + * @param $season_number + * @param $episode_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCredits($tvshow_id, $season_number, $episode_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s/episode/%s/credits', $tvshow_id, $season_number,$episode_number), $parameters, $headers); + } + + /** + * Get the external ids for a TV episode by comabination of a season and episode number. + * + * @param $tvshow_id + * @param $season_number + * @param $episode_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getExternalIds($tvshow_id, $season_number, $episode_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s/episode/%s/external_ids', $tvshow_id, $season_number,$episode_number), $parameters, $headers); + } + + /** + * Get the images (episode stills) for a TV episode by combination of a season and episode number. + * + * @param $tvshow_id + * @param $season_number + * @param $episode_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getImages($tvshow_id, $season_number, $episode_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s/episode/%s/images', $tvshow_id, $season_number,$episode_number), $parameters, $headers); + } +} diff --git a/modules/Tmdb/Api/TvSeason.php b/modules/Tmdb/Api/TvSeason.php new file mode 100644 index 00000000..cc0e8544 --- /dev/null +++ b/modules/Tmdb/Api/TvSeason.php @@ -0,0 +1,78 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Api; + +/** + * Class TvSeason + * @package Tmdb\Api + * @see http://docs.themoviedb.apiary.io/#tvseasons + */ +class TvSeason + extends AbstractApi +{ + /** + * Get the primary information about a TV season by its season number. + * + * @param $tvshow_id + * @param $season_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getSeason($tvshow_id, $season_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s', $tvshow_id, $season_number), $parameters, $headers); + } + + /** + * Get the cast & crew credits for a TV season by season number. + * + * @param $tvshow_id + * @param $season_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getCredits($tvshow_id, $season_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s/credits', $tvshow_id, $season_number), $parameters, $headers); + } + + /** + * Get the external ids that we have stored for a TV season by season number. + * + * @param $tvshow_id + * @param $season_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getExternalIds($tvshow_id, $season_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s/external_ids', $tvshow_id, $season_number), $parameters, $headers); + } + + /** + * Get the images (posters) that we have stored for a TV season by season number. + * + * @param $tvshow_id + * @param $season_number + * @param array $parameters + * @param array $headers + * @return mixed + */ + public function getImages($tvshow_id, $season_number, array $parameters = array(), array $headers = array()) + { + return $this->get(sprintf('tv/%s/season/%s/images', $tvshow_id, $season_number), $parameters, $headers); + } +} diff --git a/modules/Tmdb/ApiToken.php b/modules/Tmdb/ApiToken.php new file mode 100644 index 00000000..0f6bffa3 --- /dev/null +++ b/modules/Tmdb/ApiToken.php @@ -0,0 +1,49 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb; + +/** + * Class ApiToken + * @package Tmdb + */ +class ApiToken { + private $apiToken = null; + + /** + * Token bag + * + * @param $api_token + */ + public function __construct($api_token = null) + { + $this->apiToken = $api_token; + } + + /** + * @param null $apiToken + * @return $this + */ + public function setToken($apiToken) + { + $this->apiToken = $apiToken; + return $this; + } + + /** + * @return null + */ + public function getToken() + { + return $this->apiToken; + } +} diff --git a/modules/Tmdb/Client.php b/modules/Tmdb/Client.php new file mode 100644 index 00000000..743ad5e6 --- /dev/null +++ b/modules/Tmdb/Client.php @@ -0,0 +1,355 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb; + +use Guzzle\Http\Client as GuzzleClient; +use Guzzle\Http\ClientInterface; +use Tmdb\HttpClient\HttpClient; +use Tmdb\HttpClient\HttpClientInterface; +use Tmdb\ApiToken as Token; +use Tmdb\HttpClient\Plugin\AcceptJsonHeaderPlugin; +use Tmdb\HttpClient\Plugin\ApiTokenPlugin; +use Tmdb\HttpClient\Plugin\SessionTokenPlugin; + +/** + * Client wrapper for TMDB + * @package Tmdb + */ +class Client { + /** + * Base API URI + */ + const TMDB_URI = '//api.themoviedb.org/3/'; + + /** + * Insecure schema + */ + const SCHEME_INSECURE = 'http'; + + /** + * Secure schema + */ + const SCHEME_SECURE = 'https'; + + /** + * Stores API authentication token + * + * @var Token + */ + private $token; + + /** + * Stores API user session token + * + * @var SessionToken + */ + private $sessionToken; + + /** + * Whether the request is supposed to use a secure schema + * + * @var bool + */ + private $secure = false; + + /** + * Stores the HTTP Client + * + * @var HttpClientInterface + */ + private $httpClient; + + /** + * Construct our client + * + * @param ClientInterface|null $httpClient + * @param ApiToken $token + * @param boolean $secure + */ + public function __construct(Token $token, ClientInterface $httpClient = null, $secure = false) + { + $this->setToken($token); + $this->setSecure($secure); + + $httpClient = $httpClient ?: new GuzzleClient($this->getBaseUrl()); + + if ($httpClient instanceof \Guzzle\Common\HasDispatcherInterface) { + $apiTokenPlugin = new ApiTokenPlugin($token); + $httpClient->addSubscriber($apiTokenPlugin); + + $acceptJsonHeaderPlugin = new AcceptJsonHeaderPlugin(); + $httpClient->addSubscriber($acceptJsonHeaderPlugin); + } + + $this->httpClient = new HttpClient($this->getBaseUrl(), array(), $httpClient); + } + + /** + * Add the token subscriber + * + * @param Token $token + * @return $this + */ + public function setToken(Token $token) + { + $this->token = $token; + return $this; + } + + /** + * @return Api\Configuration + */ + public function getConfigurationApi() + { + return new Api\Configuration($this); + } + + /** + * @return Api\Authentication + */ + public function getAuthenticationApi() + { + return new Api\Authentication($this); + } + + /** + * @return Api\Account + */ + public function getAccountApi() + { + return new Api\Account($this); + } + + /** + * @return Api\Collections + */ + public function getCollectionsApi() + { + return new Api\Collections($this); + } + + /** + * @return Api\Find + */ + public function getFindApi() + { + return new Api\Find($this); + } + + /** + * @return Api\Movies + */ + public function getMoviesApi() + { + return new Api\Movies($this); + } + + /** + * @return Api\Tv + */ + public function getTvApi() + { + return new Api\Tv($this); + } + + /** + * @return Api\TvSeason + */ + public function getTvSeasonApi() + { + return new Api\TvSeason($this); + } + + /** + * @return Api\TvEpisode + */ + public function getTvEpisodeApi() + { + return new Api\TvEpisode($this); + } + + /** + * @return Api\People + */ + public function getPeopleApi() + { + return new Api\People($this); + } + + /** + * @return Api\Lists + */ + public function getListsApi() + { + return new Api\Lists($this); + } + + /** + * @return Api\Companies + */ + public function getCompaniesApi() + { + return new Api\Companies($this); + } + + /** + * @return Api\Genres + */ + public function getGenresApi() + { + return new Api\Genres($this); + } + + /** + * @return Api\Keywords + */ + public function getKeywordsApi() + { + return new Api\Keywords($this); + } + + /** + * @return Api\Discover + */ + public function getDiscoverApi() + { + return new Api\Discover($this); + } + + /** + * @return Api\Search + */ + public function getSearchApi() + { + return new Api\Search($this); + } + + /** + * @return Api\Reviews + */ + public function getReviewsApi() + { + return new Api\Reviews($this); + } + + /** + * @return Api\Changes + */ + public function getChangesApi() + { + return new Api\Changes($this); + } + + /** + * @return Api\Jobs + */ + public function getJobsApi() + { + return new Api\Jobs($this); + } + + /** + * @return Api\Networks + */ + public function getNetworksApi() + { + return new Api\Networks($this); + } + + /** + * @return Api\Credits + */ + public function getCreditsApi() + { + return new Api\Credits($this); + } + + /** + * @return Api\Certifications + */ + public function getCertificationsApi() + { + return new Api\Certifications($this); + } + + /** + * @return HttpClientInterface + */ + public function getHttpClient() + { + return $this->httpClient; + } + + /** + * @param HttpClientInterface $httpClient + */ + public function setHttpClient(HttpClientInterface $httpClient) + { + $this->httpClient = $httpClient; + } + + /** + * Return the base url with preferred schema + * + * @return string + */ + public function getBaseUrl() + { + return sprintf( + '%s:%s', + $this->getSecure() ? self::SCHEME_SECURE : self::SCHEME_INSECURE, + self::TMDB_URI + ); + } + + /** + * @param boolean $secure + * @return $this + */ + public function setSecure($secure) + { + $this->secure = $secure; + return $this; + } + + /** + * @return boolean + */ + public function getSecure() + { + return $this->secure; + } + + /** + * @param SessionToken $sessionToken + * @return $this + */ + public function setSessionToken($sessionToken) + { + if ($this->httpClient->getClient() instanceof \Guzzle\Common\HasDispatcherInterface) { + $sessionTokenPlugin = new SessionTokenPlugin($sessionToken); + $this->httpClient->getClient()->addSubscriber($sessionTokenPlugin); + } + + $this->sessionToken = $sessionToken; + return $this; + } + + /** + * @return SessionToken + */ + public function getSessionToken() + { + return $this->sessionToken; + } +} diff --git a/modules/Tmdb/Common/ObjectHydrator.php b/modules/Tmdb/Common/ObjectHydrator.php new file mode 100644 index 00000000..be4c66c6 --- /dev/null +++ b/modules/Tmdb/Common/ObjectHydrator.php @@ -0,0 +1,81 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Common; + +use Tmdb\Exception\RuntimeException; +use Tmdb\Model\AbstractModel; + +/** + * Utilisation class to hydrate objects. + * + * Class ObjectHydrator + * @package Tmdb\Common + */ +class ObjectHydrator { + /** + * Hydrate the object with data + * + * @param AbstractModel $object + * @param array $data + * @return AbstractModel + * @throws RuntimeException + */ + public function hydrate(AbstractModel $object, $data = array()) + { + if (!empty($data)) { + foreach ($data as $k => $v) { + + if (in_array($k, $object::$_properties)) { + + $method = $this->camelize( + sprintf('set_%s', $k) + ); + + if (!is_callable(array($object, $method))) { + throw new RuntimeException(sprintf( + 'Trying to call method "%s" on "%s" but it does not exist or is private.', + $method, + get_class($object) + )); + }else{ + $object->$method($v); + } + } + } + } + + return $object; + } + + /** + * Transforms an under_scored_string to a camelCasedOne + * + * @see https://gist.github.com/troelskn/751517 + * + * @param string $candidate + * @return string + */ + public function camelize($candidate) + { + return lcfirst( + implode('', + array_map('ucfirst', + array_map('strtolower', + explode('_', $candidate + ) + ) + ) + ) + ); + } +} \ No newline at end of file diff --git a/modules/Tmdb/Exception/InvalidArgumentException.php b/modules/Tmdb/Exception/InvalidArgumentException.php new file mode 100644 index 00000000..023ce8b7 --- /dev/null +++ b/modules/Tmdb/Exception/InvalidArgumentException.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Exception; + +/** + * Class InvalidArgumentException + * @package Tmdb\Exception + */ +class InvalidArgumentException extends \InvalidArgumentException { + +} diff --git a/modules/Tmdb/Exception/MissingArgumentException.php b/modules/Tmdb/Exception/MissingArgumentException.php new file mode 100644 index 00000000..edbedd87 --- /dev/null +++ b/modules/Tmdb/Exception/MissingArgumentException.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Exception; + +/** + * Class MissingArgumentException + * @package Tmdb\Exception + */ +class MissingArgumentException extends \InvalidArgumentException { + +} diff --git a/modules/Tmdb/Exception/NotImplementedException.php b/modules/Tmdb/Exception/NotImplementedException.php new file mode 100644 index 00000000..65659f48 --- /dev/null +++ b/modules/Tmdb/Exception/NotImplementedException.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Exception; + +/** + * Class NotImplementedException + * @package Tmdb\Exception + */ +class NotImplementedException extends \Exception { + +} diff --git a/modules/Tmdb/Exception/RuntimeException.php b/modules/Tmdb/Exception/RuntimeException.php new file mode 100644 index 00000000..a3f6c3e6 --- /dev/null +++ b/modules/Tmdb/Exception/RuntimeException.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Exception; + +/** + * Class RuntimeException + * @package Tmdb\Exception + */ +class RuntimeException extends \RuntimeException { + +} diff --git a/modules/Tmdb/Exception/UnauthorizedRequestTokenException.php b/modules/Tmdb/Exception/UnauthorizedRequestTokenException.php new file mode 100644 index 00000000..d96a8b58 --- /dev/null +++ b/modules/Tmdb/Exception/UnauthorizedRequestTokenException.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Exception; + +/** + * Class UnauthorizedRequestTokenException + * @package Tmdb\Exception + */ +class UnauthorizedRequestTokenException extends \RuntimeException { + +} diff --git a/modules/Tmdb/Factory/AbstractFactory.php b/modules/Tmdb/Factory/AbstractFactory.php new file mode 100644 index 00000000..f11e9902 --- /dev/null +++ b/modules/Tmdb/Factory/AbstractFactory.php @@ -0,0 +1,110 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Common\ObjectHydrator; +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Common\GenericCollection; + +/** + * Class AbstractFactory + * @package Tmdb\Factory + */ +abstract class AbstractFactory { + /** + * Convert an array to an hydrated object + * + * @param array $data + * @return AbstractModel + */ + abstract public function create(array $data = array()); + + /** + * Convert an array with an collection of items to an hydrated object collection + * + * @param array $data + * @return GenericCollection + */ + abstract public function createCollection(array $data = array()); + + /** + * Create a generic collection of data and map it on the class by it's static parameter $_properties + * + * @param array $data + * @param $class + * @return GenericCollection + */ + protected function createGenericCollection(array $data = array(), $class) + { + if (is_object($class)) { + $class = get_class($class); + } + + $collection = new GenericCollection(); + + foreach($data as $item) { + $collection->add(null, $this->hydrate(new $class(), $item)); + } + + return $collection; + } + + /** + * Create a result collection + * + * @param array $data + * @param string $method + * @return ResultCollection + */ + public function createResultCollection(array $data = array(), $method = 'create') + { + $collection = new ResultCollection(); + + if (array_key_exists('page', $data)) { + $collection->setPage($data['page']); + } + + if (array_key_exists('total_pages', $data)) { + $collection->setTotalPages($data['total_pages']); + } + + if (array_key_exists('total_results', $data)) { + $collection->setTotalResults($data['total_results']); + } + + if (array_key_exists('results', $data)) { + $data = $data['results']; + } + + foreach($data as $item) { + $collection->add(null, $this->$method($item)); + } + + return $collection; + } + + /** + * Hydrate the object with data + * + * @param AbstractModel $object + * @param array $data + * @return AbstractModel + */ + protected function hydrate(AbstractModel $object, $data = array()) + { + $objectHydrator = new ObjectHydrator(); + + return $objectHydrator->hydrate($object, $data); + } +} diff --git a/modules/Tmdb/Factory/AccountFactory.php b/modules/Tmdb/Factory/AccountFactory.php new file mode 100644 index 00000000..85c066ca --- /dev/null +++ b/modules/Tmdb/Factory/AccountFactory.php @@ -0,0 +1,131 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Exception\NotImplementedException; +use Tmdb\Model\Account; +use Tmdb\Model\Lists\Result; + +/** + * Class AccountFactory + * @package Tmdb\Factory + */ +class AccountFactory extends AbstractFactory +{ + /** + * @var MovieFactory + */ + private $movieFactory; + + /** + * @var ImageFactory + */ + private $imageFactory; + + public function __construct() + { + $this->movieFactory = new MovieFactory(); + $this->imageFactory = new ImageFactory(); + } + + /** + * @param array $data + * + * @return Account + */ + public function create(array $data = array()) + { + return $this->hydrate(new Account(), $data); + } + + /** + * @param array $data + * + * @return Result + */ + public function createStatusResult(array $data = array()) + { + return $this->hydrate(new Result(), $data); + } + + /** + * Create movie + * + * @param array $data + * @return \Tmdb\Model\Movie + */ + public function createMovie(array $data = array()) { + return $this->getMovieFactory()->create($data); + } + + /** + * Create list item + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createListItem(array $data = array()) + { + $listItem = new Account\ListItem(); + + if (array_key_exists('poster_path', $data)) { + $listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + return $this->hydrate($listItem, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + throw new NotImplementedException('Not implemented'); + } + + /** + * @param \Tmdb\Factory\MovieFactory $movieFactory + * @return $this + */ + public function setMovieFactory($movieFactory) + { + $this->movieFactory = $movieFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\MovieFactory + */ + public function getMovieFactory() + { + return $this->movieFactory; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } +} diff --git a/modules/Tmdb/Factory/AuthenticationFactory.php b/modules/Tmdb/Factory/AuthenticationFactory.php new file mode 100644 index 00000000..38b61d9e --- /dev/null +++ b/modules/Tmdb/Factory/AuthenticationFactory.php @@ -0,0 +1,117 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Exception\NotImplementedException; +use Tmdb\RequestToken; +use Tmdb\SessionToken; + +/** + * Class AuthenticationFactory + * @package Tmdb\Factory + */ +class AuthenticationFactory extends AbstractFactory +{ + /** + * @param array $data + * + * @throws NotImplementedException + * @return void + */ + public function create(array $data = array()) + { + throw new NotImplementedException(); + } + + /** + * @param array $data + * + * @throws NotImplementedException + * @return void + */ + public function createCollection(array $data = array()) + { + throw new NotImplementedException(); + } + + /** + * Create request token + * + * @param array $data + * @return RequestToken + */ + public function createRequestToken(array $data = array()) + { + $token = new RequestToken(); + + if (array_key_exists('expires_at', $data)) { + $token->setExpiresAt(new \DateTime($data['expires_at'])); + } + + if (array_key_exists('request_token', $data)) { + $token->setToken($data['request_token']); + } + + if (array_key_exists('success', $data)) { + $token->setSuccess($data['success']); + } + + return $token; + } + + /** + * Create session token for user + * + * @param array $data + * @return SessionToken + */ + public function createSessionToken(array $data = array()) + { + $token = new SessionToken(); + + if (array_key_exists('session_id', $data)) { + $token->setToken($data['session_id']); + } + + if (array_key_exists('success', $data)) { + $token->setSuccess($data['success']); + } + + return $token; + } + + /** + * Create session token for guest + * + * @param array $data + * @return SessionToken + */ + public function createGuestSessionToken(array $data = array()) + { + $token = new SessionToken(); + + if (array_key_exists('expires_at', $data)) { + $token->setExpiresAt(new \DateTime($data['expires_at'])); + } + + if (array_key_exists('guest_session_id', $data)) { + $token->setToken($data['guest_session_id']); + } + + if (array_key_exists('success', $data)) { + $token->setSuccess($data['success']); + } + + return $token; + } +} diff --git a/modules/Tmdb/Factory/CertificationFactory.php b/modules/Tmdb/Factory/CertificationFactory.php new file mode 100644 index 00000000..6b92f418 --- /dev/null +++ b/modules/Tmdb/Factory/CertificationFactory.php @@ -0,0 +1,60 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Certification; +use Tmdb\Model\Common\GenericCollection; + +/** + * Class CertificationFactory + * @package Tmdb\Factory + */ +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; + } +} diff --git a/modules/Tmdb/Factory/ChangesFactory.php b/modules/Tmdb/Factory/ChangesFactory.php new file mode 100644 index 00000000..ba21489a --- /dev/null +++ b/modules/Tmdb/Factory/ChangesFactory.php @@ -0,0 +1,62 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Change; +use Tmdb\Model\Collection\Changes; + +/** + * Class ChangesFactory + * @package Tmdb\Factory + */ +class ChangesFactory extends AbstractFactory +{ + /** + * {@inheritdoc} + * @return \Tmdb\Model\Change + */ + public function create(array $data = array()) + { + return $this->hydrate(new Change(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new Changes(); + + if (array_key_exists('page', $data)) { + $collection->setPage($data['page']); + } + + if (array_key_exists('total_pages', $data)) { + $collection->setTotalPages($data['total_pages']); + } + + if (array_key_exists('total_results', $data)) { + $collection->setTotalResults($data['total_results']); + } + + if (array_key_exists('results', $data)) { + $data = $data['results']; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/CollectionFactory.php b/modules/Tmdb/Factory/CollectionFactory.php new file mode 100644 index 00000000..f1c29e2d --- /dev/null +++ b/modules/Tmdb/Factory/CollectionFactory.php @@ -0,0 +1,121 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Collection; +use Tmdb\Model\Common\GenericCollection; + +/** + * Class CollectionFactory + * @package Tmdb\Factory + */ +class CollectionFactory extends AbstractFactory +{ + /** + * @var MovieFactory + */ + private $movieFactory; + + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->movieFactory = new MovieFactory(); + $this->imageFactory = new ImageFactory(); + } + + /** + * {@inheritdoc} + * @return \Tmdb\Model\Collection + */ + public function create(array $data = array()) + { + $collection = new Collection(); + + if (array_key_exists('parts', $data)) { + $collection->setParts( + $this->getMovieFactory()->createCollection($data['parts']) + ); + } + + if (array_key_exists('backdrop_path', $data)) { + $collection->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); + } + + if (array_key_exists('images', $data)) { + $collection->setImages($this->getImageFactory()->createCollectionFromMovie($data['images'])); + } + + if (array_key_exists('poster_path', $data)) { + $collection->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + return $this->hydrate($collection, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } + + /** + * @param \Tmdb\Factory\MovieFactory $movieFactory + * @return $this + */ + public function setMovieFactory($movieFactory) + { + $this->movieFactory = $movieFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\MovieFactory + */ + public function getMovieFactory() + { + return $this->movieFactory; + } +} diff --git a/modules/Tmdb/Factory/Common/ChangeFactory.php b/modules/Tmdb/Factory/Common/ChangeFactory.php new file mode 100644 index 00000000..896ae1a7 --- /dev/null +++ b/modules/Tmdb/Factory/Common/ChangeFactory.php @@ -0,0 +1,75 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\Common; + +use Tmdb\Factory\AbstractFactory; +use Tmdb\Model\Common\Change; +use Tmdb\Model\Common\GenericCollection; + +/** + * Class ChangeFactory + * @package Tmdb\Factory\Common + */ +class ChangeFactory extends AbstractFactory +{ + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + $change = new Change(); + + if (array_key_exists('items', $data)) { + $items = new GenericCollection(); + + foreach($data['items'] as $item) { + $item = $this->createChangeItem($item); + + $items->add(null, $item); + } + + $change->setItems($items); + } + + return $this->hydrate($change, $data); + } + + /** + * Create individual change items + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + private function createChangeItem(array $data = array()) + { + return $this->hydrate(new Change\Item(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + if (array_key_exists('changes', $data)) { + $data = $data['changes']; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/Common/GenericCollectionFactory.php b/modules/Tmdb/Factory/Common/GenericCollectionFactory.php new file mode 100644 index 00000000..90cf3ce2 --- /dev/null +++ b/modules/Tmdb/Factory/Common/GenericCollectionFactory.php @@ -0,0 +1,55 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\Common; + +use Tmdb\Common\ObjectHydrator; +use Tmdb\Model\Common\GenericCollection; + +/** + * @deprecated + * + * Class GenericCollectionFactory + * @package Tmdb\Factory\Common + */ +class GenericCollectionFactory { + /** + * @param array $data + * @param $class + * @return GenericCollection + */ + public function create(array $data = array(), $class) + { + return $this->createCollection($data, $class); + } + + /** + * @param array $data + * @param $class + * @return GenericCollection + */ + public function createCollection(array $data = array(), $class) + { + if (is_object($class)) { + $class = get_class($class); + } + + $collection = new GenericCollection(); + $objectHydrator = new ObjectHydrator(); + + foreach($data as $item) { + $collection->add(null, $objectHydrator->hydrate(new $class(), $item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/CompanyFactory.php b/modules/Tmdb/Factory/CompanyFactory.php new file mode 100644 index 00000000..7fac2dda --- /dev/null +++ b/modules/Tmdb/Factory/CompanyFactory.php @@ -0,0 +1,75 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Company; + +/** + * Class CompanyFactory + * @package Tmdb\Factory + */ +class CompanyFactory extends AbstractFactory +{ + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->imageFactory = new ImageFactory(); + } + + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + $company = new Company(); + + if (array_key_exists('logo_path', $data)) { + $company->setLogoImage($this->getImageFactory()->createFromPath($data['logo_path'], 'logo_path')); + } + + return $this->hydrate($company, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + return array(); + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } +} diff --git a/modules/Tmdb/Factory/ConfigurationFactory.php b/modules/Tmdb/Factory/ConfigurationFactory.php new file mode 100644 index 00000000..0f18d267 --- /dev/null +++ b/modules/Tmdb/Factory/ConfigurationFactory.php @@ -0,0 +1,40 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Configuration; + +/** + * Class ConfigurationFactory + * @package Tmdb\Factory + */ +class ConfigurationFactory extends AbstractFactory +{ + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + $config = new Configuration(); + + return $this->hydrate($config, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + return array(); + } +} diff --git a/modules/Tmdb/Factory/CreditsFactory.php b/modules/Tmdb/Factory/CreditsFactory.php new file mode 100644 index 00000000..5b33634d --- /dev/null +++ b/modules/Tmdb/Factory/CreditsFactory.php @@ -0,0 +1,144 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Exception\NotImplementedException; +use Tmdb\Model\Genre; +use Tmdb\Model\Movie; +use Tmdb\Model\Credits as Credits; + +/** + * Class CreditsFactory + * @package Tmdb\Factory + */ +class CreditsFactory extends AbstractFactory +{ + /** + * @var TvSeasonFactory + */ + private $tvSeasonFactory; + + /** + * @var TvEpisodeFactory + */ + private $tvEpisodeFactory; + + /** + * @var PeopleFactory + */ + private $peopleFactory; + + public function __construct() + { + $this->tvSeasonFactory = new TvSeasonFactory(); + $this->tvEpisodeFactory = new TvEpisodeFactory(); + $this->peopleFactory = new PeopleFactory(); + } + + /** + * @param array $data + * + * @return Genre + */ + public function create(array $data = array()) + { + $credits = new Credits(); + + if (array_key_exists('media', $data)) { + + $credits->setMedia( + $this->hydrate($credits->getMedia(), $data['media']) + ); + + if (array_key_exists('seasons', $data['media'])) { + $episodes = $this->getTvSeasonFactory()->createCollection($data['media']['seasons']); + $credits->getMedia()->setSeasons($episodes); + } + + if (array_key_exists('episodes', $data['media'])) { + $episodes = $this->getTvEpisodeFactory()->createCollection($data['media']['episodes']); + $credits->getMedia()->setEpisodes($episodes); + } + } + + if (array_key_exists('person', $data)) { + $credits->setPerson( + $this->getPeopleFactory()->create($data['person']) + ); + } + + return $this->hydrate($credits, $data); + } + + /** + * @throws NotImplementedException + */ + public function createCollection(array $data = array()) + { + throw new NotImplementedException('Credits are usually obtained through the PeopleFactory, however we might add a shortcut for that here.'); + } + + /** + * @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/modules/Tmdb/Factory/FindFactory.php b/modules/Tmdb/Factory/FindFactory.php new file mode 100644 index 00000000..cba3716d --- /dev/null +++ b/modules/Tmdb/Factory/FindFactory.php @@ -0,0 +1,134 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Exception\NotImplementedException; +use Tmdb\Model\Find; + +/** + * Class FindFactory + * @package Tmdb\Factory + */ +class FindFactory extends AbstractFactory +{ + /** + * @var MovieFactory + */ + private $movieFactory; + + /** + * @var PeopleFactory + */ + private $peopleFactory; + + /** + * @var TvFactory + */ + private $tvFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->movieFactory = new MovieFactory(); + $this->peopleFactory = new PeopleFactory(); + $this->tvFactory = new TvFactory(); + } + + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + $find = new Find(); + + if (array_key_exists('movie_results', $data)) { + $find->setMovieResults($this->getMovieFactory()->createCollection($data['movie_results'])); + } + + if (array_key_exists('person_results', $data)) { + $find->setPersonResults($this->getPeopleFactory()->createCollection($data['person_results'])); + } + + if (array_key_exists('tv_results', $data)) { + $find->setTvResults($this->getTvFactory()->createCollection($data['tv_results'])); + } + + return $find; + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + throw new NotImplementedException(sprintf('Method "%s" is not implemented.', __METHOD__)); + } + + /** + * @param \Tmdb\Factory\MovieFactory $movieFactory + * @return $this + */ + public function setMovieFactory($movieFactory) + { + $this->movieFactory = $movieFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\MovieFactory + */ + public function getMovieFactory() + { + return $this->movieFactory; + } + + /** + * @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; + } + + /** + * @param \Tmdb\Factory\TvFactory $tvFactory + * @return $this + */ + public function setTvFactory($tvFactory) + { + $this->tvFactory = $tvFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\TvFactory + */ + public function getTvFactory() + { + return $this->tvFactory; + } + + +} diff --git a/modules/Tmdb/Factory/GenreFactory.php b/modules/Tmdb/Factory/GenreFactory.php new file mode 100644 index 00000000..f87116d3 --- /dev/null +++ b/modules/Tmdb/Factory/GenreFactory.php @@ -0,0 +1,52 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Collection\Genres; +use Tmdb\Model\Genre; +use Tmdb\Model\Movie; + +/** + * Class GenreFactory + * @package Tmdb\Factory + */ +class GenreFactory extends AbstractFactory +{ + /** + * @param array $data + * + * @return Genre + */ + public function create(array $data = array()) + { + return $this->hydrate(new Genre(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new Genres(); + + if (array_key_exists('genres', $data)) { + $data = $data['genres']; + } + + foreach($data as $item) { + $collection->addGenre($this->create($item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/ImageFactory.php b/modules/Tmdb/Factory/ImageFactory.php new file mode 100644 index 00000000..f1d0a2e3 --- /dev/null +++ b/modules/Tmdb/Factory/ImageFactory.php @@ -0,0 +1,202 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Collection\Images; +use Tmdb\Model\Image; + +/** + * Class ImageFactory + * @package Tmdb\Factory + */ +class ImageFactory extends AbstractFactory +{ + /** + * Convert an array to an hydrated object + * + * @param array $data + * @param string|null $key + * @return Image + */ + public function create(array $data = array(), $key = null) + { + $type = self::resolveImageType($key); + + return $this->hydrate($type, $data); + } + + /** + * Create an image instance based on the path and type, e.g. + * + * '/xkQ5yWnMjpC2bGmu7GsD66AAoKO.jpg', 'backdrop_path' + * + * @param $path + * @param string $key + * @return Image|Image\BackdropImage|Image\LogoImage|Image\PosterImage|Image\ProfileImage|Image\StillImage + */ + public function createFromPath($path, $key) + { + return $this->hydrate( + self::resolveImageType($key), + array('file_path' => $path) + ); + } + + /** + * Helper function to obtain a new object for an image type + * + * @param string|null $key + * @return Image|Image\BackdropImage|Image\LogoImage|Image\PosterImage|Image\ProfileImage|Image\StillImage + */ + public function resolveImageType($key = null) + { + switch($key) { + case 'poster': + case 'posters': + case 'poster_path': + $object = new Image\PosterImage(); + break; + + case 'backdrop': + case 'backdrops': + case 'backdrop_path': + $object = new Image\BackdropImage(); + break; + + case 'profile': + case 'profiles': + case 'profile_path': + $object = new Image\ProfileImage(); + break; + + case 'logo': + case 'logos': + case 'logo_path': + $object = new Image\LogoImage(); + break; + + case 'still': + case 'stills': + case 'still_path': + $object = new Image\StillImage(); + break; + + case 'file_path': + default: + $object = new Image(); + break; + } + + return $object; + } + + /** + * Create generic collection + * + * @param array $data + * @return Images + */ + public function createCollection(array $data = array()) + { + $collection = new Images(); + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } + + /** + * Create full collection + * + * @param array $data + * @return Images + */ + public function createImageCollection(array $data = array()) + { + $collection = new Images(); + + foreach($data as $format => $formatCollection) { + + if (!is_array($formatCollection)) { + continue; + } + + foreach($formatCollection as $item) { + if (array_key_exists($format, Image::$_formats)) { + $item = $this->create($item, $format); + + $collection->addImage($item); + } + } + } + + return $collection; + } + + /** + * Create full movie collection + * + * @param array $data + * @return Images + */ + public function createCollectionFromMovie(array $data = array()) + { + return $this->createImageCollection($data); + } + + /** + * Create full tv show collection + * + * @param array $data + * @return Images + */ + public function createCollectionFromTv(array $data = array()) + { + return $this->createImageCollection($data); + } + + /** + * Create full tv season collection + * + * @param array $data + * @return Images + */ + public function createCollectionFromTvSeason(array $data = array()) + { + return $this->createImageCollection($data); + } + + /** + * Create full tv episode collection + * + * @param array $data + * @return Images + */ + public function createCollectionFromTvEpisode(array $data = array()) + { + return $this->createImageCollection($data); + } + + /** + * Create full people collection + * + * @param array $data + * @return Images + */ + public function createCollectionFromPeople(array $data = array()) + { + return $this->createImageCollection($data); + } +} diff --git a/modules/Tmdb/Factory/JobsFactory.php b/modules/Tmdb/Factory/JobsFactory.php new file mode 100644 index 00000000..07725155 --- /dev/null +++ b/modules/Tmdb/Factory/JobsFactory.php @@ -0,0 +1,49 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Collection\Jobs; +use Tmdb\Model\Job; + +/** + * Class JobsFactory + * @package Tmdb\Factory + */ +class JobsFactory extends AbstractFactory +{ + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + return $this->hydrate(new Job(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new Jobs(); + + if (array_key_exists('jobs', $data)) { + $data = $data['jobs']; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/KeywordFactory.php b/modules/Tmdb/Factory/KeywordFactory.php new file mode 100644 index 00000000..2fe2c650 --- /dev/null +++ b/modules/Tmdb/Factory/KeywordFactory.php @@ -0,0 +1,52 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Collection\Keywords; +use Tmdb\Model\Keyword; +use Tmdb\Model\Movie; + +/** + * Class KeywordFactory + * @package Tmdb\Factory + */ +class KeywordFactory extends AbstractFactory +{ + /** + * @param array $data + * + * @return Keyword + */ + public function create(array $data = array()) + { + return $this->hydrate(new Keyword(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new Keywords(); + + if (array_key_exists('keywords', $data)) { + $data = $data['keywords']; + } + + foreach($data as $item) { + $collection->addKeyword($this->create($item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/ListFactory.php b/modules/Tmdb/Factory/ListFactory.php new file mode 100644 index 00000000..11e33b2d --- /dev/null +++ b/modules/Tmdb/Factory/ListFactory.php @@ -0,0 +1,145 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Factory\Lists\ListItemFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Genre; +use Tmdb\Model\Lists; +use Tmdb\Model\Movie; + +/** + * Class ListFactory + * @package Tmdb\Factory + */ +class ListFactory extends AbstractFactory +{ + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * @var ListItemFactory + */ + private $listItemFactory; + + public function __construct() + { + $this->imageFactory = new ImageFactory(); + $this->listItemFactory = new ListItemFactory(); + } + + /** + * @param array $data + * + * @return Genre + */ + public function create(array $data = array()) + { + $lists = new Lists(); + + if (array_key_exists('items', $data)) { + $lists->setItems( + $this->getListItemFactory()->createCollection($data['items']) + ); + } + + /** Images */ + if (array_key_exists('poster_path', $data)) { + $lists->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + return $this->hydrate($lists, $data); + } + + /** + * @param array $data + * + * @return Lists\ItemStatus + */ + public function createItemStatus(array $data = array()) + { + return $this->hydrate(new Lists\ItemStatus(), $data); + } + + /** + * @param array $data + * + * @return Lists\Result + */ + public function createResult(array $data = array()) + { + return $this->hydrate(new Lists\Result(), $data); + } + + /** + * @param array $data + * + * @return Lists\ResultWithListId + */ + public function createResultWithListId(array $data = array()) + { + return $this->hydrate(new Lists\ResultWithListId(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } + + /** + * @param \Tmdb\Factory\Lists\ListItemFactory $listItemFactory + * @return $this + */ + public function setListItemFactory($listItemFactory) + { + $this->listItemFactory = $listItemFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\Lists\ListItemFactory + */ + public function getListItemFactory() + { + return $this->listItemFactory; + } +} diff --git a/modules/Tmdb/Factory/Lists/ListItemFactory.php b/modules/Tmdb/Factory/Lists/ListItemFactory.php new file mode 100644 index 00000000..208cc9db --- /dev/null +++ b/modules/Tmdb/Factory/Lists/ListItemFactory.php @@ -0,0 +1,92 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\Lists; + +use Tmdb\Factory\AbstractFactory; +use Tmdb\Factory\ImageFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Lists\ListItem; + +/** + * Class ListItemFactory + * @package Tmdb\Factory\Lists + */ +class ListItemFactory extends AbstractFactory +{ + /** + * @var ImageFactory + */ + private $imageFactory; + + public function __construct() + { + $this->imageFactory = new ImageFactory(); + } + + /** + * @param array $data + * + * @return ListItem + */ + public function create(array $data = array()) + { + $listItem = new ListItem(); + + /** Images */ + if (array_key_exists('backdrop_path', $data)) { + $listItem->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); + } + + if (array_key_exists('poster_path', $data)) { + $listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + return $this->hydrate($listItem, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + if (array_key_exists('items', $data)) { + $data = $data['items']; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } +} diff --git a/modules/Tmdb/Factory/Movie/AlternativeTitleFactory.php b/modules/Tmdb/Factory/Movie/AlternativeTitleFactory.php new file mode 100644 index 00000000..7195f5b0 --- /dev/null +++ b/modules/Tmdb/Factory/Movie/AlternativeTitleFactory.php @@ -0,0 +1,48 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\Movie; + +use Tmdb\Factory\AbstractFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Movie\AlternativeTitle; + +/** + * Class AlternativeTitleFactory + * @package Tmdb\Factory\Movie + */ +class AlternativeTitleFactory extends AbstractFactory +{ + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + $title = new AlternativeTitle(); + + return $this->hydrate($title, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/Movie/ListItemFactory.php b/modules/Tmdb/Factory/Movie/ListItemFactory.php new file mode 100644 index 00000000..3ca64eae --- /dev/null +++ b/modules/Tmdb/Factory/Movie/ListItemFactory.php @@ -0,0 +1,71 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\Movie; + +use Tmdb\Factory\AbstractFactory; +use Tmdb\Factory\ImageFactory; +use Tmdb\Model\Movie\ListItem; + +/** + * Class ListItemFactory + * @package Tmdb\Factory\Movie + */ +class ListItemFactory extends AbstractFactory +{ + private $imageFactory; + + public function __construct() + { + $this->imageFactory = new ImageFactory(); + } + + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + $listItem = new ListItem(); + + if (array_key_exists('poster_path', $data)) { + $listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + return $this->hydrate($listItem, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + return $this->createResultCollection($data); + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } +} diff --git a/modules/Tmdb/Factory/MovieFactory.php b/modules/Tmdb/Factory/MovieFactory.php new file mode 100644 index 00000000..dac55bc5 --- /dev/null +++ b/modules/Tmdb/Factory/MovieFactory.php @@ -0,0 +1,370 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Factory\Common\ChangeFactory; +use Tmdb\Factory\Movie\ListItemFactory; +use Tmdb\Factory\People\CastFactory; +use Tmdb\Factory\People\CrewFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Common\Trailer\Youtube; +use Tmdb\Model\Common\Translation; +use Tmdb\Model\Lists\Result; +use Tmdb\Model\Movie; + +/** + * Class MovieFactory + * @package Tmdb\Factory + */ +class MovieFactory extends AbstractFactory { + /** + * @var People\CastFactory + */ + private $castFactory; + + /** + * @var People\CrewFactory + */ + private $crewFactory; + + /** + * @var GenreFactory + */ + private $genreFactory; + + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * @var ChangeFactory + */ + private $changeFactory; + + /** + * @var ReviewFactory + */ + private $reviewFactory; + + /** + * @var ListItemFactory + */ + private $listItemFactory; + + /** + * @var KeywordFactory + */ + private $keywordFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->castFactory = new CastFactory(); + $this->crewFactory = new CrewFactory(); + $this->genreFactory = new GenreFactory(); + $this->imageFactory = new ImageFactory(); + $this->changeFactory = new ChangeFactory(); + $this->reviewFactory = new ReviewFactory(); + $this->listItemFactory = new ListItemFactory(); + $this->keywordFactory = new KeywordFactory(); + } + + /** + * @param array $data + * @return Movie + */ + public function create(array $data = array()) + { + if (!$data) { + return null; + } + + $movie = new Movie(); + + if (array_key_exists('alternative_titles', $data) && array_key_exists('titles', $data['alternative_titles'])) { + $movie->setAlternativeTitles( + $this->createGenericCollection($data['alternative_titles']['titles'], new Movie\AlternativeTitle()) + ); + } + + if (array_key_exists('credits', $data)) { + if (array_key_exists('cast', $data['credits'])) { + $movie->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast'])); + } + + if (array_key_exists('crew', $data['credits'])) { + $movie->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew'])); + } + } + + /** Genres */ + if (array_key_exists('genres', $data)) { + $movie->setGenres($this->getGenreFactory()->createCollection($data['genres'])); + } + + /** Images */ + if (array_key_exists('backdrop_path', $data)) { + $movie->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); + } + + if (array_key_exists('images', $data)) { + $movie->setImages($this->getImageFactory()->createCollectionFromMovie($data['images'])); + } + + if (array_key_exists('poster_path', $data)) { + $movie->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + /** Keywords */ + if (array_key_exists('keywords', $data)) { + $movie->setKeywords($this->getKeywordFactory()->createCollection($data['keywords'])); + } + + if (array_key_exists('releases', $data) && array_key_exists('countries', $data['releases'])) { + $movie->setReleases($this->createGenericCollection($data['releases']['countries'], new Movie\Release())); + } + + /** + * @TODO actually implement more providers? ( Can't seem to find any quicktime related trailers anyways? ). For now KISS + */ + if (array_key_exists('trailers', $data) && array_key_exists('youtube', $data['trailers'])) { + $movie->setTrailers($this->createGenericCollection($data['trailers']['youtube'], new Youtube())); + } + + if (array_key_exists('translations', $data) && array_key_exists('translations', $data['translations'])) { + $movie->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation())); + } + + if (array_key_exists('similar_movies', $data)) { + $movie->setSimilarMovies($this->createResultCollection($data['similar_movies'])); + } + + if (array_key_exists('reviews', $data)) { + $movie->setReviews($this->getReviewFactory()->createResultCollection($data['reviews'])); + } + + if (array_key_exists('lists', $data)) { + $movie->setLists($this->getListItemFactory()->createResultCollection($data['lists'])); + } + + if (array_key_exists('changes', $data)) { + $movie->setChanges($this->getChangeFactory()->createCollection($data['changes'])); + } + + return $this->hydrate($movie, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + if (array_key_exists('results', $data)) { + $data = $data['results']; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } + + /** + * Create result + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createResult(array $data = array()) { + return $this->hydrate(new Result(), $data); + } + + /** + * Create rating + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createRating(array $data = array()) { + return $this->hydrate(new Movie\Rating(), $data); + } + + /** + * Create the account states + * + * @param array $data + * @return \Tmdb\Model\AbstractModel + */ + public function createAccountStates(array $data = array()) + { + $accountStates = new Movie\AccountStates(); + + if (array_key_exists('rated', $data)) { + $rating = new Movie\Rating(); + + $accountStates->setRated($this->hydrate($rating, $data['rated'])); + } + + return $this->hydrate($accountStates, $data); + } + + /** + * @param \Tmdb\Factory\People\CastFactory $castFactory + * @return $this + */ + public function setCastFactory($castFactory) + { + $this->castFactory = $castFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\People\CastFactory + */ + public function getCastFactory() + { + return $this->castFactory; + } + + /** + * @param \Tmdb\Factory\People\CrewFactory $crewFactory + * @return $this + */ + public function setCrewFactory($crewFactory) + { + $this->crewFactory = $crewFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\People\CrewFactory + */ + public function getCrewFactory() + { + return $this->crewFactory; + } + + /** + * @param \Tmdb\Factory\GenreFactory $genreFactory + * @return $this + */ + public function setGenreFactory($genreFactory) + { + $this->genreFactory = $genreFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\GenreFactory + */ + public function getGenreFactory() + { + return $this->genreFactory; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } + + /** + * @param \Tmdb\Factory\Common\ChangeFactory $changeFactory + * @return $this + */ + public function setChangeFactory($changeFactory) + { + $this->changeFactory = $changeFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\Common\ChangeFactory + */ + public function getChangeFactory() + { + return $this->changeFactory; + } + + /** + * @param \Tmdb\Factory\ReviewFactory $reviewFactory + * @return $this + */ + public function setReviewFactory($reviewFactory) + { + $this->reviewFactory = $reviewFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ReviewFactory + */ + public function getReviewFactory() + { + return $this->reviewFactory; + } + + /** + * @param \Tmdb\Factory\Movie\ListItemFactory $listItemFactory + * @return $this + */ + public function setListItemFactory($listItemFactory) + { + $this->listItemFactory = $listItemFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\Movie\ListItemFactory + */ + public function getListItemFactory() + { + return $this->listItemFactory; + } + + /** + * @param \Tmdb\Factory\KeywordFactory $keywordFactory + * @return $this + */ + public function setKeywordFactory($keywordFactory) + { + $this->keywordFactory = $keywordFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\KeywordFactory + */ + public function getKeywordFactory() + { + return $this->keywordFactory; + } +} \ No newline at end of file diff --git a/modules/Tmdb/Factory/NetworkFactory.php b/modules/Tmdb/Factory/NetworkFactory.php new file mode 100644 index 00000000..fd2cc67f --- /dev/null +++ b/modules/Tmdb/Factory/NetworkFactory.php @@ -0,0 +1,52 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Network; +use Tmdb\Model\Movie; + +/** + * Class NetworkFactory + * @package Tmdb\Factory + */ +class NetworkFactory extends AbstractFactory +{ + /** + * @param array $data + * + * @return Network + */ + public function create(array $data = array()) + { + return $this->hydrate(new Network(), $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + if (array_key_exists('networks', $data)) { + $data = $data['networks']; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/People/CastFactory.php b/modules/Tmdb/Factory/People/CastFactory.php new file mode 100644 index 00000000..09300754 --- /dev/null +++ b/modules/Tmdb/Factory/People/CastFactory.php @@ -0,0 +1,53 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\People; + +use Tmdb\Factory\PeopleFactory; +use Tmdb\Model\Collection\People\Cast; + +/** + * Class CastFactory + * @package Tmdb\Factory\People + */ +class CastFactory extends PeopleFactory +{ + /** + * {@inheritdoc} + */ + public function create(array $data = array(), $person = null) + { + return parent::create($data, $person); + } + + /** + * {@inheritdoc} + * @param \Tmdb\Model\Person\CastMember $person + */ + public function createCollection(array $data = array(), $person = null) + { + $collection = new Cast(); + + if (is_object($person)) { + $class = get_class($person); + } + else{ + $class = '\Tmdb\Model\Person\CastMember'; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item, new $class())); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/People/CrewFactory.php b/modules/Tmdb/Factory/People/CrewFactory.php new file mode 100644 index 00000000..ae9bf8ec --- /dev/null +++ b/modules/Tmdb/Factory/People/CrewFactory.php @@ -0,0 +1,53 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\People; + +use Tmdb\Factory\PeopleFactory; +use Tmdb\Model\Collection\People\Crew; + +/** + * Class CrewFactory + * @package Tmdb\Factory\People + */ +class CrewFactory extends PeopleFactory +{ + /** + * {@inheritdoc} + */ + public function create(array $data = array(), $person = null) + { + return parent::create($data, $person); + } + + /** + * {@inheritdoc} + * @param \Tmdb\Model\Person\CrewMember $person + */ + public function createCollection(array $data = array(), $person = null) + { + $collection = new Crew(); + + if (is_object($person)) { + $class = get_class($person); + } + else{ + $class = '\Tmdb\Model\Person\CrewMember'; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item, new $class())); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Factory/PeopleFactory.php b/modules/Tmdb/Factory/PeopleFactory.php new file mode 100644 index 00000000..a46b8901 --- /dev/null +++ b/modules/Tmdb/Factory/PeopleFactory.php @@ -0,0 +1,206 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Common\ObjectHydrator; +use Tmdb\Factory\Common\ChangeFactory; +use Tmdb\Model\Collection\People; +use Tmdb\Model\Common\ExternalIds; +use Tmdb\Model\Person\CastMember; +use Tmdb\Model\Person\CrewMember; +use Tmdb\Model\Person; + +/** + * Class PeopleFactory + * @package Tmdb\Factory + */ +class PeopleFactory extends AbstractFactory { + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * @var ChangeFactory + */ + private $changeFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->imageFactory = new ImageFactory(); + $this->changeFactory = new ChangeFactory(); + } + + /** + * @param array $data + * @param Person\AbstractMember|null $person + * + * @return Person|CrewMember|CastMember + */ + public function create(array $data = array(), $person = null) + { + if (!is_object($person)) { + if (array_key_exists('character', $data)) { + $person = new CastMember(); + } + + if (array_key_exists('job', $data)) { + $person = new CrewMember(); + } + + if (null === $person) { + $person = new Person(); + } + } + + if (array_key_exists('profile_path', $data)) { + $person->setProfileImage($this->getImageFactory()->createFromPath($data['profile_path'], 'profile_path')); + } + + if ($person instanceof Person) { + /** Images */ + if (array_key_exists('images', $data)) { + $person->setImages($this->getImageFactory()->createCollectionFromPeople($data['images'])); + } + + /** Credits */ + $this->applyCredits($data, $person); + } + + if (array_key_exists('changes', $data)) { + $person->setChanges($this->getChangeFactory()->createCollection($data['changes'])); + } + + /** External ids */ + if (array_key_exists('external_ids', $data)) { + $person->setExternalIds( + $this->hydrate(new ExternalIds(), $data['external_ids']) + ); + } + + return $this->hydrate($person, $data); + } + + /** + * Apply credits + * + * @param array $data + * @param Person $person + */ + protected function applyCredits(array $data = array(), Person $person) { + $hydrator = new ObjectHydrator(); + $types = array('movie_credits', 'tv_credits', 'combined_credits'); + + foreach($types as $type) { + if (array_key_exists($type, $data)) { + $method = $hydrator->camelize(sprintf('get_%s', $type)); + + if (array_key_exists('cast', $data[$type])) { + $cast = $this->createGenericCollection( + $data[$type]['cast'], + new Person\MovieCredit() + ); + + foreach($cast as $member) { + $member->setPosterImage($member->getPosterPath()); + } + + $person->$method()->setCast($cast); + } + + if (array_key_exists('crew', $data[$type])) { + $crew = $this->createGenericCollection( + $data[$type]['crew'], + new Person\MovieCredit() + ); + + foreach($crew as $member) { + $member->setPosterImage($member->getPosterPath()); + } + + $person->$method()->setCrew($crew); + } + } + } + } + + protected function getPosterImageForCredit($posterPath) + { + return $this->getImageFactory()->createFromPath($posterPath, 'poster_path'); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array(), $person = null, $collection = null) + { + if (!$collection) { + $collection = new People(); + } + + if (array_key_exists('results', $data)) { + $data = $data['results']; + } + + if (is_object($person)) { + $class = get_class($person); + } + else{ + $class = '\Tmdb\Model\Person'; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item, new $class())); + } + return $collection; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } + + /** + * @param \Tmdb\Factory\Common\ChangeFactory $changeFactory + * @return $this + */ + public function setChangeFactory($changeFactory) + { + $this->changeFactory = $changeFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\Common\ChangeFactory + */ + public function getChangeFactory() + { + return $this->changeFactory; + } +} diff --git a/modules/Tmdb/Factory/ReviewFactory.php b/modules/Tmdb/Factory/ReviewFactory.php new file mode 100644 index 00000000..4ff4ca05 --- /dev/null +++ b/modules/Tmdb/Factory/ReviewFactory.php @@ -0,0 +1,40 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Model\Review; + +/** + * Class ReviewFactory + * @package Tmdb\Factory + */ +class ReviewFactory extends AbstractFactory +{ + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + $review = new Review(); + + return $this->hydrate($review, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + return $this->createResultCollection($data); + } +} diff --git a/modules/Tmdb/Factory/TvEpisodeFactory.php b/modules/Tmdb/Factory/TvEpisodeFactory.php new file mode 100644 index 00000000..bc40a9a1 --- /dev/null +++ b/modules/Tmdb/Factory/TvEpisodeFactory.php @@ -0,0 +1,166 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Factory\People\CastFactory; +use Tmdb\Factory\People\CrewFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Person\CastMember; +use Tmdb\Model\Person\CrewMember; +use Tmdb\Model\Common\ExternalIds; +use Tmdb\Model\Tv\Episode; + +/** + * Class TvEpisodeFactory + * @package Tmdb\Factory + */ +class TvEpisodeFactory extends AbstractFactory { + /** + * @var People\CastFactory + */ + private $castFactory; + + /** + * @var People\CrewFactory + */ + private $crewFactory; + + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->castFactory = new CastFactory(); + $this->crewFactory = new CrewFactory(); + $this->imageFactory = new ImageFactory(); + } + + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + if (!$data) { + return null; + } + + $tvEpisode = new Episode(); + + if (array_key_exists('credits', $data)) { + if (array_key_exists('cast', $data['credits'])) { + $tvEpisode->getCredits()->setCast( + $this->getCastFactory()->createCollection($data['credits']['cast'], + new CastMember()) + ); + } + + if (array_key_exists('crew', $data['credits'])) { + $tvEpisode->getCredits()->setCrew( + $this->getCrewFactory()->createCollection($data['credits']['crew'], + new CrewMember()) + ); + } + } + + /** External ids */ + if (array_key_exists('external_ids', $data)) { + $tvEpisode->setExternalIds( + $this->hydrate(new ExternalIds(), $data['external_ids']) + ); + } + + /** Images */ + if (array_key_exists('images', $data)) { + $tvEpisode->setImages($this->getImageFactory()->createCollectionFromTvEpisode($data['images'])); + } + + if (array_key_exists('still_path', $data)) { + $tvEpisode->setStillImage($this->getImageFactory()->createFromPath($data['still_path'], 'still_path')); + } + + return $this->hydrate($tvEpisode, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } + + /** + * @param \Tmdb\Factory\People\CastFactory $castFactory + * @return $this + */ + public function setCastFactory($castFactory) + { + $this->castFactory = $castFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\People\CastFactory + */ + public function getCastFactory() + { + return $this->castFactory; + } + + /** + * @param \Tmdb\Factory\People\CrewFactory $crewFactory + * @return $this + */ + public function setCrewFactory($crewFactory) + { + $this->crewFactory = $crewFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\People\CrewFactory + */ + public function getCrewFactory() + { + return $this->crewFactory; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } +} diff --git a/modules/Tmdb/Factory/TvFactory.php b/modules/Tmdb/Factory/TvFactory.php new file mode 100644 index 00000000..0b1d1091 --- /dev/null +++ b/modules/Tmdb/Factory/TvFactory.php @@ -0,0 +1,263 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Factory\People\CastFactory; +use Tmdb\Factory\People\CrewFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Common\Translation; +use Tmdb\Model\Person\CastMember; +use Tmdb\Model\Person\CrewMember; +use Tmdb\Model\Common\ExternalIds; +use Tmdb\Model\Tv; + +/** + * Class TvFactory + * @package Tmdb\Factory + */ +class TvFactory extends AbstractFactory { + /** + * @var People\CastFactory + */ + private $castFactory; + + /** + * @var People\CrewFactory + */ + private $crewFactory; + + /** + * @var GenreFactory + */ + private $genreFactory; + + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * @var TvSeasonFactory + */ + private $tvSeasonFactory; + + /** + * @var NetworkFactory + */ + private $networkFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->castFactory = new CastFactory(); + $this->crewFactory = new CrewFactory(); + $this->genreFactory = new GenreFactory(); + $this->imageFactory = new ImageFactory(); + $this->tvSeasonFactory = new TvSeasonFactory(); + $this->networkFactory = new NetworkFactory(); + } + + /** + * @param array $data + * + * @return Tv + */ + public function create(array $data = array()) + { + if (!$data) { + return null; + } + + $tvShow = new Tv(); + + if (array_key_exists('credits', $data)) { + if (array_key_exists('cast', $data['credits'])) { + $tvShow->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast'], new CastMember())); + } + + if (array_key_exists('crew', $data['credits'])) { + $tvShow->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew'], new CrewMember())); + } + } + + /** External ids */ + if (array_key_exists('external_ids', $data)) { + $tvShow->setExternalIds( + $this->hydrate(new ExternalIds(), $data['external_ids']) + ); + } + + /** Genres */ + if (array_key_exists('genres', $data)) { + $tvShow->setGenres($this->getGenreFactory()->createCollection($data['genres'])); + } + + /** Images */ + if (array_key_exists('images', $data)) { + $tvShow->setImages($this->getImageFactory()->createCollectionFromTv($data['images'])); + } + + if (array_key_exists('backdrop_path', $data)) { + $tvShow->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); + } + + if (array_key_exists('poster_path', $data)) { + $tvShow->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + /** Translations */ + if (array_key_exists('translations', $data) && null !== $data['translations']) { + $tvShow->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation())); + } + + /** Seasons */ + if (array_key_exists('seasons', $data)) { + $tvShow->setSeasons($this->getTvSeasonFactory()->createCollection($data['seasons'])); + } + + /** Networks */ + if (array_key_exists('networks', $data)) { + $tvShow->setNetworks($this->getNetworkFactory()->createCollection($data['networks'])); + } + + return $this->hydrate($tvShow, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + if (array_key_exists('results', $data)) { + $data = $data['results']; + } + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } + + /** + * @param \Tmdb\Factory\People\CastFactory $castFactory + * @return $this + */ + public function setCastFactory($castFactory) + { + $this->castFactory = $castFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\People\CastFactory + */ + public function getCastFactory() + { + return $this->castFactory; + } + + /** + * @param \Tmdb\Factory\People\CrewFactory $crewFactory + * @return $this + */ + public function setCrewFactory($crewFactory) + { + $this->crewFactory = $crewFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\People\CrewFactory + */ + public function getCrewFactory() + { + return $this->crewFactory; + } + + /** + * @param \Tmdb\Factory\GenreFactory $genreFactory + * @return $this + */ + public function setGenreFactory($genreFactory) + { + $this->genreFactory = $genreFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\GenreFactory + */ + public function getGenreFactory() + { + return $this->genreFactory; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } + + /** + * @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\NetworkFactory $networkFactory + * @return $this + */ + public function setNetworkFactory($networkFactory) + { + $this->networkFactory = $networkFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\NetworkFactory + */ + public function getNetworkFactory() + { + return $this->networkFactory; + } +} diff --git a/modules/Tmdb/Factory/TvSeasonFactory.php b/modules/Tmdb/Factory/TvSeasonFactory.php new file mode 100644 index 00000000..78fc88d1 --- /dev/null +++ b/modules/Tmdb/Factory/TvSeasonFactory.php @@ -0,0 +1,189 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory; + +use Tmdb\Factory\People\CastFactory; +use Tmdb\Factory\People\CrewFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Person\CastMember; +use Tmdb\Model\Person\CrewMember; +use Tmdb\Model\Common\ExternalIds; +use Tmdb\Model\Tv\Season; + +/** + * Class TvSeasonFactory + * @package Tmdb\Factory + */ +class TvSeasonFactory extends AbstractFactory { + /** + * @var People\CastFactory + */ + private $castFactory; + + /** + * @var People\CrewFactory + */ + private $crewFactory; + + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * @var TvEpisodeFactory + */ + private $tvEpisodeFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->castFactory = new CastFactory(); + $this->crewFactory = new CrewFactory(); + $this->imageFactory = new ImageFactory(); + $this->tvEpisodeFactory = new TvEpisodeFactory(); + } + + /** + * {@inheritdoc} + */ + public function create(array $data = array()) + { + if (!$data) { + return null; + } + + $tvSeason = new Season(); + + if (array_key_exists('credits', $data)) { + if (array_key_exists('cast', $data['credits'])) { + $tvSeason->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast'], new CastMember())); + } + + if (array_key_exists('crew', $data['credits'])) { + $tvSeason->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew'], new CrewMember())); + } + } + + /** External ids */ + if (array_key_exists('external_ids', $data)) { + $tvSeason->setExternalIds( + $this->hydrate(new ExternalIds(), $data['external_ids']) + ); + } + + /** Images */ + if (array_key_exists('images', $data)) { + $tvSeason->setImages($this->getImageFactory()->createCollectionFromTvSeason($data['images'])); + } + + if (array_key_exists('poster_path', $data)) { + $tvSeason->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); + } + + /** Episodes */ + if (array_key_exists('episodes', $data)) { + $tvSeason->setEpisodes($this->getTvEpisodeFactory()->createCollection($data['episodes'])); + } + + return $this->hydrate($tvSeason, $data); + } + + /** + * {@inheritdoc} + */ + public function createCollection(array $data = array()) + { + $collection = new GenericCollection(); + + foreach($data as $item) { + $collection->add(null, $this->create($item)); + } + + return $collection; + } + + /** + * @param \Tmdb\Factory\People\CastFactory $castFactory + * @return $this + */ + public function setCastFactory($castFactory) + { + $this->castFactory = $castFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\People\CastFactory + */ + public function getCastFactory() + { + return $this->castFactory; + } + + /** + * @param \Tmdb\Factory\People\CrewFactory $crewFactory + * @return $this + */ + public function setCrewFactory($crewFactory) + { + $this->crewFactory = $crewFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\People\CrewFactory + */ + public function getCrewFactory() + { + return $this->crewFactory; + } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } + + /** + * @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; + } +} diff --git a/modules/Tmdb/Helper/ImageHelper.php b/modules/Tmdb/Helper/ImageHelper.php new file mode 100644 index 00000000..c5f94fce --- /dev/null +++ b/modules/Tmdb/Helper/ImageHelper.php @@ -0,0 +1,93 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Helper; + +use Tmdb\Model\Configuration; +use Tmdb\Model\Image; + +/** + * Class ImageHelper + * @package Tmdb\Helper + */ +class ImageHelper { + + private $config; + + public function __construct(Configuration $config) + { + $this->config = $config; + } + + /** + * Load the image configuration collection + * + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getImageConfiguration() + { + return $this->config->getImages(); + } + + /** + * Get the url for the image resource + * + * @param Image $image + * @param string $size + * @return string + */ + public function getUrl(Image $image, $size = 'original') { + $config = $this->getImageConfiguration(); + + return $config['base_url'] . $size . $image->getFilePath(); + } + + /** + * Get an img html tag for the image in the specified size + * + * @param Image $image + * @param string $size + * @param int|null $width + * @param int|null $height + * @return string + */ + public function getHtml(Image $image, $size = 'original', $width = null, $height = null) { + if (null == $image->getFilePath()) { + return ''; + } + + $aspectRatio = $image->getAspectRatio(); + + if (null !== $width && null == $height && $aspectRatio !== null) { + $height = round($width / $aspectRatio); + } + + if (null !== $height && null == $width && $aspectRatio !== null) { + $width = round($height * $aspectRatio); + } + + if (null == $width) { + $width = $image->getWidth(); + } + + if (null == $height) { + $height = $image->getHeight(); + } + + return sprintf( + '', + $this->getUrl($image, $size), + $width, + $height + ); + } +} diff --git a/modules/Tmdb/HttpClient/HttpClient.php b/modules/Tmdb/HttpClient/HttpClient.php new file mode 100644 index 00000000..76554c25 --- /dev/null +++ b/modules/Tmdb/HttpClient/HttpClient.php @@ -0,0 +1,204 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\HttpClient; + +use Guzzle\Http\ClientInterface; +use Guzzle\Http\Message\Request; +use Guzzle\Http\Message\RequestInterface; +use Guzzle\Http\Message\Response; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Class HttpClient + * @package Tmdb\HttpClient + */ +class HttpClient + implements HttpClientInterface +{ + /** + * @var \Guzzle\Http\ClientInterface + */ + private $client; + + protected $options = array(); + protected $base_url = null; + + /** + * @var Response + */ + private $lastResponse; + + /** + * @var Request + */ + private $lastRequest; + + /** + * Constructor + * + * @param string $baseUrl + * @param array $options + * @param ClientInterface $client + */ + public function __construct($baseUrl, array $options, ClientInterface $client) + { + $this->base_url = $baseUrl; + $this->options = $options; + $this->client = $client; + } + + /** + * Add a subscriber + * + * @param EventSubscriberInterface $subscriber + */ + public function addSubscriber(EventSubscriberInterface $subscriber) + { + $this->client->addSubscriber($subscriber); + } + + /** + * Set the query parameters + * + * @param $queryParameters + * @return array + */ + protected function buildQueryParameters($queryParameters) + { + return array_merge($this->options, array('query' => $queryParameters)); + } + + /** + * {@inheritDoc} + */ + public function get($path, array $parameters = array(), array $headers = array()) + { + $parameters = $this->buildQueryParameters($parameters); + + return $this->request( + $this->client->get($path, $headers, $parameters) + ); + } + + /** + * {@inheritDoc} + */ + public function head($path, array $parameters = array(), array $headers = array()) + { + $parameters = $this->buildQueryParameters($parameters); + + return $this->request( + $this->client->head($path, $headers, $parameters) + ); + } + + /** + * {@inheritDoc} + */ + public function post($path, $postBody, array $parameters = array(), array $headers = array()) + { + $parameters = $this->buildQueryParameters($parameters); + + return $this->request( + $this->client->post($path, $headers, $postBody, $parameters) + ); + } + + /** + * {@inheritDoc} + */ + public function postJson($path, $postBody, array $parameters = array(), array $headers = array()) + { + $parameters = $this->buildQueryParameters($parameters); + $request = $this->client->post($path, $headers, null, $parameters); + $request->setBody($postBody, 'application/json'); + + return $this->request($request); + } + + /** + * {@inheritDoc} + */ + public function patch($path, $body = null, array $parameters = array(), array $headers = array()) + { + $parameters = $this->buildQueryParameters($parameters); + + return $this->request( + $this->client->patch($path, $headers, $body, $parameters) + ); + } + + /** + * {@inheritDoc} + */ + public function delete($path, $body = null, array $parameters = array(), array $headers = array()) + { + $parameters = $this->buildQueryParameters($parameters); + + return $this->request( + $this->client->delete($path, $headers, $body, $parameters) + ); + } + + /** + * {@inheritDoc} + */ + public function put($path, $body = null, array $parameters = array(), array $headers = array()) + { + $parameters = $this->buildQueryParameters($parameters); + + return $this->request( + $this->client->put($path, $headers, $body, $parameters) + ); + } + + /** + * @{inheritDoc} + */ + public function request(RequestInterface $request) + { + $response = null; + + try { + $response = $request->send(); + } + catch(\Exception $e) + { + // @TODO catch any API errors / timeouts / other specific information from Guzzle? + throw $e; + } + + $this->lastRequest = $request; + $this->lastResponse = $response; + + return $response; + } + + /** + * @param \Guzzle\Http\ClientInterface $client + * @return $this + */ + public function setClient($client) + { + $this->client = $client; + return $this; + } + + /** + * @return \Guzzle\Http\ClientInterface + */ + public function getClient() + { + return $this->client; + } +} diff --git a/modules/Tmdb/HttpClient/HttpClientInterface.php b/modules/Tmdb/HttpClient/HttpClientInterface.php new file mode 100644 index 00000000..1899df98 --- /dev/null +++ b/modules/Tmdb/HttpClient/HttpClientInterface.php @@ -0,0 +1,103 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\HttpClient; + +use Guzzle\Http\Message\RequestInterface; +use Guzzle\Http\Message\Response; + +/** + * Interface HttpClientInterface + * @package Tmdb\HttpClient + */ +interface HttpClientInterface +{ + /** + * Compose a GET request + * + * @param string $path Request path + * @param array $parameters GET Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return Response Data + */ + public function get($path, array $parameters = array(), array $headers = array()); + + /** + * Compose a POST request + * + * @param string $path Request path + * @param string $postBody The post BODY + * @param array $parameters POST Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return Response Data + */ + public function post($path, $postBody, array $parameters = array(), array $headers = array()); + + /** + * Compose a POST request but json_encode the body + * + * @param string $path Request path + * @param array $postBody The post BODY + * @param array $parameters POST Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return Response Data + */ + public function postJson($path, $postBody, array $parameters = array(), array $headers = array()); + + /** + * Compose a PATCH request + * + * @param string $path Request path + * @param string $body The body + * @param array $parameters PATCH Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return Response Data + */ + public function patch($path, $body = null, array $parameters = array(), array $headers = array()); + + /** + * Compose a PUT request + * + * @param string $path Request path + * @param string $body The body + * @param array $parameters PUT Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return Response Data + */ + public function put($path, $body = null, array $parameters = array(), array $headers = array()); + + /** + * Compose a DELETE request + * + * @param string $path Request path + * @param string $body The body + * @param array $parameters DELETE Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return Response Data + */ + public function delete($path, $body = null, array $parameters = array(), array $headers = array()); + + /** + * Send a request to the server, receive a response, + * decode the response and returns an associative array + * @param $request RequestInterface + * @return Response + */ + public function request(RequestInterface $request); + +} diff --git a/modules/Tmdb/HttpClient/Plugin/AcceptJsonHeaderPlugin.php b/modules/Tmdb/HttpClient/Plugin/AcceptJsonHeaderPlugin.php new file mode 100644 index 00000000..05fc6a11 --- /dev/null +++ b/modules/Tmdb/HttpClient/Plugin/AcceptJsonHeaderPlugin.php @@ -0,0 +1,33 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\HttpClient\Plugin; + +use Guzzle\Common\Event; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Class AcceptJsonHeaderPlugin + * @package Tmdb\HttpClient\Plugin + */ +class AcceptJsonHeaderPlugin implements EventSubscriberInterface +{ + public static function getSubscribedEvents() + { + return array('request.before_send' => 'onBeforeSend'); + } + + public function onBeforeSend(Event $event) + { + $event['request']->setHeader('accept', 'application/json'); + } +} diff --git a/modules/Tmdb/HttpClient/Plugin/AdultFilterPlugin.php b/modules/Tmdb/HttpClient/Plugin/AdultFilterPlugin.php new file mode 100644 index 00000000..18698271 --- /dev/null +++ b/modules/Tmdb/HttpClient/Plugin/AdultFilterPlugin.php @@ -0,0 +1,44 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\HttpClient\Plugin; + +use Guzzle\Common\Event; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Class AdultFilterPlugin + * @package Tmdb\HttpClient\Plugin + */ +class AdultFilterPlugin implements EventSubscriberInterface +{ + private $includeAdult; + + public function __construct($includeAdult = false) + { + $this->includeAdult = $includeAdult; + } + + public static function getSubscribedEvents() + { + return array('request.before_send' => 'onBeforeSend'); + } + + public function onBeforeSend(Event $event) + { + $url = $event['request']->getUrl(true); + + $url->getQuery()->set('include_adult', $this->includeAdult === true ? 'true' : 'false'); + + $event['request']->setUrl($url); + } +} diff --git a/modules/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php b/modules/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php new file mode 100644 index 00000000..c7eaa6a6 --- /dev/null +++ b/modules/Tmdb/HttpClient/Plugin/ApiTokenPlugin.php @@ -0,0 +1,48 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\HttpClient\Plugin; + +use Guzzle\Common\Event; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Tmdb\ApiToken; + +/** + * Class ApiTokenPlugin + * @package Tmdb\HttpClient\Plugin + */ +class ApiTokenPlugin implements EventSubscriberInterface +{ + /** + * @var \Tmdb\ApiToken + */ + private $token; + + public function __construct(ApiToken $token) + { + $this->token = $token; + } + + public static function getSubscribedEvents() + { + return array('request.before_send' => 'onBeforeSend'); + } + + public function onBeforeSend(Event $event) + { + $url = $event['request']->getUrl(true); + + $url->getQuery()->set('api_key', $this->token->getToken()); + + $event['request']->setUrl($url); + } +} diff --git a/modules/Tmdb/HttpClient/Plugin/LanguageFilterPlugin.php b/modules/Tmdb/HttpClient/Plugin/LanguageFilterPlugin.php new file mode 100644 index 00000000..122f059d --- /dev/null +++ b/modules/Tmdb/HttpClient/Plugin/LanguageFilterPlugin.php @@ -0,0 +1,44 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\HttpClient\Plugin; + +use Guzzle\Common\Event; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Class LanguageFilterPlugin + * @package Tmdb\HttpClient\Plugin + */ +class LanguageFilterPlugin implements EventSubscriberInterface +{ + private $language; + + public function __construct($language = 'en') + { + $this->language = $language; + } + + public static function getSubscribedEvents() + { + return array('request.before_send' => 'onBeforeSend'); + } + + public function onBeforeSend(Event $event) + { + $url = $event['request']->getUrl(true); + + $url->getQuery()->set('language', $this->language); + + $event['request']->setUrl($url); + } +} diff --git a/modules/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php b/modules/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php new file mode 100644 index 00000000..d7536df0 --- /dev/null +++ b/modules/Tmdb/HttpClient/Plugin/SessionTokenPlugin.php @@ -0,0 +1,48 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\HttpClient\Plugin; + +use Guzzle\Common\Event; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Tmdb\SessionToken; + +/** + * Class SessionTokenPlugin + * @package Tmdb\HttpClient\Plugin + */ +class SessionTokenPlugin implements EventSubscriberInterface +{ + /** + * @var \Tmdb\ApiToken + */ + private $token; + + public function __construct(SessionToken $token) + { + $this->token = $token; + } + + public static function getSubscribedEvents() + { + return array('request.before_send' => 'onBeforeSend'); + } + + public function onBeforeSend(Event $event) + { + $url = $event['request']->getUrl(true); + + $url->getQuery()->set('session_id', $this->token->getToken()); + + $event['request']->setUrl($url); + } +} diff --git a/modules/Tmdb/Model/AbstractModel.php b/modules/Tmdb/Model/AbstractModel.php new file mode 100644 index 00000000..4d40864f --- /dev/null +++ b/modules/Tmdb/Model/AbstractModel.php @@ -0,0 +1,27 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class AbstractModel + * @package Tmdb\Model + */ +class AbstractModel { + /** + * List of properties to populate by the ObjectHydrator + * + * @var array + */ + public static $_properties = array(); + +} diff --git a/modules/Tmdb/Model/Account.php b/modules/Tmdb/Model/Account.php new file mode 100644 index 00000000..a9334b51 --- /dev/null +++ b/modules/Tmdb/Model/Account.php @@ -0,0 +1,171 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class Account + * @package Tmdb\Model + */ +class Account extends AbstractModel { + /** + * @var integer + */ + private $id; + + /** + * @var boolean + */ + private $includeAdult; + + /** + * @var string + */ + private $iso31661; + + /** + * @var string + */ + private $iso6391; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $username; + + /** + * @var array + */ + public static $_properties = array( + 'id', + 'include_adult', + 'iso_3166_1', + 'iso_639_1', + 'name', + 'username' + ); + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param boolean $includeAdult + * @return $this + */ + public function setIncludeAdult($includeAdult) + { + $this->includeAdult = $includeAdult; + return $this; + } + + /** + * @return boolean + */ + public function getIncludeAdult() + { + return $this->includeAdult; + } + + /** + * @param string $iso31661 + * @return $this + */ + public function setIso31661($iso31661) + { + $this->iso31661 = $iso31661; + return $this; + } + + /** + * @return string + */ + public function getIso31661() + { + return $this->iso31661; + } + + /** + * @param string $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return string + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $username + * @return $this + */ + public function setUsername($username) + { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getUsername() + { + return $this->username; + } + + +} diff --git a/modules/Tmdb/Model/Account/ListItem.php b/modules/Tmdb/Model/Account/ListItem.php new file mode 100644 index 00000000..7ce61239 --- /dev/null +++ b/modules/Tmdb/Model/Account/ListItem.php @@ -0,0 +1,243 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Account; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image\PosterImage; + +/** + * Class ListItem + * @package Tmdb\Model\Account + */ +class ListItem extends AbstractModel { + /** + * @var string + */ + private $id; + + /** + * @var string + */ + private $description; + + /** + * @var int + */ + private $favoriteCount; + + /** + * @var int + */ + private $itemCount; + + /** + * @var string + */ + private $iso6391; + + /** + * @var string + */ + private $listType; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $posterPath; + + /** + * @var PosterImage + */ + private $posterImage; + + /** + * @var array + */ + public static $_properties = array( + 'description', + 'favorite_count', + 'id', + 'item_count', + 'iso_639_1', + 'list_type', + 'name', + 'poster_path' + ); + + /** + * @param string $description + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param int $favoriteCount + * @return $this + */ + public function setFavoriteCount($favoriteCount) + { + $this->favoriteCount = $favoriteCount; + return $this; + } + + /** + * @return int + */ + public function getFavoriteCount() + { + return $this->favoriteCount; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return string + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param int $itemCount + * @return $this + */ + public function setItemCount($itemCount) + { + $this->itemCount = $itemCount; + return $this; + } + + /** + * @return int + */ + public function getItemCount() + { + return $this->itemCount; + } + + /** + * @param string $listType + * @return $this + */ + public function setListType($listType) + { + $this->listType = $listType; + return $this; + } + + /** + * @return string + */ + public function getListType() + { + return $this->listType; + } + + /** + * @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\Image\PosterImage $posterImage + * @return $this + */ + public function setPosterImage($posterImage) + { + $this->posterImage = $posterImage; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->posterImage; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } +} diff --git a/modules/Tmdb/Model/Certification.php b/modules/Tmdb/Model/Certification.php new file mode 100644 index 00000000..dea8b7f6 --- /dev/null +++ b/modules/Tmdb/Model/Certification.php @@ -0,0 +1,77 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Common\GenericCollection; + +/** + * Class Certification + * @package Tmdb\Model + */ +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/modules/Tmdb/Model/Certification/CountryCertification.php b/modules/Tmdb/Model/Certification/CountryCertification.php new file mode 100644 index 00000000..479a93d1 --- /dev/null +++ b/modules/Tmdb/Model/Certification/CountryCertification.php @@ -0,0 +1,99 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Certification; + +use Tmdb\Model\AbstractModel; + +/** + * Class CountryCertification + * @package Tmdb\Model\Certification + */ +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/modules/Tmdb/Model/Change.php b/modules/Tmdb/Model/Change.php new file mode 100644 index 00000000..c3186cce --- /dev/null +++ b/modules/Tmdb/Model/Change.php @@ -0,0 +1,73 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class Change + * @package Tmdb\Model + */ +class Change extends AbstractModel { + /** + * @var integer + */ + private $id; + + /** + * @var boolean + */ + private $adult; + + /** + * @var array + */ + public static $_properties = array( + 'id', + 'adult' + ); + + /** + * @param boolean $adult + * @return $this + */ + public function setAdult($adult) + { + $this->adult = (bool) $adult; + return $this; + } + + /** + * @return boolean + */ + public function getAdult() + { + return $this->adult; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } +} diff --git a/modules/Tmdb/Model/Collection.php b/modules/Tmdb/Model/Collection.php new file mode 100644 index 00000000..e11948a9 --- /dev/null +++ b/modules/Tmdb/Model/Collection.php @@ -0,0 +1,246 @@ + + * @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 + * @package Tmdb\Model + */ +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 string + */ + private $overview; + + /** + * @var Common\GenericCollection + */ + private $parts; + + /** + * @var string + */ + private $posterPath; + + /** + * @var PosterImage + */ + private $poster; + + public static $_properties = array( + 'backdrop_path', + 'id', + 'name', + 'overview', + 'poster_path', + ); + + public function __construct() + { + $this->parts = new GenericCollection(); + $this->images = new Images(); + } + + /** + * @param \Tmdb\Model\Image\BackdropImage $backdrop + * @return $this + */ + public function setBackdropImage(BackdropImage $backdrop) + { + $this->backdrop = $backdrop; + return $this; + } + + /** + * @return \Tmdb\Model\Image\BackdropImage + */ + public function getBackdropImage() + { + 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 = (int) $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param \Tmdb\Model\Collection\Images $images + * @return $this + */ + public function setImages(Images $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 string $overview + * @return $this + */ + public function setOverview($overview) + { + $this->overview = $overview; + return $this; + } + + /** + * @return string + */ + public function getOverview() + { + return $this->overview; + } + + /** + * @param GenericCollection $parts + * @return $this + */ + public function setParts($parts) + { + $this->parts = $parts; + return $this; + } + + /** + * @return GenericCollection + */ + public function getParts() + { + return $this->parts; + } + + /** + * @param \Tmdb\Model\Image\PosterImage $poster + * @return $this + */ + public function setPosterImage(PosterImage $poster) + { + $this->poster = $poster; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + 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; + } +} diff --git a/modules/Tmdb/Model/Collection/Changes.php b/modules/Tmdb/Model/Collection/Changes.php new file mode 100644 index 00000000..1d047b89 --- /dev/null +++ b/modules/Tmdb/Model/Collection/Changes.php @@ -0,0 +1,19 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +/** + * Class Changes + * @package Tmdb\Model\Collection + */ +class Changes extends ResultCollection {} diff --git a/modules/Tmdb/Model/Collection/CreditsCollection.php b/modules/Tmdb/Model/Collection/CreditsCollection.php new file mode 100644 index 00000000..d81f57ab --- /dev/null +++ b/modules/Tmdb/Model/Collection/CreditsCollection.php @@ -0,0 +1,78 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +use Tmdb\Model\Collection\People\Cast; +use Tmdb\Model\Collection\People\Crew; +use Tmdb\Model\Common\GenericCollection; + +/** + * Class CreditsCollection + * @package Tmdb\Model\Collection + */ +class CreditsCollection { + /** + * @var Cast + */ + public $cast; + + /** + * @var Crew + */ + private $crew; + + /** + * Constructor + */ + public function __construct() + { + $this->cast = new Cast(); + $this->crew = new Crew(); + } + + /** + * @param Cast|GenericCollection $cast + * @return $this + */ + public function setCast(GenericCollection $cast) + { + $this->cast = $cast; + return $this; + } + + /** + * @return Cast + */ + public function getCast() + { + return $this->cast; + } + + /** + * @param Crew|GenericCollection $crew + * @return $this + */ + public function setCrew(GenericCollection $crew) + { + $this->crew = $crew; + return $this; + } + + /** + * @return Crew + */ + public function getCrew() + { + return $this->crew; + } +} diff --git a/modules/Tmdb/Model/Collection/CreditsCollection/CombinedCredits.php b/modules/Tmdb/Model/Collection/CreditsCollection/CombinedCredits.php new file mode 100644 index 00000000..a321af2d --- /dev/null +++ b/modules/Tmdb/Model/Collection/CreditsCollection/CombinedCredits.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection\CreditsCollection; + +use Tmdb\Model\Collection\CreditsCollection; + +/** + * Class CombinedCredits + * @package Tmdb\Model\Collection\CreditsCollection + */ +class CombinedCredits extends CreditsCollection {} diff --git a/modules/Tmdb/Model/Collection/CreditsCollection/MovieCredits.php b/modules/Tmdb/Model/Collection/CreditsCollection/MovieCredits.php new file mode 100644 index 00000000..6d63d4cd --- /dev/null +++ b/modules/Tmdb/Model/Collection/CreditsCollection/MovieCredits.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection\CreditsCollection; + +use Tmdb\Model\Collection\CreditsCollection; + +/** + * Class MovieCredits + * @package Tmdb\Model\Collection\CreditsCollection + */ +class MovieCredits extends CreditsCollection {} diff --git a/modules/Tmdb/Model/Collection/CreditsCollection/TvCredits.php b/modules/Tmdb/Model/Collection/CreditsCollection/TvCredits.php new file mode 100644 index 00000000..b2d91be7 --- /dev/null +++ b/modules/Tmdb/Model/Collection/CreditsCollection/TvCredits.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection\CreditsCollection; + +use Tmdb\Model\Collection\CreditsCollection; + +/** + * Class TvCredits + * @package Tmdb\Model\Collection\CreditsCollection + */ +class TvCredits extends CreditsCollection {} diff --git a/modules/Tmdb/Model/Collection/Genres.php b/modules/Tmdb/Model/Collection/Genres.php new file mode 100644 index 00000000..169fc1a6 --- /dev/null +++ b/modules/Tmdb/Model/Collection/Genres.php @@ -0,0 +1,59 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Genre; + +/** + * Class Genres + * @package Tmdb\Model\Collection + */ +class Genres extends GenericCollection { + + /** + * Returns all genres + * + * @return Genre[] + */ + public function getGenres() + { + return $this->data; + } + + /** + * Retrieve a genre from the collection + * + * @param $id + * @return Genre|null + */ + public function getGenre($id) { + foreach($this->data as $genre) { + if ($id === $genre->getId()) { + return $genre; + } + } + + return null; + } + + /** + * Add a genre to the collection + * + * @param Genre $genre + */ + public function addGenre(Genre $genre) + { + $this->data[] = $genre; + } +} diff --git a/modules/Tmdb/Model/Collection/Images.php b/modules/Tmdb/Model/Collection/Images.php new file mode 100644 index 00000000..38525357 --- /dev/null +++ b/modules/Tmdb/Model/Collection/Images.php @@ -0,0 +1,193 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Filter\ImageFilter; +use Tmdb\Model\Image; + +/** + * Class Images + * @package Tmdb\Model\Collection + */ +class Images extends GenericCollection { + + /** + * Returns all images + * + * @return array + */ + public function getImages() + { + return $this->data; + } + + /** + * Retrieve a image from the collection + * + * @param $id + * @return null + */ + public function getImage($id) { + return $this->filterId($id); + } + + /** + * Add a image to the collection + * + * @param Image $image + */ + public function addImage(Image $image) + { + $this->add(null, $image); + } + + /** + * Filter poster images + * + * @return Images + */ + public function filterPosters() + { + return $this->filter( + function($key, $value) { + if ($value instanceof ImageFilter && $value instanceof Image\PosterImage) { return true; } + } + ); + } + + /** + * Filter backdrop images + * + * @return Images + */ + public function filterBackdrops() + { + return $this->filter( + function($key, $value) { + if ($value instanceof ImageFilter && $value instanceof Image\BackdropImage) { return true; } + } + ); + } + + /** + * Filter profile images + * + * @return Images + */ + public function filterProfile() + { + return $this->filter( + function($key, $value) { + if ($value instanceof ImageFilter && $value instanceof Image\ProfileImage) { return true; } + } + ); + } + + /** + * Filter still images + * + * @return Images + */ + public function filterStills() + { + return $this->filter( + function($key, $value) { + if ($value instanceof ImageFilter && $value instanceof Image\StillImage) { return true; } + } + ); + } + + /** + * Filter by image size + * + * @param $width + * @return Images + */ + public function filterMaxWidth($width) + { + return $this->filter( + function($key, $value) use ($width) { + if ($value instanceof ImageFilter && $value->getWidth() <= $width && $value->getWidth() !== null) { return true; } + } + ); + } + + /** + * Filter by image size + * + * @param $width + * @return Images + */ + public function filterMinWidth($width) + { + return $this->filter( + function($key, $value) use ($width) { + if ($value instanceof ImageFilter && $value->getWidth() >= $width && $value->getWidth() !== null) { return true; } + } + ); + } + + /** + * Filter by image size + * + * @param $height + * @return Images + */ + public function filterMaxHeight($height) + { + return $this->filter( + function($key, $value) use ($height) { + if ($value instanceof ImageFilter && $value->getHeight() <= $height && $value->getHeight() !== null) { return true; } + } + ); + } + + /** + * Filter by image size + * + * @param $height + * @return Images + */ + public function filterMinHeight($height) + { + return $this->filter( + function($key, $value) use ($height) { + if ($value instanceof ImageFilter && $value->getHeight() >= $height && $value->getHeight() !== null) { return true; } + } + ); + } + + /** + * Return a single image that is rated highest + * + * @return ImageFilter|null + */ + public function filterBestVotedImage() + { + $currentImage = null; + $voteAverage = 0; + + /** + * @var $image Image + */ + foreach($this->data as $image) { + if ($image->getVoteAverage() > $voteAverage) { + $voteAverage = $image->getVoteAverage(); + $currentImage = $image; + } + } + + return $currentImage; + } +} diff --git a/modules/Tmdb/Model/Collection/Jobs.php b/modules/Tmdb/Model/Collection/Jobs.php new file mode 100644 index 00000000..6f2312b6 --- /dev/null +++ b/modules/Tmdb/Model/Collection/Jobs.php @@ -0,0 +1,94 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +use Tmdb\Model\Common\GenericCollection; + +/** + * Class Jobs + * @package Tmdb\Model\Collection + */ +class Jobs extends GenericCollection { + + /** + * Filter by department + * + * @param string $department + * @return $this + */ + public function filterByDepartment($department) + { + $result = $this->filter( + function($key, $value) use ($department) { + if ($value->getDepartment() == $department) { return true; } + } + ); + + if ($result && 1 === count($result)) { + $results = $result->toArray(); + return array_shift($results); + } + + return $result; + } + + /** + * Filter by department and return the jobs collection + * + * @param string $department + * @return $this + */ + public function filterByDepartmentAndReturnJobsList($department) + { + $result = $this->filter( + function($key, $value) use ($department) { + if ($value->getDepartment() == $department) { return true; } + } + ); + + if ($result && 1 === count($result)) { + $results = $result->toArray(); + $data = array_shift($results); + + return $data->getJobList(); + } + + return $result; + } + + /** + * Filter by job + * + * @param string $filterByJob + * @return $this + */ + public function filterByJob($filterByJob) + { + $result = $this->filter( + function($key, $value) use ($filterByJob) { + $jobList = $value->getJobList(); + + foreach($jobList as $job) { + if ($filterByJob == $job) { return true; } + } + } + ); + + if ($result && 1 === count($result)) { + $results = $result->toArray(); + return array_shift($results); + } + + return $result; + } +} diff --git a/modules/Tmdb/Model/Collection/Keywords.php b/modules/Tmdb/Model/Collection/Keywords.php new file mode 100644 index 00000000..d6d52a90 --- /dev/null +++ b/modules/Tmdb/Model/Collection/Keywords.php @@ -0,0 +1,53 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Keyword; + +/** + * Class Keywords + * @package Tmdb\Model\Collection + */ +class Keywords extends GenericCollection { + + /** + * Returns all keywords + * + * @return array + */ + public function getKeywords() + { + return $this->data; + } + + /** + * Retrieve a keyword from the collection + * + * @param $id + * @return Keyword + */ + public function getKeyword($id) { + return $this->filterId($id); + } + + /** + * Add a keyword to the collection + * + * @param Keyword $keyword + */ + public function addKeyword(Keyword $keyword) + { + $this->data[] = $keyword; + } +} diff --git a/modules/Tmdb/Model/Collection/People.php b/modules/Tmdb/Model/Collection/People.php new file mode 100644 index 00000000..65a16784 --- /dev/null +++ b/modules/Tmdb/Model/Collection/People.php @@ -0,0 +1,54 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Collection\People\PersonInterface; +use Tmdb\Model\Person; + +/** + * Class People + * @package Tmdb\Model\Collection + */ +class People extends GenericCollection { + + /** + * Returns all people + * + * @return Person[] + */ + public function getPeople() + { + return $this->data; + } + + /** + * Retrieve a person from the collection + * + * @param $id + * @return Person + */ + public function getPerson($id) { + return $this->filterId($id); + } + + /** + * Add a person to the collection + * + * @param PersonInterface $person + */ + public function addPerson(PersonInterface $person) + { + $this->data[] = $person; + } +} diff --git a/modules/Tmdb/Model/Collection/People/Cast.php b/modules/Tmdb/Model/Collection/People/Cast.php new file mode 100644 index 00000000..ff4b8dbc --- /dev/null +++ b/modules/Tmdb/Model/Collection/People/Cast.php @@ -0,0 +1,42 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection\People; + +use Tmdb\Model\Collection\People; +use Tmdb\Model\Person; + +/** + * Class Cast + * @package Tmdb\Model\Collection\People + */ +class Cast extends People { + /** + * Returns all people + * + * @return Person[] + */ + public function getCast() + { + return parent::getPeople(); + } + + /** + * Retrieve a cast member from the collection + * + * @param $id + * @return Person + */ + public function getCastMember($id) { + return parent::getPerson($id); + } +} diff --git a/modules/Tmdb/Model/Collection/People/Crew.php b/modules/Tmdb/Model/Collection/People/Crew.php new file mode 100644 index 00000000..d3a06649 --- /dev/null +++ b/modules/Tmdb/Model/Collection/People/Crew.php @@ -0,0 +1,42 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection\People; + +use Tmdb\Model\Collection\People; +use Tmdb\Model\Person; + +/** + * Class Crew + * @package Tmdb\Model\Collection\People + */ +class Crew extends People { + /** + * Returns all people + * + * @return Person[] + */ + public function getCrew() + { + return parent::getPeople(); + } + + /** + * Retrieve a crew member from the collection + * + * @param $id + * @return Person + */ + public function getCrewMember($id) { + return parent::getPerson($id); + } +} diff --git a/modules/Tmdb/Model/Collection/People/PersonInterface.php b/modules/Tmdb/Model/Collection/People/PersonInterface.php new file mode 100644 index 00000000..4f4538c1 --- /dev/null +++ b/modules/Tmdb/Model/Collection/People/PersonInterface.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection\People; + +/** + * Interface PersonInterface + * @package Tmdb\Model\Collection\People + */ +interface PersonInterface { + function getName(); + + /** + * @return integer + */ + function getId(); +} diff --git a/modules/Tmdb/Model/Collection/QueryParameter/AppendToResponse.php b/modules/Tmdb/Model/Collection/QueryParameter/AppendToResponse.php new file mode 100644 index 00000000..5523f6c2 --- /dev/null +++ b/modules/Tmdb/Model/Collection/QueryParameter/AppendToResponse.php @@ -0,0 +1,23 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection\QueryParameter; + +use Tmdb\Model\Common\QueryParameter\AppendToResponse as BaseAppendToResponse; + +/** + * Class AppendToResponse + * @package Tmdb\Model\Collection\QueryParameter + */ +final class AppendToResponse extends BaseAppendToResponse { + const IMAGES = 'images'; +} diff --git a/modules/Tmdb/Model/Collection/QueryParametersCollection.php b/modules/Tmdb/Model/Collection/QueryParametersCollection.php new file mode 100644 index 00000000..b1f3cd21 --- /dev/null +++ b/modules/Tmdb/Model/Collection/QueryParametersCollection.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +use Tmdb\Model\Common\GenericCollection; + +/** + * Class QueryParametersCollection + * @package Tmdb\Model\Collection + */ +class QueryParametersCollection extends GenericCollection {} diff --git a/modules/Tmdb/Model/Collection/ResultCollection.php b/modules/Tmdb/Model/Collection/ResultCollection.php new file mode 100644 index 00000000..aa0acbcc --- /dev/null +++ b/modules/Tmdb/Model/Collection/ResultCollection.php @@ -0,0 +1,99 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Collection; + +use Tmdb\Model\Common\GenericCollection; + +/** + * Class ResultCollection + * @package Tmdb\Model\Collection + */ +class ResultCollection extends GenericCollection { + /** + * @var int + */ + private $page = 1; + + /** + * @var int + */ + private $totalPages = 1; + + /** + * @var int + */ + private $totalResults = 0; + + /** + * @var array + */ + public static $_properties = array( + 'page', + 'total_pages', + 'total_results' + ); + + /** + * @param int $page + * @return $this + */ + public function setPage($page) + { + $this->page = (int) $page; + return $this; + } + + /** + * @return int + */ + public function getPage() + { + return $this->page; + } + + /** + * @param int $totalPages + * @return $this + */ + public function setTotalPages($totalPages) + { + $this->totalPages = (int) $totalPages; + return $this; + } + + /** + * @return int + */ + public function getTotalPages() + { + return $this->totalPages; + } + + /** + * @param int $totalResults + * @return $this + */ + public function setTotalResults($totalResults) + { + $this->totalResults = (int) $totalResults; + return $this; + } + + /** + * @return int + */ + public function getTotalResults() + { + return $this->totalResults; + } +} diff --git a/modules/Tmdb/Model/Common/AbstractTrailer.php b/modules/Tmdb/Model/Common/AbstractTrailer.php new file mode 100644 index 00000000..083a3c9e --- /dev/null +++ b/modules/Tmdb/Model/Common/AbstractTrailer.php @@ -0,0 +1,28 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common; + +use Tmdb\Model\AbstractModel; + +/** + * Class AbstractTrailer + * @package Tmdb\Model\Common + */ +abstract class AbstractTrailer extends AbstractModel { + /** + * Returns the http url to the trailer + * + * @return string + */ + abstract public function getUrl(); +} diff --git a/modules/Tmdb/Model/Common/Change.php b/modules/Tmdb/Model/Common/Change.php new file mode 100644 index 00000000..2d4663f3 --- /dev/null +++ b/modules/Tmdb/Model/Common/Change.php @@ -0,0 +1,79 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common; + +use Tmdb\Model\AbstractModel; + +/** + * Class Change + * @package Tmdb\Model\Common + */ +class Change extends AbstractModel { + + /** + * @var string + */ + private $key; + + /** + * @var GenericCollection + */ + private $items; + + public static $_properties = array( + 'key', + ); + + public function __construct() + { + $this->items = new GenericCollection(); + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $items + * @return $this + */ + public function setItems($items) + { + $this->items = $items; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getItems() + { + return $this->items; + } + + /** + * @param string $key + * @return $this + */ + public function setKey($key) + { + $this->key = $key; + return $this; + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + +} diff --git a/modules/Tmdb/Model/Common/Change/Item.php b/modules/Tmdb/Model/Common/Change/Item.php new file mode 100644 index 00000000..766483a4 --- /dev/null +++ b/modules/Tmdb/Model/Common/Change/Item.php @@ -0,0 +1,128 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common\Change; + +use Tmdb\Model\AbstractModel; + +/** + * Class Item + * @package Tmdb\Model\Common\Change + */ +class Item extends AbstractModel { + + /** + * @var string + */ + private $id; + + /** + * @var string + */ + private $action; + + /** + * @var \DateTime + */ + private $time; + + /** + * @var array + */ + private $value; + + public static $_properties = array( + 'id', + 'action', + 'time', + 'value' + ); + + /** + * @param string $action + * @return $this + */ + public function setAction($action) + { + $this->action = $action; + return $this; + } + + /** + * @return string + */ + public function getAction() + { + return $this->action; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string|\DateTime $time + * @return $this + */ + public function setTime($time) + { + if (!$time instanceof \DateTime) { + $time = new \DateTime($time); + } + + $this->time = $time; + return $this; + } + + /** + * @return \DateTime + */ + public function getTime() + { + return $this->time; + } + + /** + * @param array $value + * @return $this + */ + public function setValue($value) + { + $this->value = $value; + return $this; + } + + /** + * @return array + */ + public function getValue() + { + return $this->value; + } + + + +} diff --git a/modules/Tmdb/Model/Common/Country.php b/modules/Tmdb/Model/Common/Country.php new file mode 100644 index 00000000..9e0dfcd4 --- /dev/null +++ b/modules/Tmdb/Model/Common/Country.php @@ -0,0 +1,67 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Filter\CountryFilter; + +/** + * Class Country + * @package Tmdb\Model\Common + */ +class Country extends AbstractModel implements CountryFilter { + + private $iso31661; + private $name; + + public static $_properties = array( + 'iso_3166_1', + 'name', + ); + + /** + * @param string $iso31661 + * @return $this + */ + public function setIso31661($iso31661) + { + $this->iso31661 = $iso31661; + return $this; + } + + /** + * @return string + */ + public function getIso31661() + { + return $this->iso31661; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } +} diff --git a/modules/Tmdb/Model/Common/ExternalIds.php b/modules/Tmdb/Model/Common/ExternalIds.php new file mode 100644 index 00000000..a36a4b13 --- /dev/null +++ b/modules/Tmdb/Model/Common/ExternalIds.php @@ -0,0 +1,146 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common; + +use Tmdb\Model\AbstractModel; + +/** + * Class ExternalIds + * @package Tmdb\Model\Common + */ +class ExternalIds extends AbstractModel { + + private $imdbId; + private $freebaseId; + private $freebaseMid; + private $id; + private $tvdbId; + private $tvrageId; + + public static $_properties = array( + 'imdb_id', + 'freebase_id', + 'freebase_mid', + 'id', + 'tvdb_id', + 'tvrage_id', + ); + + /** + * @param mixed $freebaseId + * @return $this + */ + public function setFreebaseId($freebaseId) + { + $this->freebaseId = $freebaseId; + return $this; + } + + /** + * @return mixed + */ + public function getFreebaseId() + { + return $this->freebaseId; + } + + /** + * @param mixed $freebaseMid + * @return $this + */ + public function setFreebaseMid($freebaseMid) + { + $this->freebaseMid = $freebaseMid; + return $this; + } + + /** + * @return mixed + */ + public function getFreebaseMid() + { + return $this->freebaseMid; + } + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $imdbId + * @return $this + */ + public function setImdbId($imdbId) + { + $this->imdbId = $imdbId; + return $this; + } + + /** + * @return mixed + */ + public function getImdbId() + { + return $this->imdbId; + } + + /** + * @param mixed $tvdbId + * @return $this + */ + public function setTvdbId($tvdbId) + { + $this->tvdbId = $tvdbId; + return $this; + } + + /** + * @return mixed + */ + public function getTvdbId() + { + return $this->tvdbId; + } + + /** + * @param mixed $tvrageId + * @return $this + */ + public function setTvrageId($tvrageId) + { + $this->tvrageId = $tvrageId; + return $this; + } + + /** + * @return mixed + */ + public function getTvrageId() + { + return $this->tvrageId; + } +} diff --git a/modules/Tmdb/Model/Common/GenericCollection.php b/modules/Tmdb/Model/Common/GenericCollection.php new file mode 100644 index 00000000..bd9ef70c --- /dev/null +++ b/modules/Tmdb/Model/Common/GenericCollection.php @@ -0,0 +1,374 @@ + + * @author Michael Roterman + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common; + +use Tmdb\Model\Filter\AdultFilter; +use Tmdb\Model\Filter\CountryFilter; +use Tmdb\Model\Filter\LanguageFilter; + +/** + * Class GenericCollection + * @package Tmdb\Model\Common + */ +class GenericCollection implements \ArrayAccess, \IteratorAggregate, \Countable { + /** @var array Data associated with the object. */ + protected $data = array(); + + /** + * @param array $data Associative array of data to set + */ + public function __construct(array $data = array()) + { + $this->data = $data; + } + + /** + * @return int + */ + public function count() + { + return count($this->data); + } + + /** + * @return \ArrayIterator|\Traversable + */ + public function getIterator() + { + return new \ArrayIterator($this->data); + } + + /** + * @return array + */ + public function toArray() + { + return $this->data; + } + + /** + * Removes all key value pairs + * + * @return GenericCollection + */ + public function clear() + { + $this->data = array(); + + return $this; + } + + /** + * Get all or a subset of matching key value pairs + * + * @param array $keys Pass an array of keys to retrieve only a subset of key value pairs + * + * @return array Returns an array of all matching key value pairs + */ + public function getAll(array $keys = null) + { + return $keys ? array_intersect_key($this->data, array_flip($keys)) : $this->data; + } + + /** + * Get a specific key value. + * + * @param string $key Key to retrieve. + * + * @return mixed|null Value of the key or NULL + */ + public function get($key) + { + if (is_object($key)) { + $key = spl_object_hash($key); + } + + return isset($this->data[$key]) ? $this->data[$key] : null; + } + + /** + * Set a key value pair + * + * @param string $key Key to set + * @param mixed $value Value to set + * + * @return GenericCollection Returns a reference to the object + */ + public function set($key, $value) + { + if ($key === null && is_object($value)) { + $key = spl_object_hash($value); + } + + $this->data[$key] = $value; + + return $this; + } + + /** + * Add a value to a key. + * + * @param string $key Key to add + * @param mixed $value Value to add to the key + * + * @return GenericCollection Returns a reference to the object. + */ + public function add($key, $value) + { + if ($key === null && is_object($value)) { + $key = spl_object_hash($value); + } + + if (!array_key_exists($key, $this->data)) { + $this->data[$key] = $value; + } elseif (is_array($this->data[$key])) { + $this->data[$key][] = $value; + } else { + $this->data[$key] = array($this->data[$key], $value); + } + + return $this; + } + + /** + * Remove a specific key value pair + * + * @param string $key A key to remove or an object in the same state + * + * @return GenericCollection + */ + public function remove($key) + { + if (is_object($key)) { + $key = spl_object_hash($key); + } + + unset($this->data[$key]); + + return $this; + } + + /** + * Get all keys in the collection + * + * @return array + */ + public function getKeys() + { + return array_keys($this->data); + } + + /** + * Returns whether or not the specified key is present. + * + * @param string $key The key for which to check the existence. + * + * @return bool + */ + public function hasKey($key) + { + return array_key_exists($key, $this->data); + } + + /** + * Case insensitive search the keys in the collection + * + * @param string $key Key to search for + * + * @return bool|string Returns false if not found, otherwise returns the key + */ + public function keySearch($key) + { + foreach (array_keys($this->data) as $k) { + if (!strcasecmp($k, $key)) { + return $k; + } + } + + return false; + } + + /** + * Checks if any keys contains a certain value + * + * @param string $value Value to search for + * + * @return mixed Returns the key if the value was found FALSE if the value was not found. + */ + public function hasValue($value) + { + return array_search($value, $this->data); + } + + /** + * Replace the data of the object with the value of an array + * + * @param array $data Associative array of data + * + * @return GenericCollection Returns a reference to the object + */ + public function replace(array $data) + { + $this->data = $data; + + return $this; + } + + /** + * Add and merge in a Collection or array of key value pair data. + * + * @param GenericCollection|array $data Associative array of key value pair data + * + * @return GenericCollection Returns a reference to the object. + */ + public function merge($data) + { + foreach ($data as $key => $value) { + $this->add($key, $value); + } + + return $this; + } + + /** + * Returns a Collection containing all the elements of the collection after applying the callback function to each + * one. The Closure should accept three parameters: (string) $key, (string) $value, (array) $context and return a + * modified value + * + * @param \Closure $closure Closure to apply + * @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 GenericCollection + */ + public function map(\Closure $closure, array $context = array(), $static = true) + { + $collection = $static ? new static() : new self(); + foreach ($this as $key => $value) { + $collection->add($key, $closure($key, $value, $context)); + } + + return $collection; + } + + /** + * Iterates over each key value pair in the collection passing them to the Closure. If the Closure function returns + * true, the current value from input is returned into the result Collection. The Closure must accept three + * parameters: (string) $key, (string) $value and return Boolean TRUE or FALSE for each value. + * + * @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 GenericCollection + */ + public function filter(\Closure $closure, $static = true) + { + $collection = ($static) ? new static() : new self(); + foreach ($this->data as $key => $value) { + if ($closure($key, $value)) { + $collection->add($key, $value); + } + } + + return $collection; + } + + public function offsetExists($offset) + { + return isset($this->data[$offset]); + } + + public function offsetGet($offset) + { + return isset($this->data[$offset]) ? $this->data[$offset] : null; + } + + public function offsetSet($offset, $value) + { + $this->data[$offset] = $value; + } + + public function offsetUnset($offset) + { + unset($this->data[$offset]); + } + + /** + * Filter by id + * + * @param integer $id + * @return GenericCollection + */ + public function filterId($id) + { + $result = $this->filter( + function($key, $value) use ($id) { + if ($value->getId() == $id) { return true; } + } + ); + + if ($result && 1 === count($result)) { + return array_shift($this->data); + } + + return null; + } + + /** + * Filter by language ISO 639-1 code. + * + * @param string $language + * @return GenericCollection + */ + public function filterLanguage($language = 'en') + { + return $this->filter( + function($key, $value) use ($language) { + if ($value instanceof LanguageFilter && $value->getIso6391() == $language) { return true; } + } + ); + } + + /** + * Filter by country ISO 3166-1 code. + * + * @param string $country + * @return GenericCollection + */ + public function filterCountry($country = 'US') + { + return $this->filter( + function($key, $value) use ($country) { + if ($value instanceof CountryFilter && $value->getIso31661() == $country) { return true; } + } + ); + } + + /** + * Filter by adult content + * + * @param boolean $adult + * @return GenericCollection + */ + public function filterAdult($adult = false) + { + return $this->filter( + function($key, $value) use ($adult) { + if ($value instanceof AdultFilter && $value->getAdult() == $adult) { return true; } + } + ); + } +} diff --git a/modules/Tmdb/Model/Common/QueryParameter/Adult.php b/modules/Tmdb/Model/Common/QueryParameter/Adult.php new file mode 100644 index 00000000..5aed8bb2 --- /dev/null +++ b/modules/Tmdb/Model/Common/QueryParameter/Adult.php @@ -0,0 +1,43 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common\QueryParameter; + +/** + * Class Adult + * @package Tmdb\Model\Common\QueryParameter + */ +class Adult implements QueryParameterInterface { + + private $adult; + + public function __construct($adult) + { + $this->adult = $adult; + } + + /** + * @return string + */ + public function getKey() + { + return 'adult'; + } + + /** + * @return string + */ + public function getValue() + { + return $this->adult; + } +} diff --git a/modules/Tmdb/Model/Common/QueryParameter/AppendToResponse.php b/modules/Tmdb/Model/Common/QueryParameter/AppendToResponse.php new file mode 100644 index 00000000..a9c409d7 --- /dev/null +++ b/modules/Tmdb/Model/Common/QueryParameter/AppendToResponse.php @@ -0,0 +1,29 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common\QueryParameter; + +use Tmdb\Model\Common\QueryParameter\Type\CollectionToCommaSeperatedString; + +/** + * Class AppendToResponse + * @package Tmdb\Model\Common\QueryParameter + */ +class AppendToResponse extends CollectionToCommaSeperatedString { + /** + * @return string + */ + public function getKey() + { + return 'append_to_response'; + } +} diff --git a/modules/Tmdb/Model/Common/QueryParameter/Language.php b/modules/Tmdb/Model/Common/QueryParameter/Language.php new file mode 100644 index 00000000..4a91a10e --- /dev/null +++ b/modules/Tmdb/Model/Common/QueryParameter/Language.php @@ -0,0 +1,43 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common\QueryParameter; + +/** + * Class Language + * @package Tmdb\Model\Common\QueryParameter + */ +class Language implements QueryParameterInterface { + + private $language; + + public function __construct($language) + { + $this->language = $language; + } + + /** + * @return string + */ + public function getKey() + { + return 'language'; + } + + /** + * @return string + */ + public function getValue() + { + return $this->language; + } +} diff --git a/modules/Tmdb/Model/Common/QueryParameter/QueryParameterInterface.php b/modules/Tmdb/Model/Common/QueryParameter/QueryParameterInterface.php new file mode 100644 index 00000000..87ab2154 --- /dev/null +++ b/modules/Tmdb/Model/Common/QueryParameter/QueryParameterInterface.php @@ -0,0 +1,29 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common\QueryParameter; + +/** + * Interface QueryParameterInterface + * @package Tmdb\Model\Common\QueryParameter + */ +interface QueryParameterInterface { + /** + * @return string + */ + function getKey(); + + /** + * @return string + */ + function getValue(); +} diff --git a/modules/Tmdb/Model/Common/QueryParameter/Type/CollectionToCommaSeperatedString.php b/modules/Tmdb/Model/Common/QueryParameter/Type/CollectionToCommaSeperatedString.php new file mode 100644 index 00000000..05af7079 --- /dev/null +++ b/modules/Tmdb/Model/Common/QueryParameter/Type/CollectionToCommaSeperatedString.php @@ -0,0 +1,44 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common\QueryParameter\Type; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Common\QueryParameter\QueryParameterInterface; + +/** + * Class CollectionToCommaSeperatedString + * @package Tmdb\Model\Common\QueryParameter\Type + */ +abstract class CollectionToCommaSeperatedString extends GenericCollection implements QueryParameterInterface { + /** + * @param array $collection + */ + public function __construct(array $collection = array()) + { + $i = 0; + + foreach($collection as $item) { + $this->add($i, $item); + + $i++; + } + } + + /** + * {@inheritdoc} + */ + public function getValue() + { + return implode(',', $this->data); + } +} diff --git a/modules/Tmdb/Model/Common/SpokenLanguage.php b/modules/Tmdb/Model/Common/SpokenLanguage.php new file mode 100644 index 00000000..0c441d85 --- /dev/null +++ b/modules/Tmdb/Model/Common/SpokenLanguage.php @@ -0,0 +1,67 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Filter\LanguageFilter; + +/** + * Class SpokenLanguage + * @package Tmdb\Model\Common + */ +class SpokenLanguage extends AbstractModel implements LanguageFilter { + + private $iso6391; + private $name; + + public static $_properties = array( + 'iso_369_1', + 'name', + ); + + /** + * @param string $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return string + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } +} diff --git a/modules/Tmdb/Model/Common/Trailer/Youtube.php b/modules/Tmdb/Model/Common/Trailer/Youtube.php new file mode 100644 index 00000000..bc00660b --- /dev/null +++ b/modules/Tmdb/Model/Common/Trailer/Youtube.php @@ -0,0 +1,120 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common\Trailer; + +use Tmdb\Model\Common\AbstractTrailer; + +/** + * Class Youtube + * @package Tmdb\Model\Common\Trailer + */ +class Youtube extends AbstractTrailer { + + const URL = 'http://www.youtube.com/watch?v=%s'; + + private $name; + private $size; + private $source; + private $type; + + public static $_properties = array( + 'name', + 'size', + 'source', + 'type' + ); + + /** + * Retrieve the url to the source + * + * @todo add bonus hd=1 query parameters, but we'd need some easy way of configuring this behaviour + * + * @return string + */ + public function getUrl() + { + return sprintf(self::URL, $this->source); + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $size + * @return $this + */ + public function setSize($size) + { + $this->size = $size; + return $this; + } + + /** + * @return string + */ + public function getSize() + { + return $this->size; + } + + /** + * @param string $source + * @return $this + */ + public function setSource($source) + { + $this->source = $source; + return $this; + } + + /** + * @return string + */ + public function getSource() + { + return $this->source; + } + + /** + * @param string $type + * @return $this + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } +} diff --git a/modules/Tmdb/Model/Common/Translation.php b/modules/Tmdb/Model/Common/Translation.php new file mode 100644 index 00000000..6d0f9a64 --- /dev/null +++ b/modules/Tmdb/Model/Common/Translation.php @@ -0,0 +1,48 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Common; + +use Tmdb\Model\Filter\LanguageFilter; + +/** + * Class Translation + * @package Tmdb\Model\Common + */ +class Translation extends SpokenLanguage implements LanguageFilter { + + private $englishName; + + public static $_properties = array( + 'iso_639_1', + 'name', + 'english_name' + ); + + /** + * @param string $englishName + * @return $this + */ + public function setEnglishName($englishName) + { + $this->englishName = $englishName; + return $this; + } + + /** + * @return string + */ + public function getEnglishName() + { + return $this->englishName; + } +} diff --git a/modules/Tmdb/Model/Company.php b/modules/Tmdb/Model/Company.php new file mode 100644 index 00000000..79b8a351 --- /dev/null +++ b/modules/Tmdb/Model/Company.php @@ -0,0 +1,185 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Image\LogoImage; + +/** + * Class Company + * @package Tmdb\Model + */ +class Company extends AbstractModel { + + private $description; + private $headquarters; + private $homepage; + private $id; + private $logo; + private $logoPath; + private $name; + private $parentCompany; + + public static $_properties = array( + 'description', + 'headquarters', + 'homepage', + 'id', + 'logo_path', + 'name', + 'parent_company' + ); + + /** + * @param mixed $description + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * @return mixed + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param mixed $headquarters + * @return $this + */ + public function setHeadquarters($headquarters) + { + $this->headquarters = $headquarters; + return $this; + } + + /** + * @return mixed + */ + public function getHeadquarters() + { + return $this->headquarters; + } + + /** + * @param mixed $homepage + * @return $this + */ + public function setHomepage($homepage) + { + $this->homepage = $homepage; + return $this; + } + + /** + * @return mixed + */ + public function getHomepage() + { + return $this->homepage; + } + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param LogoImage $logo + * @return $this + */ + public function setLogoImage(LogoImage $logo) + { + $this->logo = $logo; + return $this; + } + + /** + * @return LogoImage + */ + public function getLogoImage() + { + return $this->logo; + } + + /** + * @param mixed $logoPath + * @return $this + */ + public function setLogoPath($logoPath) + { + $this->logoPath = $logoPath; + return $this; + } + + /** + * @return mixed + */ + public function getLogoPath() + { + return $this->logoPath; + } + + /** + * @param mixed $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @param mixed $parentCompany + * @return $this + */ + public function setParentCompany($parentCompany) + { + $this->parentCompany = $parentCompany; + return $this; + } + + /** + * @return mixed + */ + public function getParentCompany() + { + return $this->parentCompany; + } +} diff --git a/modules/Tmdb/Model/Configuration.php b/modules/Tmdb/Model/Configuration.php new file mode 100644 index 00000000..699dfeb7 --- /dev/null +++ b/modules/Tmdb/Model/Configuration.php @@ -0,0 +1,71 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class Configuration + * @package Tmdb\Model + */ +class Configuration extends AbstractModel { + + /** + * @var array + */ + private $images; + + /** + * @var array + */ + private $change_keys; + + public static $_properties = array( + 'images', + 'change_keys', + ); + + /** + * @param array $change_keys + * @return $this + */ + public function setChangeKeys(array $change_keys = array()) + { + $this->change_keys = $change_keys; + return $this; + } + + /** + * @return array + */ + public function getChangeKeys() + { + return $this->change_keys; + } + + /** + * @param array $images + * @return $this + */ + public function setImages(array $images = array()) + { + $this->images = $images; + return $this; + } + + /** + * @return array + */ + public function getImages() + { + return $this->images; + } +} diff --git a/modules/Tmdb/Model/Credits.php b/modules/Tmdb/Model/Credits.php new file mode 100644 index 00000000..72688a31 --- /dev/null +++ b/modules/Tmdb/Model/Credits.php @@ -0,0 +1,198 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Credits\Media; + +/** + * Class Credits + * @package Tmdb\Model + */ +class Credits extends AbstractModel { + /** + * @var string + */ + private $creditType; + + /** + * @var string + */ + private $department; + + /** + * @var string + */ + private $job; + + /** + * @var Media + */ + private $media; + + /** + * @var string + */ + private $mediaType; + + /** + * @var string + */ + private $id; + + /** + * @var Person + */ + private $person; + + /** + * @var array + */ + public static $_properties = array( + 'credit_type', + 'department', + 'job', + 'media_type', + 'id', + ); + + public function __construct() + { + $this->media = new Media(); + } + + /** + * @param string $creditType + * @return $this + */ + public function setCreditType($creditType) + { + $this->creditType = $creditType; + return $this; + } + + /** + * @return string + */ + public function getCreditType() + { + return $this->creditType; + } + + /** + * @param string $department + * @return $this + */ + public function setDepartment($department) + { + $this->department = $department; + return $this; + } + + /** + * @return string + */ + public function getDepartment() + { + return $this->department; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $job + * @return $this + */ + public function setJob($job) + { + $this->job = $job; + return $this; + } + + /** + * @return string + */ + public function getJob() + { + return $this->job; + } + + /** + * @param \Tmdb\Model\Credits\Media $media + * @return $this + */ + public function setMedia($media) + { + $this->media = $media; + return $this; + } + + /** + * @return \Tmdb\Model\Credits\Media + */ + public function getMedia() + { + return $this->media; + } + + /** + * @param string $mediaType + * @return $this + */ + public function setMediaType($mediaType) + { + $this->mediaType = $mediaType; + return $this; + } + + /** + * @return string + */ + public function getMediaType() + { + return $this->mediaType; + } + + /** + * @param \Tmdb\Model\Person $person + * @return $this + */ + public function setPerson($person) + { + $this->person = $person; + return $this; + } + + /** + * @return \Tmdb\Model\Person + */ + public function getPerson() + { + return $this->person; + } +} diff --git a/modules/Tmdb/Model/Credits/Media.php b/modules/Tmdb/Model/Credits/Media.php new file mode 100644 index 00000000..24b0e4b7 --- /dev/null +++ b/modules/Tmdb/Model/Credits/Media.php @@ -0,0 +1,167 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Credits; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Common\GenericCollection; + +/** + * Class Media + * @package Tmdb\Model\Credits + */ +class Media extends AbstractModel { + /** + * @var integer + */ + private $id; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $originalName; + + /** + * @var string + */ + private $character; + + /** + * @var GenericCollection + */ + private $episodes; + + /** + * @var GenericCollection + */ + private $seasons; + + public static $_properties = array( + 'id', + 'name', + 'original_name', + 'character', + ); + + /** + * @param string $character + * @return $this + */ + public function setCharacter($character) + { + $this->character = $character; + return $this; + } + + /** + * @return string + */ + public function getCharacter() + { + return $this->character; + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $episodes + * @return $this + */ + public function setEpisodes($episodes) + { + $this->episodes = $episodes; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getEpisodes() + { + return $this->episodes; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $originalName + * @return $this + */ + public function setOriginalName($originalName) + { + $this->originalName = $originalName; + return $this; + } + + /** + * @return string + */ + public function getOriginalName() + { + return $this->originalName; + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $seasons + * @return $this + */ + public function setSeasons($seasons) + { + $this->seasons = $seasons; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getSeasons() + { + return $this->seasons; + } +} diff --git a/modules/Tmdb/Model/Filter/AdultFilter.php b/modules/Tmdb/Model/Filter/AdultFilter.php new file mode 100644 index 00000000..71a612a8 --- /dev/null +++ b/modules/Tmdb/Model/Filter/AdultFilter.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Filter; + +/** + * Interface AdultFilter + * @package Tmdb\Model\Filter + */ +interface AdultFilter { + public function getAdult(); +} diff --git a/modules/Tmdb/Model/Filter/CountryFilter.php b/modules/Tmdb/Model/Filter/CountryFilter.php new file mode 100644 index 00000000..4d6645f4 --- /dev/null +++ b/modules/Tmdb/Model/Filter/CountryFilter.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Filter; + +/** + * Interface CountryFilter + * @package Tmdb\Model\Filter + */ +interface CountryFilter { + + /** + * @return string + */ + public function getIso31661(); +} diff --git a/modules/Tmdb/Model/Filter/ImageFilter.php b/modules/Tmdb/Model/Filter/ImageFilter.php new file mode 100644 index 00000000..593a8581 --- /dev/null +++ b/modules/Tmdb/Model/Filter/ImageFilter.php @@ -0,0 +1,20 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Filter; + +/** + * Interface ImageFilter + * @package Tmdb\Model\Filter + */ +interface ImageFilter { +} diff --git a/modules/Tmdb/Model/Filter/LanguageFilter.php b/modules/Tmdb/Model/Filter/LanguageFilter.php new file mode 100644 index 00000000..cc1d8d31 --- /dev/null +++ b/modules/Tmdb/Model/Filter/LanguageFilter.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Filter; + +/** + * Interface LanguageFilter + * @package Tmdb\Model\Filter + */ +interface LanguageFilter { + public function getIso6391(); +} diff --git a/modules/Tmdb/Model/Find.php b/modules/Tmdb/Model/Find.php new file mode 100644 index 00000000..4812265b --- /dev/null +++ b/modules/Tmdb/Model/Find.php @@ -0,0 +1,94 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Collection\People; +use Tmdb\Model\Common\GenericCollection; + +/** + * Class Find + * @package Tmdb\Model + */ +class Find extends AbstractModel { + + /** + * @var GenericCollection + */ + private $movieResults; + + /** + * @var People + */ + private $personResults; + + /** + * @var GenericCollection + */ + private $tvResults; + + /** + * @param \Tmdb\Model\Common\GenericCollection $movieResults + * @return $this + */ + public function setMovieResults($movieResults) + { + $this->movieResults = $movieResults; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getMovieResults() + { + return $this->movieResults; + } + + /** + * @param \Tmdb\Model\Collection\People $personResults + * @return $this + */ + public function setPersonResults($personResults) + { + $this->personResults = $personResults; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\People + */ + public function getPersonResults() + { + return $this->personResults; + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $tvResults + * @return $this + */ + public function setTvResults($tvResults) + { + $this->tvResults = $tvResults; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getTvResults() + { + return $this->tvResults; + } + + +} diff --git a/modules/Tmdb/Model/Genre.php b/modules/Tmdb/Model/Genre.php new file mode 100644 index 00000000..44569c02 --- /dev/null +++ b/modules/Tmdb/Model/Genre.php @@ -0,0 +1,64 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class Genre + * @package Tmdb\Model + */ +class Genre extends AbstractModel { + + private $id; + private $name; + + public static $_properties = array( + 'id', + 'name', + ); + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } +} diff --git a/modules/Tmdb/Model/Image.php b/modules/Tmdb/Model/Image.php new file mode 100644 index 00000000..28a77e4f --- /dev/null +++ b/modules/Tmdb/Model/Image.php @@ -0,0 +1,197 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Filter\ImageFilter; +use Tmdb\Model\Filter\LanguageFilter; + +/** + * Class Image + * @package Tmdb\Model + */ +class Image extends AbstractModel implements ImageFilter, LanguageFilter { + + const FORMAT_POSTER = 'poster'; + const FORMAT_BACKDROP = 'backdrop'; + const FORMAT_PROFILE = 'profile'; + const FORMAT_LOGO = 'logo'; + const FORMAT_STILL = 'still'; + + private $filePath; + private $width; + private $height; + private $iso6391; + private $aspectRatio; + private $voteAverage; + private $voteCount; + + protected $id; + protected $type; + + public static $_properties = array( + 'file_path', + 'width', + 'height', + 'iso_639_1', + 'aspect_ratio', + 'vote_average', + 'vote_count' + ); + + public static $_formats = array( + 'posters' => self::FORMAT_POSTER, + 'backdrops' => self::FORMAT_BACKDROP, + 'profiles' => self::FORMAT_PROFILE, + 'logos' => self::FORMAT_LOGO, + 'stills' => self::FORMAT_STILL + ); + + /** + * Get the singular type as defined in $_types + * + * @param $name + * @return mixed + */ + public static function getTypeFromCollectionName($name) + { + if (array_key_exists($name, self::$_formats)) { + return self::$_formats[$name]; + } + } + + /** + * @param float $aspectRatio + * @return $this + */ + public function setAspectRatio($aspectRatio) + { + $this->aspectRatio = (float) $aspectRatio; + return $this; + } + + /** + * @return float + */ + public function getAspectRatio() + { + return $this->aspectRatio; + } + + /** + * @param mixed $filePath + * @return $this + */ + public function setFilePath($filePath) + { + $this->filePath = $filePath; + return $this; + } + + /** + * @return mixed + */ + public function getFilePath() + { + return $this->filePath; + } + + /** + * @param mixed $height + * @return $this + */ + public function setHeight($height) + { + $this->height = (int) $height; + return $this; + } + + /** + * @return integer + */ + public function getHeight() + { + return $this->height; + } + + /** + * @param mixed $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return mixed + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param float $voteAverage + * @return $this + */ + public function setVoteAverage($voteAverage) + { + $this->voteAverage = (float) $voteAverage; + return $this; + } + + /** + * @return float + */ + public function getVoteAverage() + { + return $this->voteAverage; + } + + /** + * @param int $voteCount + * @return $this + */ + public function setVoteCount($voteCount) + { + $this->voteCount = (int) $voteCount; + return $this; + } + + /** + * @return int + */ + public function getVoteCount() + { + return $this->voteCount; + } + + /** + * @param int $width + * @return $this + */ + public function setWidth($width) + { + $this->width = (int) $width; + return $this; + } + + /** + * @return int + */ + public function getWidth() + { + return $this->width; + } +} diff --git a/modules/Tmdb/Model/Image/BackdropImage.php b/modules/Tmdb/Model/Image/BackdropImage.php new file mode 100644 index 00000000..81f9c6bb --- /dev/null +++ b/modules/Tmdb/Model/Image/BackdropImage.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Image; + +use Tmdb\Model\Image; + +/** + * Class BackdropImage + * @package Tmdb\Model\Image + */ +class BackdropImage extends Image {} diff --git a/modules/Tmdb/Model/Image/LogoImage.php b/modules/Tmdb/Model/Image/LogoImage.php new file mode 100644 index 00000000..e2e82035 --- /dev/null +++ b/modules/Tmdb/Model/Image/LogoImage.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Image; + +use Tmdb\Model\Image; + +/** + * Class LogoImage + * @package Tmdb\Model\Image + */ +class LogoImage extends Image {} diff --git a/modules/Tmdb/Model/Image/PosterImage.php b/modules/Tmdb/Model/Image/PosterImage.php new file mode 100644 index 00000000..e0337de6 --- /dev/null +++ b/modules/Tmdb/Model/Image/PosterImage.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Image; + +use Tmdb\Model\Image; + +/** + * Class PosterImage + * @package Tmdb\Model\Image + */ +class PosterImage extends Image {} diff --git a/modules/Tmdb/Model/Image/ProfileImage.php b/modules/Tmdb/Model/Image/ProfileImage.php new file mode 100644 index 00000000..a62bbdcc --- /dev/null +++ b/modules/Tmdb/Model/Image/ProfileImage.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Image; + +use Tmdb\Model\Image; + +/** + * Class ProfileImage + * @package Tmdb\Model\Image + */ +class ProfileImage extends Image {} diff --git a/modules/Tmdb/Model/Image/StillImage.php b/modules/Tmdb/Model/Image/StillImage.php new file mode 100644 index 00000000..dff71b50 --- /dev/null +++ b/modules/Tmdb/Model/Image/StillImage.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Image; + +use Tmdb\Model\Image; + +/** + * Class StillImage + * @package Tmdb\Model\Image + */ +class StillImage extends Image {} diff --git a/modules/Tmdb/Model/Job.php b/modules/Tmdb/Model/Job.php new file mode 100644 index 00000000..c7876538 --- /dev/null +++ b/modules/Tmdb/Model/Job.php @@ -0,0 +1,69 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class Job + * @package Tmdb\Model + */ +class Job extends AbstractModel { + + public static $_properties = array( + 'department', + 'job_list' + ); + + /** + * @var string + */ + private $department; + + /** + * @var array + */ + private $jobList; + + /** + * @param string $department + * @return $this + */ + public function setDepartment($department) + { + $this->department = $department; + } + + /** + * @return string + */ + public function getDepartment() + { + return $this->department; + } + + /** + * @param array $jobList + * @return $this + */ + public function setJobList(array $jobList) + { + $this->jobList = $jobList; + } + + /** + * @return array + */ + public function getJobList() + { + return $this->jobList; + } +} diff --git a/modules/Tmdb/Model/Keyword.php b/modules/Tmdb/Model/Keyword.php new file mode 100644 index 00000000..7c2755f8 --- /dev/null +++ b/modules/Tmdb/Model/Keyword.php @@ -0,0 +1,64 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class Keyword + * @package Tmdb\Model + */ +class Keyword extends AbstractModel { + + private $id; + private $name; + + public static $_properties = array( + 'id', + 'name', + ); + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } +} diff --git a/modules/Tmdb/Model/Lists.php b/modules/Tmdb/Model/Lists.php new file mode 100644 index 00000000..722c31f3 --- /dev/null +++ b/modules/Tmdb/Model/Lists.php @@ -0,0 +1,269 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Image\PosterImage; + +/** + * Class Lists + * @package Tmdb\Model + */ +class Lists extends AbstractModel { + + /** + * @var string + */ + private $createdBy; + + /** + * @var string + */ + private $description; + + /** + * @var int + */ + private $favoriteCount; + + /** + * @var string + */ + private $id; + + /** + * @var GenericCollection + */ + private $items; + + /** + * @var int + */ + private $itemCount; + + /** + * @var string + */ + private $iso6391; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $posterPath; + + /** + * @var PosterImage + */ + private $posterImage; + + public static $_properties = array( + 'created_by', + 'description', + 'favorite_count', + 'id', + 'item_count', + 'iso_639_1', + 'name', + 'poster_path' + ); + + public function __construct() + { + $this->items = new GenericCollection(); + } + + /** + * @param string $createdBy + * @return $this + */ + public function setCreatedBy($createdBy) + { + $this->createdBy = $createdBy; + return $this; + } + + /** + * @return string + */ + public function getCreatedBy() + { + return $this->createdBy; + } + + /** + * @param string $description + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param int $favoriteCount + * @return $this + */ + public function setFavoriteCount($favoriteCount) + { + $this->favoriteCount = $favoriteCount; + return $this; + } + + /** + * @return int + */ + public function getFavoriteCount() + { + return $this->favoriteCount; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return string + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param int $itemCount + * @return $this + */ + public function setItemCount($itemCount) + { + $this->itemCount = $itemCount; + return $this; + } + + /** + * @return int + */ + public function getItemCount() + { + return $this->itemCount; + } + + /** + * @param \Tmdb\Model\Common\GenericCollection $items + * @return $this + */ + public function setItems($items) + { + $this->items = $items; + return $this; + } + + /** + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getItems() + { + return $this->items; + } + + /** + * @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\Image\PosterImage $posterImage + * @return $this + */ + public function setPosterImage($posterImage) + { + $this->posterImage = $posterImage; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->posterImage; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } +} diff --git a/modules/Tmdb/Model/Lists/ItemStatus.php b/modules/Tmdb/Model/Lists/ItemStatus.php new file mode 100644 index 00000000..44187e05 --- /dev/null +++ b/modules/Tmdb/Model/Lists/ItemStatus.php @@ -0,0 +1,75 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Lists; + +use Tmdb\Model\AbstractModel; + +/** + * Class ItemStatus + * @package Tmdb\Model\Lists + */ +class ItemStatus extends AbstractModel { + /** + * @var string + */ + private $id; + + /** + * @var boolean + */ + private $itemPresent; + + /** + * @var array + */ + public static $_properties = array( + 'id', + 'item_present' + ); + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param boolean $itemPresent + * @return $this + */ + public function setItemPresent($itemPresent) + { + $this->itemPresent = $itemPresent; + return $this; + } + + /** + * @return boolean + */ + public function getItemPresent() + { + return $this->itemPresent; + } +} diff --git a/modules/Tmdb/Model/Lists/ListItem.php b/modules/Tmdb/Model/Lists/ListItem.php new file mode 100644 index 00000000..fdc0a142 --- /dev/null +++ b/modules/Tmdb/Model/Lists/ListItem.php @@ -0,0 +1,267 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Lists; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image\BackdropImage; +use Tmdb\Model\Image\PosterImage; + +/** + * Class ListItem + * @package Tmdb\Model\Lists + */ +class ListItem extends AbstractModel { + /** + * @var string + */ + private $backdropPath; + + /** + * @var BackdropImage + */ + private $backdropImage; + + /** + * @var int + */ + private $id; + + /** + * @var string + */ + private $originalTitle; + + /** + * @var \DateTime + */ + private $releaseDate; + + /** + * @var string + */ + private $posterPath; + + /** + * @var PosterImage + */ + private $posterImage; + + /** + * @var string + */ + private $title; + + /** + * @var float + */ + private $voteAverage; + + /** + * @var int + */ + private $voteCount; + + /** + * @var array + */ + public static $_properties = array( + 'backdrop_path', + 'id', + 'original_title', + 'release_date', + 'poster_path', + 'title', + 'vote_average', + 'vote_count' + ); + + /** + * @param \Tmdb\Model\Image\BackdropImage $backdropImage + * @return $this + */ + public function setBackdropImage($backdropImage) + { + $this->backdropImage = $backdropImage; + return $this; + } + + /** + * @return \Tmdb\Model\Image\BackdropImage + */ + public function getBackdropImage() + { + return $this->backdropImage; + } + + /** + * @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 string $originalTitle + * @return $this + */ + public function setOriginalTitle($originalTitle) + { + $this->originalTitle = $originalTitle; + return $this; + } + + /** + * @return string + */ + public function getOriginalTitle() + { + return $this->originalTitle; + } + + /** + * @param \Tmdb\Model\Image\PosterImage $posterImage + * @return $this + */ + public function setPosterImage($posterImage) + { + $this->posterImage = $posterImage; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->posterImage; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } + + /** + * @param \DateTime $releaseDate + * @return $this + */ + public function setReleaseDate($releaseDate) + { + $this->releaseDate = $releaseDate; + return $this; + } + + /** + * @return \DateTime + */ + public function getReleaseDate() + { + return $this->releaseDate; + } + + /** + * @param string $title + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param float $voteAverage + * @return $this + */ + public function setVoteAverage($voteAverage) + { + $this->voteAverage = $voteAverage; + return $this; + } + + /** + * @return float + */ + public function getVoteAverage() + { + return $this->voteAverage; + } + + /** + * @param int $voteCount + * @return $this + */ + public function setVoteCount($voteCount) + { + $this->voteCount = $voteCount; + return $this; + } + + /** + * @return int + */ + public function getVoteCount() + { + return $this->voteCount; + } +} diff --git a/modules/Tmdb/Model/Lists/Result.php b/modules/Tmdb/Model/Lists/Result.php new file mode 100644 index 00000000..814ed7d5 --- /dev/null +++ b/modules/Tmdb/Model/Lists/Result.php @@ -0,0 +1,75 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Lists; + +use Tmdb\Model\AbstractModel; + +/** + * Class Result + * @package Tmdb\Model\Lists + */ +class Result extends AbstractModel { + /** + * @var int + */ + private $statusCode; + + /** + * @var string + */ + private $statusMessage; + + /** + * @var array + */ + public static $_properties = array( + 'status_code', + 'status_message' + ); + + /** + * @param int $statusCode + * @return $this + */ + public function setStatusCode($statusCode) + { + $this->statusCode = $statusCode; + return $this; + } + + /** + * @return int + */ + public function getStatusCode() + { + return $this->statusCode; + } + + /** + * @param string $statusMessage + * @return $this + */ + public function setStatusMessage($statusMessage) + { + $this->statusMessage = $statusMessage; + return $this; + } + + /** + * @return string + */ + public function getStatusMessage() + { + return $this->statusMessage; + } +} diff --git a/modules/Tmdb/Model/Lists/ResultWithListId.php b/modules/Tmdb/Model/Lists/ResultWithListId.php new file mode 100644 index 00000000..8048496c --- /dev/null +++ b/modules/Tmdb/Model/Lists/ResultWithListId.php @@ -0,0 +1,51 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Lists; + +/** + * Class ResultWithListId + * @package Tmdb\Model\Lists + */ +class ResultWithListId extends Result { + /** + * @var string + */ + private $listId; + + /** + * @var array + */ + public static $_properties = array( + 'status_code', + 'status_message', + 'list_id' + ); + + /** + * @param string $listId + * @return $this + */ + public function setListId($listId) + { + $this->listId = $listId; + return $this; + } + + /** + * @return string + */ + public function getListId() + { + return $this->listId; + } +} diff --git a/modules/Tmdb/Model/Movie.php b/modules/Tmdb/Model/Movie.php new file mode 100644 index 00000000..94622f4c --- /dev/null +++ b/modules/Tmdb/Model/Movie.php @@ -0,0 +1,919 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Collection\CreditsCollection; +use Tmdb\Model\Collection\Genres; +use Tmdb\Model\Collection\Images; +use Tmdb\Model\Collection\People; +use Tmdb\Model\Common\Country; +use Tmdb\Model\Common\SpokenLanguage; +use Tmdb\Model\Common\Translation; +use Tmdb\Model\Movie\AlternativeTitle; +use Tmdb\Model\Movie\Release; + +/** + * Class Movie + * @package Tmdb\Model + */ +class Movie extends AbstractModel { + /** + * @var bool + */ + private $adult = false; + + /** + * @var string + */ + private $backdropPath; + + /** + * @var Image + */ + private $backdrop; + + /** + * @var Collection + */ + private $belongsToCollection = null; + + /** + * @var int + */ + private $budget; + + /** + * @var Genres + */ + private $genres; + + /** + * @var string + */ + private $homepage; + + /** + * @var int + */ + private $id; + + /** + * @var string + */ + private $imdbId; + + /** + * @var string + */ + private $originalTitle; + + /** + * @var string + */ + private $overview; + + /** + * @var float + */ + private $popularity; + + /** + * @var Image + */ + private $poster; + + /** + * @var string + */ + private $posterPath; + + /** + * @var Collection + */ + private $productionCompanies; + + /** + * @var Collection + */ + private $productionCountries; + + /** + * @var \DateTime + */ + private $releaseDate; + + /** + * @var int + */ + private $revenue; + + /** + * @var int + */ + private $runtime; + + /** + * @var Collection + */ + private $spokenLanguages; + + /** + * @var string + */ + private $status; + + /** + * @var string + */ + private $tagline; + + /** + * @var string + */ + private $title; + + /** + * @var float + */ + private $voteAverage; + + /** + * @var int + */ + private $voteCount; + + /** + * @var Collection + */ + protected $alternativeTitles; + + /** + * @var Collection + */ + protected $changes; + + /** + * Credits + * + * @var Credits + */ + protected $credits; + + /** + * Images + * + * @var Images + */ + protected $images; + + /** + * @var Collection + */ + protected $keywords; + + /** + * @var Collection + */ + protected $lists; + + /** + * @var Collection + */ + protected $releases; + + /** + * @var Collection + */ + protected $similarMovies; + + /** + * @var Collection + */ + protected $trailers; + + /** + * @var Collection + */ + protected $translations; + + /** + * @var ResultCollection + */ + protected $reviews; + + /** + * Properties that are available in the API + * + * These properties are hydrated by the ObjectHydrator, all the other properties are handled by the factory. + * + * @var array + */ + public static $_properties = array( + 'adult', + 'backdrop_path', + 'belongs_to_collection', + 'budget', + 'homepage', + 'id', + 'imdb_id', + 'original_title', + 'overview', + 'popularity', + 'poster_path', + 'release_date', + 'revenue', + 'runtime', + 'status', + 'tagline', + 'title', + 'vote_average', + 'vote_count', + ); + + /** + * Constructor + * + * Set all default collections + */ + public function __construct() + { + $this->genres = new Genres(); + $this->productionCompanies = new GenericCollection(); + $this->productionCountries = new GenericCollection(); + $this->spokenLanguages = new GenericCollection(); + $this->alternativeTitles = new GenericCollection(); + $this->changes = new GenericCollection(); + $this->credits = new CreditsCollection(); + $this->images = new Images(); + $this->keywords = new GenericCollection(); + $this->lists = new GenericCollection(); + $this->releases = new GenericCollection(); + $this->similarMovies = new GenericCollection(); + $this->trailers = new GenericCollection(); + $this->translations = new GenericCollection(); + } + + /** + * @param boolean $adult + * @return $this + */ + public function setAdult($adult) + { + $this->adult = (bool) $adult; + return $this; + } + + /** + * @return boolean + */ + public function getAdult() + { + return $this->adult; + } + + /** + * @param mixed $backdropPath + * @return $this + */ + public function setBackdropPath($backdropPath) + { + $this->backdropPath = $backdropPath; + return $this; + } + + /** + * @return mixed + */ + public function getBackdropPath() + { + return $this->backdropPath; + } + + /** + * @param null $belongsToCollection + * @return $this + */ + public function setBelongsToCollection($belongsToCollection) + { + $this->belongsToCollection = $belongsToCollection; + return $this; + } + + /** + * @return Collection|null + */ + public function getBelongsToCollection() + { + return $this->belongsToCollection; + } + + /** + * @param GenericCollection $changes + * @return $this + */ + public function setChanges(GenericCollection $changes) + { + $this->changes = $changes; + return $this; + } + + /** + * @return mixed + */ + public function getChanges() + { + return $this->changes; + } + + /** + * @param Genres $genres + * @return $this + */ + public function setGenres(Genres $genres) + { + $this->genres = $genres; + return $this; + } + + /** + * @return Genre[] + */ + public function getGenres() + { + return $this->genres; + } + + /** + * @param mixed $homepage + * @return $this + */ + public function setHomepage($homepage) + { + $this->homepage = $homepage; + return $this; + } + + /** + * @return mixed + */ + public function getHomepage() + { + return $this->homepage; + } + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param Images $images + * @return $this + */ + public function setImages(Images $images) + { + $this->images = $images; + return $this; + } + + /** + * @return Images Image[] + */ + public function getImages() + { + return $this->images; + } + + /** + * @param mixed $imdbId + * @return $this + */ + public function setImdbId($imdbId) + { + $this->imdbId = $imdbId; + return $this; + } + + /** + * @return mixed + */ + public function getImdbId() + { + return $this->imdbId; + } + + /** + * @param mixed $originalTitle + * @return $this + */ + public function setOriginalTitle($originalTitle) + { + $this->originalTitle = $originalTitle; + return $this; + } + + /** + * @return mixed + */ + public function getOriginalTitle() + { + return $this->originalTitle; + } + + /** + * @param mixed $overview + * @return $this + */ + public function setOverview($overview) + { + $this->overview = $overview; + return $this; + } + + /** + * @return mixed + */ + public function getOverview() + { + return $this->overview; + } + + /** + * @param mixed $popularity + * @return $this + */ + public function setPopularity($popularity) + { + $this->popularity = (float) $popularity; + return $this; + } + + /** + * @return double + */ + public function getPopularity() + { + return $this->popularity; + } + + /** + * @param mixed $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return mixed + */ + public function getPosterPath() + { + return $this->posterPath; + } + + /** + * @param GenericCollection $productionCompanies + * @return $this + */ + public function setProductionCompanies(GenericCollection $productionCompanies) + { + $this->productionCompanies = $productionCompanies; + return $this; + } + + /** + * @return Company[] + */ + public function getProductionCompanies() + { + return $this->productionCompanies; + } + + /** + * @param GenericCollection $productionCountries + * @return $this + */ + public function setProductionCountries(GenericCollection $productionCountries) + { + $this->productionCountries = $productionCountries; + return $this; + } + + /** + * @return Country + */ + public function getProductionCountries() + { + return $this->productionCountries; + } + + /** + * @param string $releaseDate + * @return $this + */ + public function setReleaseDate($releaseDate) + { + if (!$releaseDate instanceof \DateTime) { + $releaseDate = new \DateTime($releaseDate); + } + + $this->releaseDate = $releaseDate; + return $this; + } + + /** + * @return \DateTime + */ + public function getReleaseDate() + { + return $this->releaseDate; + } + + /** + * @param mixed $revenue + * @return $this + */ + public function setRevenue($revenue) + { + $this->revenue = (int) $revenue; + return $this; + } + + /** + * @return integer + */ + public function getRevenue() + { + return $this->revenue; + } + + /** + * @param mixed $runtime + * @return $this + */ + public function setRuntime($runtime) + { + $this->runtime = (int) $runtime; + return $this; + } + + /** + * @return integer + */ + public function getRuntime() + { + return $this->runtime; + } + + /** + * @param GenericCollection $spokenLanguages + * @return $this + */ + public function setSpokenLanguages(GenericCollection $spokenLanguages) + { + $this->spokenLanguages = $spokenLanguages; + return $this; + } + + /** + * @return SpokenLanguage[] + */ + public function getSpokenLanguages() + { + return $this->spokenLanguages; + } + + /** + * @param mixed $status + * @return $this + */ + public function setStatus($status) + { + $this->status = $status; + return $this; + } + + /** + * @return mixed + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param mixed $tagline + * @return $this + */ + public function setTagline($tagline) + { + $this->tagline = $tagline; + return $this; + } + + /** + * @return mixed + */ + public function getTagline() + { + return $this->tagline; + } + + /** + * @param mixed $title + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + /** + * @return mixed + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param mixed $voteAverage + * @return $this + */ + public function setVoteAverage($voteAverage) + { + $this->voteAverage = (float) $voteAverage; + return $this; + } + + /** + * @return double + */ + public function getVoteAverage() + { + return $this->voteAverage; + } + + /** + * @param mixed $voteCount + * @return $this + */ + public function setVoteCount($voteCount) + { + $this->voteCount = (int) $voteCount; + return $this; + } + + /** + * @return integer + */ + public function getVoteCount() + { + return $this->voteCount; + } + + /** + * @param GenericCollection $alternativeTitles + * @return $this + */ + public function setAlternativeTitles($alternativeTitles) + { + $this->alternativeTitles = $alternativeTitles; + return $this; + } + + /** + * @return GenericCollection|AlternativeTitle[] + */ + public function getAlternativeTitles() + { + return $this->alternativeTitles; + } + + /** + * @param int $budget + * @return $this + */ + public function setBudget($budget) + { + $this->budget = $budget; + return $this; + } + + /** + * @return int + */ + public function getBudget() + { + return $this->budget; + } + + /** + * @param CreditsCollection $credits + * @return $this + */ + public function setCredits(CreditsCollection $credits) + { + $this->credits = $credits; + return $this; + } + + /** + * @return CreditsCollection + */ + public function getCredits() + { + return $this->credits; + } + + /** + * @param GenericCollection $keywords + * @return $this + */ + public function setKeywords($keywords) + { + $this->keywords = $keywords; + return $this; + } + + /** + * @return Keyword[] + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * @param GenericCollection $lists + * @return $this + */ + public function setLists($lists) + { + $this->lists = $lists; + return $this; + } + + /** + * @return GenericCollection + */ + public function getLists() + { + return $this->lists; + } + + /** + * @param GenericCollection $releases + * @return $this + */ + public function setReleases(GenericCollection $releases) + { + $this->releases = $releases; + return $this; + } + + /** + * @return Release[] + */ + public function getReleases() + { + return $this->releases; + } + + /** + * @param GenericCollection $similarMovies + * @return $this + */ + public function setSimilarMovies($similarMovies) + { + $this->similarMovies = $similarMovies; + return $this; + } + + /** + * @return Movie[] + */ + public function getSimilarMovies() + { + return $this->similarMovies; + } + + /** + * @param GenericCollection $trailers + * @return $this + */ + public function setTrailers($trailers) + { + $this->trailers = $trailers; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Trailer\Youtube[] + */ + public function getTrailers() + { + return $this->trailers; + } + + /** + * @param GenericCollection $translations + * @return $this + */ + public function setTranslations($translations) + { + $this->translations = $translations; + return $this; + } + + /** + * @return Translation[] + */ + public function getTranslations() + { + return $this->translations; + } + + /** + * @param \Tmdb\Model\Image $backdrop + * @return $this + */ + public function setBackdropImage($backdrop) + { + $this->backdrop = $backdrop; + return $this; + } + + /** + * @return \Tmdb\Model\Image + */ + public function getBackdropImage() + { + return $this->backdrop; + } + + /** + * @param \Tmdb\Model\Image $poster + * @return $this + */ + public function setPosterImage($poster) + { + $this->poster = $poster; + return $this; + } + + /** + * @return \Tmdb\Model\Image + */ + public function getPosterImage() + { + return $this->poster; + } + + /** + * @param \Tmdb\Model\Collection\ResultCollection $reviews + * @return $this + */ + public function setReviews($reviews) + { + $this->reviews = $reviews; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\ResultCollection + */ + public function getReviews() + { + return $this->reviews; + } +} diff --git a/modules/Tmdb/Model/Movie/AccountStates.php b/modules/Tmdb/Model/Movie/AccountStates.php new file mode 100644 index 00000000..062011b2 --- /dev/null +++ b/modules/Tmdb/Model/Movie/AccountStates.php @@ -0,0 +1,120 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; + +/** + * Class AccountStates + * @package Tmdb\Model\Movie + */ +class AccountStates extends AbstractModel { + + /** + * @var integer + */ + private $id; + + /** + * @var boolean + */ + private $favorite; + + /** + * @var Rating + */ + private $rated; + + /** + * @var boolean + */ + private $watchlist; + + public static $_properties = array( + 'id', + 'favorite', + 'watchlist', + ); + + /** + * @param boolean $favorite + * @return $this + */ + public function setFavorite($favorite) + { + $this->favorite = $favorite; + return $this; + } + + /** + * @return boolean + */ + public function getFavorite() + { + return $this->favorite; + } + + /** + * @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\Movie\Rating $rated + * @return $this + */ + public function setRated($rated) + { + $this->rated = $rated; + return $this; + } + + /** + * @return \Tmdb\Model\Movie\Rating + */ + public function getRated() + { + return $this->rated; + } + + /** + * @param boolean $watchlist + * @return $this + */ + public function setWatchlist($watchlist) + { + $this->watchlist = $watchlist; + return $this; + } + + /** + * @return boolean + */ + public function getWatchlist() + { + return $this->watchlist; + } +} diff --git a/modules/Tmdb/Model/Movie/AlternativeTitle.php b/modules/Tmdb/Model/Movie/AlternativeTitle.php new file mode 100644 index 00000000..d8b388df --- /dev/null +++ b/modules/Tmdb/Model/Movie/AlternativeTitle.php @@ -0,0 +1,67 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Filter\CountryFilter; + +/** + * Class AlternativeTitle + * @package Tmdb\Model\Movie + */ +class AlternativeTitle extends AbstractModel implements CountryFilter { + + private $iso31661; + private $title; + + public static $_properties = array( + 'iso_3166_1', + 'title', + ); + + /** + * @param string $iso31661 + * @return $this + */ + public function setIso31661($iso31661) + { + $this->iso31661 = $iso31661; + return $this; + } + + /** + * @return string + */ + public function getIso31661() + { + return $this->iso31661; + } + + /** + * @param string $title + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } +} diff --git a/modules/Tmdb/Model/Movie/ListItem.php b/modules/Tmdb/Model/Movie/ListItem.php new file mode 100644 index 00000000..1eda953b --- /dev/null +++ b/modules/Tmdb/Model/Movie/ListItem.php @@ -0,0 +1,219 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image\PosterImage; + +/** + * Class ListItem + * @package Tmdb\Model\Movie + */ +class ListItem extends AbstractModel { + + /** + * @var string + */ + private $description; + + /** + * @var int + */ + private $favoriteCount; + + /** + * @var string + */ + private $id; + + /** + * @var int + */ + private $itemCount; + + /** + * @var string + */ + private $iso6391; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $posterPath; + + /** + * @var PosterImage + */ + private $posterImage; + + public static $_properties = array( + 'description', + 'favorite_count', + 'id', + 'item_count', + 'iso_639_1', + 'name', + 'poster_path' + ); + + /** + * @param string $description + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param int $favoriteCount + * @return $this + */ + public function setFavoriteCount($favoriteCount) + { + $this->favoriteCount = $favoriteCount; + return $this; + } + + /** + * @return int + */ + public function getFavoriteCount() + { + return $this->favoriteCount; + } + + /** + * @param string $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return string + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param int $itemCount + * @return $this + */ + public function setItemCount($itemCount) + { + $this->itemCount = $itemCount; + return $this; + } + + /** + * @return int + */ + public function getItemCount() + { + return $this->itemCount; + } + + /** + * @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\Image\PosterImage $posterImage + * @return $this + */ + public function setPosterImage($posterImage) + { + $this->posterImage = $posterImage; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->posterImage; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } + + +} diff --git a/modules/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php b/modules/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php new file mode 100644 index 00000000..532af7cc --- /dev/null +++ b/modules/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php @@ -0,0 +1,33 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie\QueryParameter; + +use Tmdb\Model\Common\QueryParameter\AppendToResponse as BaseAppendToResponse; + +/** + * Class AppendToResponse + * @package Tmdb\Model\Movie\QueryParameter + */ +final class AppendToResponse extends BaseAppendToResponse { + const ALTERNATIVE_TITLES = 'alternative_titles'; + const CREDITS = 'credits'; + const IMAGES = 'images'; + const KEYWORDS = 'keywords'; + const RELEASES = 'releases'; + const TRAILERS = 'trailers'; + const TRANSLATIONS = 'translations'; + const SIMILAR_MOVIES = 'similar_movies'; + const REVIEWS = 'reviews'; + const LISTS = 'lists'; + const CHANGES = 'changes'; +} diff --git a/modules/Tmdb/Model/Movie/Rating.php b/modules/Tmdb/Model/Movie/Rating.php new file mode 100644 index 00000000..a9d11b9e --- /dev/null +++ b/modules/Tmdb/Model/Movie/Rating.php @@ -0,0 +1,49 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; + +/** + * Class Rating + * @package Tmdb\Model\Movie + */ +class Rating extends AbstractModel { + + /** + * @var float + */ + private $value; + + public static $_properties = array( + 'value', + ); + + /** + * @param float $value + * @return $this + */ + public function setValue($value) + { + $this->value = $value; + return $this; + } + + /** + * @return float + */ + public function getValue() + { + return $this->value; + } +} diff --git a/modules/Tmdb/Model/Movie/Release.php b/modules/Tmdb/Model/Movie/Release.php new file mode 100644 index 00000000..2b739301 --- /dev/null +++ b/modules/Tmdb/Model/Movie/Release.php @@ -0,0 +1,91 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Filter\CountryFilter; + +/** + * Class Release + * @package Tmdb\Model\Movie + */ +class Release extends AbstractModel implements CountryFilter { + + private $iso31661; + private $certification; + private $releaseDate; + + public static $_properties = array( + 'iso_3166_1', + 'certification', + 'release_date' + ); + + /** + * @param mixed $certification + * @return $this + */ + public function setCertification($certification) + { + $this->certification = $certification; + return $this; + } + + /** + * @return mixed + */ + public function getCertification() + { + return $this->certification; + } + + /** + * @param string $iso31661 + * @return $this + */ + public function setIso31661($iso31661) + { + $this->iso31661 = $iso31661; + return $this; + } + + /** + * @return string + */ + public function getIso31661() + { + return $this->iso31661; + } + + /** + * @param string|\DateTime $releaseDate + * @return $this + */ + public function setReleaseDate($releaseDate) + { + if (!$releaseDate instanceof \DateTime) { + $releaseDate = new \DateTime($releaseDate); + } + + $this->releaseDate = $releaseDate; + return $this; + } + + /** + * @return \DateTime + */ + public function getReleaseDate() + { + return $this->releaseDate; + } +} diff --git a/modules/Tmdb/Model/Network.php b/modules/Tmdb/Model/Network.php new file mode 100644 index 00000000..db2f1d1e --- /dev/null +++ b/modules/Tmdb/Model/Network.php @@ -0,0 +1,64 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class Network + * @package Tmdb\Model + */ +class Network extends AbstractModel { + + private $id; + private $name; + + public static $_properties = array( + 'id', + 'name', + ); + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } +} diff --git a/modules/Tmdb/Model/Person.php b/modules/Tmdb/Model/Person.php new file mode 100644 index 00000000..ced88646 --- /dev/null +++ b/modules/Tmdb/Model/Person.php @@ -0,0 +1,484 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Collection\CreditsCollection; +use Tmdb\Model\Common\ExternalIds; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Collection\Images; +use Tmdb\Model\Collection\People\PersonInterface; +use Tmdb\Model\Image\ProfileImage; + +/** + * Class Person + * @package Tmdb\Model + */ +class Person extends AbstractModel implements PersonInterface { + + /** + * @var bool + */ + private $adult; + + /** + * @var array + */ + private $alsoKnownAs = array(); + + /** + * @var string + */ + private $biography; + /** + * @var \DateTime + */ + private $birthday; + + /** + * @var \DateTime|boolean + */ + private $deathday; + + /** + * @var string + */ + private $homepage; + + /** + * @var integer + */ + private $id; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $placeOfBirth; + + /** + * @var string + */ + private $profilePath; + + /** + * @var ProfileImage + */ + private $profileImage; + + /** + * @var Collection\CreditsCollection + * @deprecated + */ + protected $credits; + + /** + * @var CreditsCollection\MovieCredits + */ + protected $movieCredits; + + /** + * @var CreditsCollection\TvCredits + */ + protected $tvCredits; + + /** + * @var CreditsCollection\CombinedCredits + */ + protected $combinedCredits; + + /** + * @var Collection\Images + */ + protected $images; + + /** + * @var Common\GenericCollection + */ + protected $changes; + + /** + * External Ids + * + * @var ExternalIds + */ + protected $externalIds; + + public static $_properties = array( + 'adult', + 'also_known_as', + 'biography', + 'birthday', + 'deathday', + 'homepage', + 'id', + 'name', + 'place_of_birth', + 'profile_path', + ); + + /** + * Constructor + * + * Set all default collections + */ + public function __construct() + { + $this->credits = new CreditsCollection(); + $this->movieCredits = new CreditsCollection\MovieCredits(); + $this->tvCredits = new CreditsCollection\TvCredits(); + $this->combinedCredits = new CreditsCollection\CombinedCredits(); + $this->images = new Images(); + $this->changes = new GenericCollection(); + $this->externalIds = new ExternalIds(); + } + + /** + * @param mixed $adult + * @return $this + */ + public function setAdult($adult) + { + $this->adult = $adult; + return $this; + } + + /** + * @return mixed + */ + public function getAdult() + { + return $this->adult; + } + + /** + * @param mixed $alsoKnownAs + * @return $this + */ + public function setAlsoKnownAs($alsoKnownAs) + { + $this->alsoKnownAs = $alsoKnownAs; + return $this; + } + + /** + * @return mixed + */ + public function getAlsoKnownAs() + { + return $this->alsoKnownAs; + } + + /** + * @param mixed $biography + * @return $this + */ + public function setBiography($biography) + { + $this->biography = $biography; + return $this; + } + + /** + * @return mixed + */ + public function getBiography() + { + return $this->biography; + } + + /** + * @param mixed $birthday + * @return $this + */ + public function setBirthday($birthday) + { + if (!$birthday instanceof \DateTime) { + $birthday = new \DateTime($birthday); + } + + $this->birthday = $birthday; + return $this; + } + + /** + * @return mixed + */ + public function getBirthday() + { + return $this->birthday; + } + + /** + * @param mixed $changes + * @return $this + */ + public function setChanges($changes) + { + $this->changes = $changes; + return $this; + } + + /** + * @return mixed + */ + public function getChanges() + { + return $this->changes; + } + + /** + * @param mixed $credits + * @return $this + */ + public function setCredits($credits) + { + $this->credits = $credits; + return $this; + } + + /** + * @return mixed + */ + public function getCredits() + { + return $this->credits; + } + + /** + * @param mixed $deathday + * @return $this + */ + public function setDeathday($deathday) + { + if (!$deathday instanceof \DateTime && !empty($deathday)) { + $deathday = new \DateTime($deathday); + } + + if (empty($deathday)) { + $deathday = false; + } + + $this->deathday = $deathday; + return $this; + } + + /** + * @return mixed + */ + public function getDeathday() + { + return $this->deathday; + } + + /** + * @param mixed $homepage + * @return $this + */ + public function setHomepage($homepage) + { + $this->homepage = $homepage; + return $this; + } + + /** + * @return mixed + */ + public function getHomepage() + { + return $this->homepage; + } + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param Images $images + * @return $this + */ + public function setImages($images) + { + $this->images = $images; + return $this; + } + + /** + * @return Images + */ + public function getImages() + { + return $this->images; + } + + /** + * @param mixed $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @param mixed $placeOfBirth + * @return $this + */ + public function setPlaceOfBirth($placeOfBirth) + { + $this->placeOfBirth = $placeOfBirth; + return $this; + } + + /** + * @return mixed + */ + public function getPlaceOfBirth() + { + return $this->placeOfBirth; + } + + /** + * @param mixed $profilePath + * @return $this + */ + public function setProfilePath($profilePath) + { + $this->profilePath = $profilePath; + return $this; + } + + /** + * @return mixed + */ + public function getProfilePath() + { + return $this->profilePath; + } + + /** + * @param ProfileImage $profileImage + * @return $this + */ + public function setProfileImage(ProfileImage $profileImage) + { + $this->profileImage = $profileImage; + return $this; + } + + /** + * @return ProfileImage + */ + public function getProfileImage() + { + return $this->profileImage; + } + + /** + * @param \Tmdb\Model\Collection\CreditsCollection\CombinedCredits $combinedCredits + * @return $this + */ + public function setCombinedCredits($combinedCredits) + { + $this->combinedCredits = $combinedCredits; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\CreditsCollection\CombinedCredits + */ + public function getCombinedCredits() + { + return $this->combinedCredits; + } + + /** + * @param \Tmdb\Model\Collection\CreditsCollection\MovieCredits $movieCredits + * @return $this + */ + public function setMovieCredits($movieCredits) + { + $this->movieCredits = $movieCredits; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\CreditsCollection\MovieCredits + */ + public function getMovieCredits() + { + return $this->movieCredits; + } + + /** + * @param \Tmdb\Model\Collection\CreditsCollection\TvCredits $tvCredits + * @return $this + */ + public function setTvCredits($tvCredits) + { + $this->tvCredits = $tvCredits; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\CreditsCollection\TvCredits + */ + public function getTvCredits() + { + return $this->tvCredits; + } + + /** + * @param \Tmdb\Model\Common\ExternalIds $externalIds + * @return $this + */ + public function setExternalIds($externalIds) + { + $this->externalIds = $externalIds; + return $this; + } + + /** + * @return \Tmdb\Model\Common\ExternalIds + */ + public function getExternalIds() + { + return $this->externalIds; + } +} diff --git a/modules/Tmdb/Model/Person/AbstractMember.php b/modules/Tmdb/Model/Person/AbstractMember.php new file mode 100644 index 00000000..283c2af5 --- /dev/null +++ b/modules/Tmdb/Model/Person/AbstractMember.php @@ -0,0 +1,131 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Person; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image; + +/** + * Class AbstractMember + * @package Tmdb\Model\Person + */ +abstract class AbstractMember extends AbstractModel { + + /** + * @var int + */ + private $id; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $profilePath; + + /** + * @var Image\ProfileImage + */ + private $profile; + + public static $_properties = array( + 'id', + 'name', + 'profile_path' + ); + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @param mixed $profilePath + * @return $this + */ + public function setProfilePath($profilePath) + { + $this->profilePath = $profilePath; + return $this; + } + + /** + * @return mixed + */ + public function getProfilePath() + { + return $this->profilePath; + } + + /** + * @param Image\ProfileImage $profile + * @return $this + */ + public function setProfileImage($profile = null) + { + $this->profile = $profile; + return $this; + } + + /** + * @return Image\ProfileImage|null + */ + public function getProfileImage() + { + return $this->profile; + } + + /** + * Assert if there is an profile image object + * + * @return bool + */ + public function hasProfileImage() + { + return $this->profile instanceof Image; + } +} diff --git a/modules/Tmdb/Model/Person/CastMember.php b/modules/Tmdb/Model/Person/CastMember.php new file mode 100644 index 00000000..bbf47e10 --- /dev/null +++ b/modules/Tmdb/Model/Person/CastMember.php @@ -0,0 +1,100 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Person; + +use Tmdb\Model\Collection\People\PersonInterface; + +/** + * Class CastMember + * @package Tmdb\Model\Person + */ +class CastMember extends AbstractMember implements PersonInterface { + + /** + * @var string + */ + private $character; + + /** + * @var int + */ + private $order; + + /** + * @var mixed + */ + private $castId; + + public static $_properties = array( + 'id', + 'cast_id', + 'name', + 'character', + 'order', + 'profile_path' + ); + + /** + * @param mixed $character + * @return $this + */ + public function setCharacter($character) + { + $this->character = $character; + return $this; + } + + /** + * @return mixed + */ + public function getCharacter() + { + return $this->character; + } + + /** + * @param int $order + * @return $this + */ + public function setOrder($order) + { + $this->order = (int) $order; + return $this; + } + + /** + * @return int + */ + public function getOrder() + { + return $this->order; + } + + /** + * @param mixed $castId + * @return $this + */ + public function setCastId($castId) + { + $this->castId = (int) $castId; + return $this; + } + + /** + * @return int + */ + public function getCastId() + { + return $this->castId; + } +} diff --git a/modules/Tmdb/Model/Person/CrewMember.php b/modules/Tmdb/Model/Person/CrewMember.php new file mode 100644 index 00000000..83b395a4 --- /dev/null +++ b/modules/Tmdb/Model/Person/CrewMember.php @@ -0,0 +1,76 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Person; + +use Tmdb\Model\Collection\People\PersonInterface; + +/** + * Class CrewMember + * @package Tmdb\Model\Person + */ +class CrewMember extends AbstractMember implements PersonInterface { + + /** + * @var string + */ + private $department; + + /** + * @var string + */ + private $job; + + public static $_properties = array( + 'id', + 'name', + 'department', + 'job', + 'profile_path' + ); + + /** + * @param mixed $department + * @return $this + */ + public function setDepartment($department) + { + $this->department = $department; + return $this; + } + + /** + * @return mixed + */ + public function getDepartment() + { + return $this->department; + } + + /** + * @param mixed $job + * @return $this + */ + public function setJob($job) + { + $this->job = $job; + return $this; + } + + /** + * @return mixed + */ + public function getJob() + { + return $this->job; + } +} diff --git a/modules/Tmdb/Model/Person/MovieCredit.php b/modules/Tmdb/Model/Person/MovieCredit.php new file mode 100644 index 00000000..afb232ea --- /dev/null +++ b/modules/Tmdb/Model/Person/MovieCredit.php @@ -0,0 +1,247 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Person; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image\PosterImage; + +/** + * Class MovieCredit + * @package Tmdb\Model\Person + */ +class MovieCredit extends AbstractModel { + + /** + * @var bool + */ + private $adult; + + /** + * @var string + */ + private $character; + + /** + * @var string + */ + private $creditId; + + /** + * @var int + */ + private $id; + + /** + * @var string + */ + private $originalTitle; + + /** + * @var string + */ + private $posterPath; + + /** + * @var \DateTime + */ + private $releaseDate; + + /** + * @var string + */ + private $title; + + /** + * @var PosterImage + */ + private $posterImage; + + public static $_properties = array( + 'adult', + 'character', + 'credit_id', + 'id', + 'original_title', + 'poster_path', + 'release_date', + 'title' + ); + + /** + * @param boolean $adult + * @return $this + */ + public function setAdult($adult) + { + $this->adult = $adult; + return $this; + } + + /** + * @return boolean + */ + public function getAdult() + { + return $this->adult; + } + + /** + * @param string $character + * @return $this + */ + public function setCharacter($character) + { + $this->character = $character; + return $this; + } + + /** + * @return string + */ + public function getCharacter() + { + return $this->character; + } + + /** + * @param string $creditId + * @return $this + */ + public function setCreditId($creditId) + { + $this->creditId = $creditId; + return $this; + } + + /** + * @return string + */ + public function getCreditId() + { + return $this->creditId; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $originalTitle + * @return $this + */ + public function setOriginalTitle($originalTitle) + { + $this->originalTitle = $originalTitle; + return $this; + } + + /** + * @return string + */ + public function getOriginalTitle() + { + return $this->originalTitle; + } + + /** + * @param \Tmdb\Model\Image\PosterImage $posterImage + * @return $this + */ + public function setPosterImage($posterImage) + { + $this->posterImage = $posterImage; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->posterImage; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } + + /** + * @param \DateTime $releaseDate + * @return $this + */ + public function setReleaseDate($releaseDate) + { + if (!$releaseDate instanceof \DateTime) { + $releaseDate = new \DateTime($releaseDate); + } + + $this->releaseDate = $releaseDate; + return $this; + } + + /** + * @return \DateTime + */ + public function getReleaseDate() + { + return $this->releaseDate; + } + + /** + * @param string $title + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + +} diff --git a/modules/Tmdb/Model/Person/QueryParameter/AppendToResponse.php b/modules/Tmdb/Model/Person/QueryParameter/AppendToResponse.php new file mode 100644 index 00000000..8d851d26 --- /dev/null +++ b/modules/Tmdb/Model/Person/QueryParameter/AppendToResponse.php @@ -0,0 +1,28 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Person\QueryParameter; + +use Tmdb\Model\Common\QueryParameter\AppendToResponse as BaseAppendToResponse; + +/** + * Class AppendToResponse + * @package Tmdb\Model\Person\QueryParameter + */ +final class AppendToResponse extends BaseAppendToResponse { + const MOVIE_CREDITS = 'movie_credits'; + const TV_CREDITS = 'tv_credits'; + const COMBINED_CREDITS = 'combined_credits'; + const IMAGES = 'images'; + const CHANGES = 'changes'; + const EXTERNAL_IDS = 'external_ids'; +} diff --git a/modules/Tmdb/Model/Query/ChangesQuery.php b/modules/Tmdb/Model/Query/ChangesQuery.php new file mode 100644 index 00000000..513593e9 --- /dev/null +++ b/modules/Tmdb/Model/Query/ChangesQuery.php @@ -0,0 +1,60 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Query; + +use Tmdb\Model\Collection\QueryParametersCollection; + +/** + * Class ChangesQuery + * @package Tmdb\Model\Query + */ +class ChangesQuery extends QueryParametersCollection { + + /** + * Set the from parameter + * + * @param \DateTime $date + * @return $this + */ + public function from(\DateTime $date) + { + $this->set('from', $date->format('Y-m-d')); + + return $this; + } + + /** + * Set the to parameter + * + * @param \DateTime $date + * @return $this + */ + public function to(\DateTime $date) + { + $this->set('to', $date->format('Y-m-d')); + + return $this; + } + + /** + * Set the page parameter + * + * @param int $page + * @return $this + */ + public function page($page = 1) { + $this->set('page', (int) $page); + + return $this; + } +} diff --git a/modules/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php b/modules/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php new file mode 100644 index 00000000..68b3b6eb --- /dev/null +++ b/modules/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php @@ -0,0 +1,278 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Query\Discover; + +use Tmdb\Model\Collection\QueryParametersCollection; + +/** + * Class DiscoverMoviesQuery + * @package Tmdb\Model\Query\Discover + */ +class DiscoverMoviesQuery extends QueryParametersCollection { + /** + * Minimum value is 1, expected value is an integer. + * + * @param integer $page + * @return $this + */ + public function page($page = 1) + { + $this->set('page', (int) $page); + + return $this; + } + + /** + * ISO 639-1 code. + * + * @param string $language + * @return $this + */ + public function language($language) + { + $this->set('language', $language); + + return $this; + } + + /** + * Available options are vote_average.desc, vote_average.asc, release_date.desc, release_date.asc, popularity.desc, popularity.asc + * + * @param string $option + * @return $this + */ + public function sortBy($option) + { + $this->set('sort_by', $option); + + return $this; + } + + /** + * Toggle the inclusion of adult titles. Expected value is a boolean, true or false + * + * @param boolean $allow + * @return $this + */ + public function includeAdult($allow = true) + { + $this->set('include_adult', (bool) $allow); + + return $this; + } + + /** + * Filter the results release dates to matches that include this value. Expected value is a year. + * + * @param \DateTime|integer $year + * @return $this + */ + public function year($year) + { + if ($year instanceof \DateTime) { + $year = $year->format('Y'); + } + + $this->set('year', (int) $year); + + return $this; + } + + /** + * Filter the results so that only the primary release date year has this value. Expected value is a year. + * + * @param \DateTime|integer $year + * @return $this + */ + public function primaryReleaseYear($year) + { + if ($year instanceof \DateTime) { + $year = $year->format('Y'); + } + + $this->set('primary_release_year', (int) $year); + + return $this; + } + + /** + * Only include movies that are equal to, or have a vote count higher than this value. Expected value is an integer. + * + * @param integer $count + * @return $this + */ + public function voteCountGte($count) + { + $this->set('vote_count.gte', (int) $count); + + return $this; + } + + /** + * Only include movies that are equal to, or have a higher average rating than this value. Expected value is a float. + * + * @param float $average + * @return $this + */ + public function voteAverageGte($average) + { + $this->set('vote_average.gte', (float) $average); + + return $this; + } + + /** + * Only include movies with the specified genres. Expected value is an integer (the id of a genre). + * Multiple values can be specified. + * + * Comma separated indicates an 'AND' query, while a pipe (|) separated value indicates an 'OR'. + * + * If an array is supplied this defaults to an AND query + * + * @param array|string $genres + * @return $this + */ + public function withGenres($genres) + { + if (is_array($genres)) { + $genres = $this->withGenresAnd($genres); + } + + $this->set('with_genres', $genres); + + return $this; + } + + /** + * Creates an or query for genres + * + * @param array $genres + * @return $this + */ + public function withGenresOr(array $genres = array()) + { + return $this->withGenres( + implode('|', $genres) + ); + } + + /** + * Creates an and query for genres + * + * @param array $genres + * @return $this + */ + public function withGenresAnd(array $genres = array()) + { + return $this->withGenres( + implode(',', $genres) + ); + } + + /** + * The minimum release to include. + * + * @param \DateTime|string $date + * @return $this + */ + public function releaseDateGte($date) + { + if ($date instanceof \DateTime) { + $date = $date->format('Y-m-d'); + } + + $this->set('release_date.gte', $date); + + return $this; + } + + /** + * The maximum release to include. + * + * @param \DateTime $date + * @return $this + */ + public function releaseDateLte(\DateTime $date) + { + if ($date instanceof \DateTime) { + $date = $date->format('Y-m-d'); + } + + $this->set('release_date.gte', $date); + + return $this; + } + + /** + * Only include movies with certifications for a specific country. + * + * When this value is specified, 'certification.lte' is required. A ISO 3166-1 is expected. + * + * @param string $country + * @return $this + */ + public function certificationCountry($country) + { + $this->set('certification_country', $country); + + return $this; + } + + /** + * Only include movies with this certification and lower. + * + * Expected value is a valid certification for the specificed 'certification_country'. + * + * @param mixed $value + * @return $this + */ + public function certificationLte($value) + { + $this->set('certification.lte', $value); + + return $this; + } + + /** + * Filter movies to include a specific company. + * + * Expected value is an integer (the id of a company). + * They can be comma separated to indicate an 'AND' query. + * + * @param array|string $companies + * @return $this + */ + public function withCompanies($companies) + { + if (is_array($companies)) { + $companies = $this->withCompaniesAnd($companies); + } + + $this->set('with_companies', $companies); + + return $this; + } + + /** + * Creates an and query for companies + * + * @param array $companies + * @return $this + */ + public function withCompaniesAnd(array $companies = array()) + { + return $this->withCompanies( + implode(',', $companies) + ); + } +} diff --git a/modules/Tmdb/Model/Query/Discover/DiscoverTvQuery.php b/modules/Tmdb/Model/Query/Discover/DiscoverTvQuery.php new file mode 100644 index 00000000..6066e637 --- /dev/null +++ b/modules/Tmdb/Model/Query/Discover/DiscoverTvQuery.php @@ -0,0 +1,219 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Query\Discover; + +use Tmdb\Model\Collection\QueryParametersCollection; + +/** + * Class DiscoverTvQuery + * @package Tmdb\Model\Query\Discover + */ +class DiscoverTvQuery extends QueryParametersCollection { + /** + * Minimum value is 1, expected value is an integer. + * + * @param integer $page + * @return $this + */ + public function page($page = 1) + { + $this->set('page', (int) $page); + + return $this; + } + + /** + * ISO 639-1 code. + * + * @param string $language + * @return $this + */ + public function language($language) + { + $this->set('language', $language); + + return $this; + } + + /** + * Available options are vote_average.desc, vote_average.asc, first_air_date.desc, first_air_date.asc, popularity.desc, popularity.asc + * + * @param string $option + * @return $this + */ + public function sortBy($option) + { + $this->set('sort_by', $option); + + return $this; + } + + /** + * Filter the results release dates to matches that include this value. Expected value is a year. + * + * @param \DateTime|integer $year + * @return $this + */ + public function firstAirDateYear($year) + { + if ($year instanceof \DateTime) { + $year = $year->format('Y'); + } + + $this->set('first_air_date_year', (int) $year); + + return $this; + } + + /** + * Only include TV shows that are equal to, or have a vote count higher than this value. Expected value is an integer. + * + * @param integer $count + * @return $this + */ + public function voteCountGte($count) + { + $this->set('vote_count.gte', (int) $count); + + return $this; + } + + /** + * Only include TV shows that are equal to, or have a higher average rating than this value. Expected value is a float. + * + * @param float $average + * @return $this + */ + public function voteAverageGte($average) + { + $this->set('vote_average.gte', (float) $average); + + return $this; + } + + /** + * Only include TV shows with the specified genres. Expected value is an integer (the id of a genre). + * + * Multiple values can be specified. + * Comma separated indicates an 'AND' query, while a pipe (|) separated value indicates an 'OR'. + * + * @param array|string $genres + * @return $this + */ + public function withGenres($genres) + { + if (is_array($genres)) { + $genres = $this->withGenresAnd($genres); + } + + $this->set('with_genres', $genres); + + return $this; + } + + /** + * Creates an OR query for genres + * + * @param array $genres + * @return $this + */ + public function withGenresOr(array $genres = array()) + { + return $this->withGenres( + implode('|', $genres) + ); + } + + /** + * Creates an AND query for genres + * + * @param array $genres + * @return $this + */ + public function withGenresAnd(array $genres = array()) + { + return $this->withGenres( + implode(',', $genres) + ); + } + + /** + * The minimum release to include. Expected format is YYYY-MM-DD. + * + * @param \DateTime|string $date + * @return $this + */ + public function firstAirDateGte($date) + { + if ($date instanceof \DateTime) { + $date = $date->format('Y-m-d'); + } + + $this->set('first_air_date.gte', $date); + + return $this; + } + + /** + * The maximum release to include. Expected format is YYYY-MM-DD. + * + * @param \DateTime|string $date + * @return $this + */ + public function firstAirDateLte($date) + { + if ($date instanceof \DateTime) { + $date = $date->format('Y-m-d'); + } + + $this->set('first_air_date.lte', $date); + + return $this; + } + + + /** + * Filter TV shows to include a specific network. + * + * Expected value is an integer (the id of a network). They can be comma separated to indicate an 'AND' query. + * + * Expected value is an integer (the id of a company). + * They can be comma separated to indicate an 'AND' query. + * + * @param array|string $networks + * @return $this + */ + public function withNetworks($networks) + { + if (is_array($networks)) { + $networks = $this->withNetworksAnd($networks); + } + + $this->set('with_networks', $networks); + + return $this; + } + + /** + * Creates an and query for networks + * + * @param array $networks + * @return $this + */ + public function withNetworksAnd(array $networks = array()) + { + return $this->withNetworks( + implode(',', $networks) + ); + } +} diff --git a/modules/Tmdb/Model/Query/FindQuery.php b/modules/Tmdb/Model/Query/FindQuery.php new file mode 100644 index 00000000..eadfdc2b --- /dev/null +++ b/modules/Tmdb/Model/Query/FindQuery.php @@ -0,0 +1,24 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Query; + +use Tmdb\Model\Collection\QueryParametersCollection; + +// @todo +/** + * Class FindQuery + * @package Tmdb\Model\Query + */ +class FindQuery extends QueryParametersCollection { + +} diff --git a/modules/Tmdb/Model/Review.php b/modules/Tmdb/Model/Review.php new file mode 100644 index 00000000..f56e2f89 --- /dev/null +++ b/modules/Tmdb/Model/Review.php @@ -0,0 +1,186 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +/** + * Class Review + * @package Tmdb\Model + */ +class Review extends AbstractModel { + + private $id; + private $author; + private $content; + private $iso6391; + private $mediaId; + private $mediaTitle; + private $mediaType; + private $url; + + public static $_properties = array( + 'id', + 'author', + 'content', + 'iso_639_1', + 'media_id', + 'media_title', + 'media_type', + 'url' + ); + + /** + * @param mixed $author + * @return $this + */ + public function setAuthor($author) + { + $this->author = $author; + return $this; + } + + /** + * @return mixed + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @param mixed $content + * @return $this + */ + public function setContent($content) + { + $this->content = $content; + return $this; + } + + /** + * @return mixed + */ + public function getContent() + { + return $this->content; + } + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $iso6391 + * @return $this + */ + public function setIso6391($iso6391) + { + $this->iso6391 = $iso6391; + return $this; + } + + /** + * @return mixed + */ + public function getIso6391() + { + return $this->iso6391; + } + + /** + * @param mixed $mediaId + * @return $this + */ + public function setMediaId($mediaId) + { + $this->mediaId = $mediaId; + return $this; + } + + /** + * @return mixed + */ + public function getMediaId() + { + return $this->mediaId; + } + + /** + * @param mixed $mediaTitle + * @return $this + */ + public function setMediaTitle($mediaTitle) + { + $this->mediaTitle = $mediaTitle; + return $this; + } + + /** + * @return mixed + */ + public function getMediaTitle() + { + return $this->mediaTitle; + } + + /** + * @param mixed $mediaType + * @return $this + */ + public function setMediaType($mediaType) + { + $this->mediaType = $mediaType; + return $this; + } + + /** + * @return mixed + */ + public function getMediaType() + { + return $this->mediaType; + } + + /** + * @param mixed $url + * @return $this + */ + public function setUrl($url) + { + $this->url = $url; + return $this; + } + + /** + * @return mixed + */ + public function getUrl() + { + return $this->url; + } + + +} diff --git a/modules/Tmdb/Model/Search/SearchQuery.php b/modules/Tmdb/Model/Search/SearchQuery.php new file mode 100644 index 00000000..e32b95f8 --- /dev/null +++ b/modules/Tmdb/Model/Search/SearchQuery.php @@ -0,0 +1,47 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search; + +use Tmdb\Model\Collection\QueryParametersCollection; + +/** + * Class SearchQuery + * @package Tmdb\Model\Search + */ +class SearchQuery extends QueryParametersCollection { + /** + * CGI escaped string + * + * @param string + * @return $this + */ + public function query($query) + { + $this->set('query', $query); + + return $this; + } + + /** + * Minimum 1, maximum 1000. + * + * @param int + * @return $this + */ + public function page($page) + { + $this->set('page', $page); + + return $this; + } +} diff --git a/modules/Tmdb/Model/Search/SearchQuery/CollectionSearchQuery.php b/modules/Tmdb/Model/Search/SearchQuery/CollectionSearchQuery.php new file mode 100644 index 00000000..db513d7f --- /dev/null +++ b/modules/Tmdb/Model/Search/SearchQuery/CollectionSearchQuery.php @@ -0,0 +1,34 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +/** + * Class CollectionSearchQuery + * @package Tmdb\Model\Search\SearchQuery + */ +class CollectionSearchQuery extends SearchQuery { + /** + * ISO 639-1 code. + * + * @param string + * @return $this + */ + public function language($language) + { + $this->set('language', $language); + + return $this; + } +} diff --git a/modules/Tmdb/Model/Search/SearchQuery/CompanySearchQuery.php b/modules/Tmdb/Model/Search/SearchQuery/CompanySearchQuery.php new file mode 100644 index 00000000..03741501 --- /dev/null +++ b/modules/Tmdb/Model/Search/SearchQuery/CompanySearchQuery.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +/** + * Class CompanySearchQuery + * @package Tmdb\Model\Search\SearchQuery + */ +class CompanySearchQuery extends SearchQuery {} diff --git a/modules/Tmdb/Model/Search/SearchQuery/KeywordSearchQuery.php b/modules/Tmdb/Model/Search/SearchQuery/KeywordSearchQuery.php new file mode 100644 index 00000000..972287a7 --- /dev/null +++ b/modules/Tmdb/Model/Search/SearchQuery/KeywordSearchQuery.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +/** + * Class KeywordSearchQuery + * @package Tmdb\Model\Search\SearchQuery + */ +class KeywordSearchQuery extends SearchQuery {} diff --git a/modules/Tmdb/Model/Search/SearchQuery/ListSearchQuery.php b/modules/Tmdb/Model/Search/SearchQuery/ListSearchQuery.php new file mode 100644 index 00000000..05206313 --- /dev/null +++ b/modules/Tmdb/Model/Search/SearchQuery/ListSearchQuery.php @@ -0,0 +1,35 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +/** + * Class ListSearchQuery + * @package Tmdb\Model\Search\SearchQuery + */ +class ListSearchQuery extends SearchQuery { + + /** + * Toggle the inclusion of adult titles. Expected value is: true or false + * + * @param bool + * @return $this + */ + public function includeAdult($include_adult) + { + $this->set('include_adult', (bool) $include_adult); + + return $this; + } +} diff --git a/modules/Tmdb/Model/Search/SearchQuery/MovieSearchQuery.php b/modules/Tmdb/Model/Search/SearchQuery/MovieSearchQuery.php new file mode 100644 index 00000000..58fc7e0b --- /dev/null +++ b/modules/Tmdb/Model/Search/SearchQuery/MovieSearchQuery.php @@ -0,0 +1,95 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +/** + * Class MovieSearchQuery + * @package Tmdb\Model\Search\SearchQuery + */ +class MovieSearchQuery extends SearchQuery { + /** + * ISO 639-1 code. + * + * @param string + * @return $this + */ + public function language($language) + { + $this->set('language', $language); + + return $this; + } + + /** + * Toggle the inclusion of adult titles. Expected value is: true or false + * + * @param bool + * @return $this + */ + public function includeAdult($include_adult) + { + $this->set('include_adult', (bool) $include_adult); + + return $this; + } + + /** + * Filter the results release dates to matches that include this value. + * + * @param string + * @return $this + */ + public function year($year) + { + if ($year instanceof \DateTime) { + $year = $year->format('Y'); + } + + $this->set('year', (int) $year); + + return $this; + } + + /** + * Filter the results so that only the primary release dates have this value. + * + * @param string + * @return $this + */ + public function primaryReleaseYear($primary_release_year) + { + $this->set('primary_release_year', $primary_release_year); + + return $this; + } + + /** + * By default, the search type is 'phrase'. + * + * This is almost guaranteed the option you will want. + * It's a great all purpose search type and by far the most tuned for every day querying. + * + * For those wanting more of an "autocomplete" type search, set this option to 'ngram'. + * + * @param string + * @return $this + */ + public function searchType($search_type = 'phrase') + { + $this->set('search_type', $search_type); + + return $this; + } +} diff --git a/modules/Tmdb/Model/Search/SearchQuery/PersonSearchQuery.php b/modules/Tmdb/Model/Search/SearchQuery/PersonSearchQuery.php new file mode 100644 index 00000000..ab86ffa6 --- /dev/null +++ b/modules/Tmdb/Model/Search/SearchQuery/PersonSearchQuery.php @@ -0,0 +1,53 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +/** + * Class PersonSearchQuery + * @package Tmdb\Model\Search\SearchQuery + */ +class PersonSearchQuery extends SearchQuery { + + /** + * Toggle the inclusion of adult titles. Expected value is: true or false + * + * @param bool + * @return $this + */ + public function includeAdult($include_adult) + { + $this->set('include_adult', (bool) $include_adult); + + return $this; + } + + /** + * By default, the search type is 'phrase'. + * + * This is almost guaranteed the option you will want. + * It's a great all purpose search type and by far the most tuned for every day querying. + * + * For those wanting more of an "autocomplete" type search, set this option to 'ngram'. + * + * @param string + * @return $this + */ + public function searchType($search_type = 'phrase') + { + $this->set('search_type', $search_type); + + return $this; + } +} diff --git a/modules/Tmdb/Model/Search/SearchQuery/TvSearchQuery.php b/modules/Tmdb/Model/Search/SearchQuery/TvSearchQuery.php new file mode 100644 index 00000000..d8863425 --- /dev/null +++ b/modules/Tmdb/Model/Search/SearchQuery/TvSearchQuery.php @@ -0,0 +1,69 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +/** + * Class TvSearchQuery + * @package Tmdb\Model\Search\SearchQuery + */ +class TvSearchQuery extends SearchQuery { + /** + * ISO 639-1 code. + * + * @param string + * @return $this + */ + public function language($language) + { + $this->set('language', $language); + + return $this; + } + + /** + * Filter the results to only match shows that have a air date with with value. + * + * @param string + * @return $this + */ + public function firstAirDateYear($year) + { + if ($year instanceof \DateTime) { + $year = $year->format('Y'); + } + + $this->set('year', (int) $year); + + return $this; + } + + /** + * By default, the search type is 'phrase'. + * + * This is almost guaranteed the option you will want. + * It's a great all purpose search type and by far the most tuned for every day querying. + * + * For those wanting more of an "autocomplete" type search, set this option to 'ngram'. + * + * @param string + * @return $this + */ + public function searchType($search_type = 'phrase') + { + $this->set('search_type', $search_type); + + return $this; + } +} diff --git a/modules/Tmdb/Model/Tv.php b/modules/Tmdb/Model/Tv.php new file mode 100644 index 00000000..ac18ad9f --- /dev/null +++ b/modules/Tmdb/Model/Tv.php @@ -0,0 +1,763 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model; + +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Collection\CreditsCollection; +use Tmdb\Model\Collection\Genres; +use Tmdb\Model\Collection\Images; +use Tmdb\Model\Image\BackdropImage; +use Tmdb\Model\Image\PosterImage; +use Tmdb\Model\Common\ExternalIds; +use Tmdb\Model\Tv\Network; + +/** + * Class Tv + * @package Tmdb\Model + */ +class Tv extends AbstractModel { + + /** + * @var Image + */ + private $backdropPath; + + /** + * @var Collection + */ + private $createdBy = null; + + /** + * @var array + */ + private $episodeRunTime; + + /** + * @var \DateTime + */ + private $firstAirDate; + + /** + * Genres + * + * @var Genres + */ + private $genres; + + /** + * @var string + */ + private $homepage; + + /** + * @var int + */ + private $id; + + /** + * @var boolean + */ + private $inProduction; + + /** + * @var array + */ + private $languages; + + /** + * @var \DateTime + */ + private $lastAirDate; + + /** + * @var string + */ + private $name; + + /** + * @var Network[] + */ + private $networks; + + /** + * @var integer + */ + private $numberOfEpisodes; + + /** + * @var integer + */ + private $numberOfSeasons; + + /** + * @var string + */ + private $originalName; + + /** + * @var Collection + */ + private $originCountry; + + /** + * @var string + */ + private $overview; + + /** + * @var float + */ + private $popularity; + + /** + * @var Image + */ + private $posterPath; + + /** + * @var Collection + */ + private $seasons; + + /** + * @var string + */ + private $status; + + /** + * @var float + */ + private $voteAverage; + + /** + * @var int + */ + private $voteCount; + + /** + * Credits + * + * @var Credits + */ + protected $credits; + + /** + * External Ids + * + * @var ExternalIds + */ + protected $externalIds; + + /** + * Images + * + * @var Images + */ + protected $images; + + /** + * @var Collection + */ + protected $translations; + + /** + * @var BackdropImage + */ + protected $backdrop; + + /** + * @var PosterImage + */ + protected $poster; + + /** + * Properties that are available in the API + * + * These properties are hydrated by the ObjectHydrator, all the other properties are handled by the factory. + * + * @var array + */ + public static $_properties = array( + 'backdrop_path', + 'created_by', + 'episode_run_time', + 'first_air_date', + 'homepage', + 'id', + 'in_production', + 'languages', + 'last_air_date', + 'name', + 'number_of_episodes', + 'number_of_seasons', + 'original_name', + 'origin_country', + 'overview', + 'popularity', + 'poster_path', + 'status', + 'vote_average', + 'vote_count', + ); + + /** + * Constructor + * + * Set all default collections + */ + public function __construct() + { + $this->createdBy = new Images(); + $this->episodeRunTime = new GenericCollection(); + $this->genres = new Genres(); + $this->languages = new GenericCollection(); + $this->networks = new GenericCollection(); + $this->originCountry = new GenericCollection(); + $this->seasons = new GenericCollection(); + + $this->credits = new CreditsCollection(); + $this->externalIds = new ExternalIds(); + $this->images = new Images(); + $this->translations = new GenericCollection(); + } + + /** + * @param string $backdropPath + * @return $this + */ + public function setBackdropPath($backdropPath) + { + $this->backdropPath = $backdropPath; + return $this; + } + + /** + * @return string + */ + public function getBackdropPath() + { + return $this->backdropPath; + } + + /** + * @param \Tmdb\Model\Common\Collection $createdBy + * @return $this + */ + public function setCreatedBy($createdBy) + { + $this->createdBy = $createdBy; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getCreatedBy() + { + return $this->createdBy; + } + + /** + * @param array $episodeRunTime + * @return $this + */ + public function setEpisodeRunTime($episodeRunTime) + { + $this->episodeRunTime = $episodeRunTime; + return $this; + } + + /** + * @return array + */ + public function getEpisodeRunTime() + { + return $this->episodeRunTime; + } + + /** + * @param \DateTime $firstAirDate + * @return $this + */ + public function setFirstAirDate($firstAirDate) + { + if (!$firstAirDate instanceof \DateTime) { + $firstAirDate = new \DateTime($firstAirDate); + } + + $this->firstAirDate = $firstAirDate; + return $this; + } + + /** + * @return \DateTime + */ + public function getFirstAirDate() + { + return $this->firstAirDate; + } + + /** + * @param \Tmdb\Model\Collection\Genres $genres + * @return $this + */ + public function setGenres($genres) + { + $this->genres = $genres; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\Genres + */ + public function getGenres() + { + return $this->genres; + } + + /** + * @param string $homepage + * @return $this + */ + public function setHomepage($homepage) + { + $this->homepage = $homepage; + return $this; + } + + /** + * @return string + */ + public function getHomepage() + { + return $this->homepage; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param boolean $inProduction + * @return $this + */ + public function setInProduction($inProduction) + { + $this->inProduction = $inProduction; + return $this; + } + + /** + * @return boolean + */ + public function getInProduction() + { + return $this->inProduction; + } + + /** + * @param array $languages + * @return $this + */ + public function setLanguages($languages) + { + $this->languages = $languages; + return $this; + } + + /** + * @return array + */ + public function getLanguages() + { + return $this->languages; + } + + /** + * @param string $lastAirDate + * @return $this + */ + public function setLastAirDate($lastAirDate) + { + if (!$lastAirDate instanceof \DateTime) { + $lastAirDate = new \DateTime($lastAirDate); + } + + $this->lastAirDate = $lastAirDate; + return $this; + } + + /** + * @return \DateTime + */ + public function getLastAirDate() + { + return $this->lastAirDate; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param GenericCollection $networks + * @return $this + */ + public function setNetworks($networks) + { + $this->networks = $networks; + return $this; + } + + /** + * @return Network[] + */ + public function getNetworks() + { + return $this->networks; + } + + /** + * @param int $numberOfEpisodes + * @return $this + */ + public function setNumberOfEpisodes($numberOfEpisodes) + { + $this->numberOfEpisodes = (int) $numberOfEpisodes; + return $this; + } + + /** + * @return int + */ + public function getNumberOfEpisodes() + { + return $this->numberOfEpisodes; + } + + /** + * @param int $numberOfSeasons + * @return $this + */ + public function setNumberOfSeasons($numberOfSeasons) + { + $this->numberOfSeasons = (int) $numberOfSeasons; + return $this; + } + + /** + * @return int + */ + public function getNumberOfSeasons() + { + return $this->numberOfSeasons; + } + + /** + * @param \Tmdb\Model\Common\Collection $originCountry + * @return $this + */ + public function setOriginCountry($originCountry) + { + $this->originCountry = $originCountry; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getOriginCountry() + { + return $this->originCountry; + } + + /** + * @param string $originalName + * @return $this + */ + public function setOriginalName($originalName) + { + $this->originalName = $originalName; + return $this; + } + + /** + * @return string + */ + public function getOriginalName() + { + return $this->originalName; + } + + /** + * @param string $overview + * @return $this + */ + public function setOverview($overview) + { + $this->overview = $overview; + return $this; + } + + /** + * @return string + */ + public function getOverview() + { + return $this->overview; + } + + /** + * @param float $popularity + * @return $this + */ + public function setPopularity($popularity) + { + $this->popularity = (float) $popularity; + return $this; + } + + /** + * @return float + */ + public function getPopularity() + { + return $this->popularity; + } + + /** + * @param string $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return string + */ + public function getPosterPath() + { + return $this->posterPath; + } + + /** + * @param GenericCollection $seasons + * @return $this + */ + public function setSeasons($seasons) + { + $this->seasons = $seasons; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getSeasons() + { + return $this->seasons; + } + + /** + * @param string $status + * @return $this + */ + public function setStatus($status) + { + $this->status = $status; + return $this; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param float $voteAverage + * @return $this + */ + public function setVoteAverage($voteAverage) + { + $this->voteAverage = (float) $voteAverage; + return $this; + } + + /** + * @return float + */ + public function getVoteAverage() + { + return $this->voteAverage; + } + + /** + * @param int $voteCount + * @return $this + */ + public function setVoteCount($voteCount) + { + $this->voteCount = (int) $voteCount; + return $this; + } + + /** + * @return int + */ + public function getVoteCount() + { + return $this->voteCount; + } + + /** + * @param GenericCollection $translations + * @return $this + */ + public function setTranslations($translations) + { + $this->translations = $translations; + return $this; + } + + /** + * @return \Tmdb\Model\Common\Collection + */ + public function getTranslations() + { + return $this->translations; + } + + /** + * @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 \Tmdb\Model\Common\ExternalIds $externalIds + * @return $this + */ + public function setExternalIds($externalIds) + { + $this->externalIds = $externalIds; + return $this; + } + + /** + * @return \Tmdb\Model\Common\ExternalIds + */ + public function getExternalIds() + { + return $this->externalIds; + } + + /** + * @param \Tmdb\Model\Collection\CreditsCollection $credits + * @return $this + */ + public function setCredits($credits) + { + $this->credits = $credits; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\CreditsCollection + */ + public function getCredits() + { + return $this->credits; + } + + /** + * @param \Tmdb\Model\Image\BackdropImage $backdrop + * @return $this + */ + public function setBackdropImage(BackdropImage $backdrop) + { + $this->backdrop = $backdrop; + return $this; + } + + /** + * @return \Tmdb\Model\Image\BackdropImage + */ + public function getBackdropImage() + { + return $this->backdrop; + } + + /** + * @param \Tmdb\Model\Image\PosterImage $poster + * @return $this + */ + public function setPosterImage(PosterImage $poster) + { + $this->poster = $poster; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->poster; + } +} diff --git a/modules/Tmdb/Model/Tv/Episode.php b/modules/Tmdb/Model/Tv/Episode.php new file mode 100644 index 00000000..1a4b5e64 --- /dev/null +++ b/modules/Tmdb/Model/Tv/Episode.php @@ -0,0 +1,389 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Tv; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Collection\CreditsCollection; +use Tmdb\Model\Collection\Images; +use Tmdb\Model\Common\ExternalIds; +use Tmdb\Model\Image\StillImage; + +/** + * Class Episode + * @package Tmdb\Model\Tv + */ +class Episode extends AbstractModel { + + /** + * @var \DateTime + */ + private $airDate; + + /** + * @var integer + */ + private $episodeNumber; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $overview; + + /** + * @var integer + */ + private $id; + + /** + * @var string + */ + private $productionCode; + + /** + * @var integer + */ + private $seasonNumber; + + /** + * @var string + */ + private $stillPath; + + /** + * @var float + */ + private $voteAverage; + + /** + * @var int + */ + private $voteCount; + + /** + * Credits + * + * @var Credits + */ + protected $credits; + + /** + * External Ids + * + * @var ExternalIds + */ + protected $externalIds; + + /** + * Images + * + * @var Images + */ + protected $images; + + /** + * @var StillImage + */ + protected $still; + + + /** + * Properties that are available in the API + * + * These properties are hydrated by the ObjectHydrator, all the other properties are handled by the factory. + * + * @var array + */ + public static $_properties = array( + 'air_date', + 'episode_number', + 'name', + 'overview', + 'id', + 'production_code', + 'season_number', + 'still_path', + 'vote_average', + 'vote_count' + ); + + /** + * Constructor + */ + public function __construct() + { + $this->credits = new CreditsCollection(); + $this->externalIds = new ExternalIds(); + $this->images = new Images(); + } + + /** + * @param \DateTime $airDate + * @return $this + */ + public function setAirDate($airDate) + { + if (!$airDate instanceof \DateTime) { + $airDate = new \DateTime($airDate); + } + + $this->airDate = $airDate; + return $this; + } + + /** + * @return \DateTime + */ + public function getAirDate() + { + return $this->airDate; + } + + /** + * @param int $episodeNumber + * @return $this + */ + public function setEpisodeNumber($episodeNumber) + { + $this->episodeNumber = (int) $episodeNumber; + return $this; + } + + /** + * @return int + */ + public function getEpisodeNumber() + { + return $this->episodeNumber; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $overview + * @return $this + */ + public function setOverview($overview) + { + $this->overview = $overview; + return $this; + } + + /** + * @return string + */ + public function getOverview() + { + return $this->overview; + } + + /** + * @param string $productionCode + * @return $this + */ + public function setProductionCode($productionCode) + { + $this->productionCode = $productionCode; + return $this; + } + + /** + * @return string + */ + public function getProductionCode() + { + return $this->productionCode; + } + + /** + * @param int $seasonNumber + * @return $this + */ + public function setSeasonNumber($seasonNumber) + { + $this->seasonNumber = (int) $seasonNumber; + return $this; + } + + /** + * @return int + */ + public function getSeasonNumber() + { + return $this->seasonNumber; + } + + /** + * @param string $stillPath + * @return $this + */ + public function setStillPath($stillPath) + { + $this->stillPath = $stillPath; + return $this; + } + + /** + * @return string + */ + public function getStillPath() + { + return $this->stillPath; + } + + /** + * @param float $voteAverage + * @return $this + */ + public function setVoteAverage($voteAverage) + { + $this->voteAverage = (float) $voteAverage; + return $this; + } + + /** + * @return float + */ + public function getVoteAverage() + { + return $this->voteAverage; + } + + /** + * @param int $voteCount + * @return $this + */ + public function setVoteCount($voteCount) + { + $this->voteCount = (int) $voteCount; + return $this; + } + + /** + * @return int + */ + public function getVoteCount() + { + return $this->voteCount; + } + + /** + * @param Credits $credits + * @return $this + */ + public function setCredits($credits) + { + $this->credits = $credits; + return $this; + } + + /** + * @return Credits + */ + public function getCredits() + { + return $this->credits; + } + + /** + * @param ExternalIds $externalIds + * @return $this + */ + public function setExternalIds($externalIds) + { + $this->externalIds = $externalIds; + return $this; + } + + /** + * @return ExternalIds + */ + public function getExternalIds() + { + return $this->externalIds; + } + + /** + * @param Images $images + * @return $this + */ + public function setImages($images) + { + $this->images = $images; + return $this; + } + + /** + * @return Images + */ + public function getImages() + { + return $this->images; + } + + /** + * @param StillImage $still + * @return $this + */ + public function setStillImage($still) + { + $this->still = $still; + return $this; + } + + /** + * @return StillImage + */ + public function getStillImage() + { + return $this->still; + } +} diff --git a/modules/Tmdb/Model/Tv/Episode/QueryParameter/AppendToResponse.php b/modules/Tmdb/Model/Tv/Episode/QueryParameter/AppendToResponse.php new file mode 100644 index 00000000..80815631 --- /dev/null +++ b/modules/Tmdb/Model/Tv/Episode/QueryParameter/AppendToResponse.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Tv\Episode\QueryParameter; + +use Tmdb\Model\Common\QueryParameter\AppendToResponse as BaseAppendToResponse; + +/** + * Class AppendToResponse + * @package Tmdb\Model\Tv\Episode\QueryParameter + */ +class AppendToResponse extends BaseAppendToResponse { + const CREDITS = 'credits'; + const EXTERNAL_IDS = 'external_ids'; + const IMAGES = 'images'; +} diff --git a/modules/Tmdb/Model/Tv/Network.php b/modules/Tmdb/Model/Tv/Network.php new file mode 100644 index 00000000..c4c4be65 --- /dev/null +++ b/modules/Tmdb/Model/Tv/Network.php @@ -0,0 +1,80 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Tv; + +use Tmdb\Model\AbstractModel; + +/** + * Class Network + * @package Tmdb\Model\Tv + */ +class Network extends AbstractModel { + + /** + * @var integer + */ + private $id; + + /** + * @var string + */ + private $name; + + /** + * Properties that are available in the API + * + * These properties are hydrated by the ObjectHydrator, all the other properties are handled by the factory. + * + * @var array + */ + public static $_properties = array( + 'id', + 'name', + ); + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } +} diff --git a/modules/Tmdb/Model/Tv/QueryParameter/AppendToResponse.php b/modules/Tmdb/Model/Tv/QueryParameter/AppendToResponse.php new file mode 100644 index 00000000..f74fd6b5 --- /dev/null +++ b/modules/Tmdb/Model/Tv/QueryParameter/AppendToResponse.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Tv\QueryParameter; + +use Tmdb\Model\Common\QueryParameter\AppendToResponse as BaseAppendToResponse; + +/** + * Class AppendToResponse + * @package Tmdb\Model\Tv\QueryParameter + */ +class AppendToResponse extends BaseAppendToResponse { + const CREDITS = 'credits'; + const EXTERNAL_IDS = 'external_ids'; + const IMAGES = 'images'; + const TRANSLATIONS = 'translations'; +} diff --git a/modules/Tmdb/Model/Tv/Season.php b/modules/Tmdb/Model/Tv/Season.php new file mode 100644 index 00000000..74a60edd --- /dev/null +++ b/modules/Tmdb/Model/Tv/Season.php @@ -0,0 +1,313 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Tv; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Collection\CreditsCollection; +use Tmdb\Model\Collection\Images; +use Tmdb\Model\Common\ExternalIds; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Image\PosterImage; + +/** + * Class Season + * @package Tmdb\Model\Tv + */ +class Season extends AbstractModel { + + /** + * @var \DateTime + */ + private $airDate; + + /** + * @var Episode[] + */ + private $episodes; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $overview; + + /** + * @var integer + */ + private $id; + + /** + * @var string + */ + private $posterPath; + + /** + * @var integer + */ + private $seasonNumber; + + /** + * Credits + * + * @var Credits + */ + protected $credits; + + /** + * External Ids + * + * @var ExternalIds + */ + protected $externalIds; + + /** + * Images + * + * @var Images + */ + protected $images; + + /** + * @var PosterImage + */ + protected $poster; + + /** + * Properties that are available in the API + * + * These properties are hydrated by the ObjectHydrator, all the other properties are handled by the factory. + * + * @var array + */ + public static $_properties = array( + 'air_date', + 'name', + 'overview', + 'id', + 'poster_path', + 'season_number' + ); + + /** + * Constructor + */ + public function __construct() + { + $this->credits = new CreditsCollection(); + $this->externalIds = new ExternalIds(); + $this->images = new Images(); + $this->episodes = new GenericCollection(); + } + + /** + * @param \DateTime $airDate + * @return $this + */ + public function setAirDate($airDate) + { + $this->airDate = new \DateTime($airDate); + return $this; + } + + /** + * @return \DateTime + */ + public function getAirDate() + { + return $this->airDate; + } + + /** + * @param GenericCollection $episodes + * @return $this + */ + public function setEpisodes($episodes) + { + $this->episodes = $episodes; + return $this; + } + + /** + * @return \Tmdb\Model\Tv\Episode[] + */ + public function getEpisodes() + { + return $this->episodes; + } + + /** + * @param int $id + * @return $this + */ + public function setId($id) + { + $this->id = (int) $id; + return $this; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $overview + * @return $this + */ + public function setOverview($overview) + { + $this->overview = $overview; + return $this; + } + + /** + * @return string + */ + public function getOverview() + { + return $this->overview; + } + + /** + * @param \Tmdb\Model\Tv\Image $posterPath + * @return $this + */ + public function setPosterPath($posterPath) + { + $this->posterPath = $posterPath; + return $this; + } + + /** + * @return \Tmdb\Model\Tv\Image + */ + public function getPosterPath() + { + return $this->posterPath; + } + + /** + * @param int $seasonNumber + * @return $this + */ + public function setSeasonNumber($seasonNumber) + { + $this->seasonNumber = $seasonNumber; + return $this; + } + + /** + * @return int + */ + public function getSeasonNumber() + { + return $this->seasonNumber; + } + + /** + * @param Credits $credits + * @return $this + */ + public function setCredits($credits) + { + $this->credits = $credits; + return $this; + } + + /** + * @return \Tmdb\Model\Collection\CreditsCollection + */ + public function getCredits() + { + return $this->credits; + } + + /** + * @param \Tmdb\Model\Common\ExternalIds $externalIds + * @return $this + */ + public function setExternalIds($externalIds) + { + $this->externalIds = $externalIds; + return $this; + } + + /** + * @return \Tmdb\Model\Common\ExternalIds + */ + public function getExternalIds() + { + return $this->externalIds; + } + + /** + * @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 \Tmdb\Model\Image\PosterImage $poster + * @return $this + */ + public function setPosterImage($poster) + { + $this->poster = $poster; + return $this; + } + + /** + * @return \Tmdb\Model\Image\PosterImage + */ + public function getPosterImage() + { + return $this->poster; + } +} diff --git a/modules/Tmdb/Model/Tv/Season/QueryParameter/AppendToResponse.php b/modules/Tmdb/Model/Tv/Season/QueryParameter/AppendToResponse.php new file mode 100644 index 00000000..5a98bb92 --- /dev/null +++ b/modules/Tmdb/Model/Tv/Season/QueryParameter/AppendToResponse.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Tv\Season\QueryParameter; + +use Tmdb\Model\Common\QueryParameter\AppendToResponse as BaseAppendToResponse; + +/** + * Class AppendToResponse + * @package Tmdb\Model\Tv\Season\QueryParameter + */ +class AppendToResponse extends BaseAppendToResponse { + const CREDITS = 'credits'; + const EXTERNAL_IDS = 'external_ids'; + const IMAGES = 'images'; +} diff --git a/modules/Tmdb/Repository/AbstractRepository.php b/modules/Tmdb/Repository/AbstractRepository.php new file mode 100644 index 00000000..3909cac0 --- /dev/null +++ b/modules/Tmdb/Repository/AbstractRepository.php @@ -0,0 +1,88 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Api\ApiInterface; +use Tmdb\Client; +use Tmdb\Factory\FactoryInterface; +use Tmdb\Model\Common\QueryParameter\QueryParameterInterface; + +/** + * Class AbstractRepository + * @package Tmdb\Repository + */ +abstract class AbstractRepository { + + protected $client = null; + protected $api = null; + + /** + * Constructor + * + * + * @todo create an interface for the client + * + * @param Client $client + */ + public function __construct(Client $client) + { + $this->client = $client; + } + + /** + * Return the client + * + * @return Client + */ + public function getClient() + { + return $this->client; + } + + /** + * Process query parameters + * + * @param array $parameters + * @return array + */ + protected function parseQueryParameters(array $parameters = array()) + { + foreach($parameters as $key => $candidate) { + if (is_a($candidate, 'Tmdb\Model\Common\QueryParameter\QueryParameterInterface')) { + $interfaces = class_implements($candidate); + + if (array_key_exists('Tmdb\Model\Common\QueryParameter\QueryParameterInterface', $interfaces)) { + unset($parameters[$key]); + + $parameters[$candidate->getKey()] = $candidate->getValue(); + } + } + } + + return $parameters; + } + + /** + * Return the API Class + * + * @return ApiInterface + */ + abstract public function getApi(); + + /** + * Return the Factory Class + * + * @return FactoryInterface + */ + abstract public function getFactory(); +} diff --git a/modules/Tmdb/Repository/AccountRepository.php b/modules/Tmdb/Repository/AccountRepository.php new file mode 100644 index 00000000..faa7f077 --- /dev/null +++ b/modules/Tmdb/Repository/AccountRepository.php @@ -0,0 +1,147 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\AccountFactory; +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Movie; + +/** + * Class AccountRepository + * @package Tmdb\Repository + * http://docs.themoviedb.apiary.io/#account + */ +class AccountRepository extends AbstractRepository { + + /** + * Get the basic information for an account. You will need to have a valid session id. + * + * @return null|\Tmdb\Model\AbstractModel + */ + public function getAccount() + { + $data = $this->getApi()->getAccount(); + return $this->getFactory()->create($data); + } + + /** + * Get the lists that you have created and marked as a favorite. + * + * @param string $accountId + * @param array $parameters + * @param array $headers + * @return ResultCollection + */ + public function getLists($accountId, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getLists($accountId, $parameters, $headers); + return $this->getFactory()->createResultCollection($data, 'createListItem'); + } + + /** + * Get the list of favorite movies for an account. + * + * @param string $accountId + * @param array $parameters + * @param array $headers + * @return ResultCollection + */ + public function getFavoriteMovies($accountId, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getFavoriteMovies($accountId, $parameters, $headers); + return $this->getFactory()->createResultCollection($data, 'createMovie'); + } + + + /** + * Add or remove a movie to an accounts favorite list. + * + * @param string $accountId + * @param int|Movie $movie + * @param boolean $isFavorite + * @return ResultCollection + */ + public function favorite($accountId, $movie, $isFavorite = true) + { + if ($movie instanceof Movie) { + $movie = $movie->getId(); + } + + $data = $this->getApi()->favorite($accountId, $movie, $isFavorite); + return $this->getFactory()->createStatusResult($data); + } + + /** + * Get the list of rated movies (and associated rating) for an account. + * + * @param string $accountId + * @param array $parameters + * @param array $headers + * @return ResultCollection + */ + public function getRatedMovies($accountId, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getRatedMovies($accountId, $parameters, $headers); + return $this->getFactory()->createResultCollection($data, 'createMovie'); + } + + /** + * Get the list of movies on an accounts watchlist. + * + * @param string $accountId + * @param array $parameters + * @param array $headers + * @return ResultCollection + */ + public function getMovieWatchlist($accountId, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getMovieWatchlist($accountId, $parameters, $headers); + return $this->getFactory()->createResultCollection($data, 'createMovie'); + } + + /** + * Add or remove a movie to an accounts watch list. + * + * @param string $accountId + * @param int|Movie $movie + * @param boolean $isOnWatchlist + * @return ResultCollection + */ + public function watchlist($accountId, $movie, $isOnWatchlist = true) + { + if ($movie instanceof Movie) { + $movie = $movie->getId(); + } + + $data = $this->getApi()->watchlist($accountId, $movie, $isOnWatchlist); + return $this->getFactory()->createStatusResult($data); + } + + /** + * Return the Collection API Class + * + * @return \Tmdb\Api\Account + */ + public function getApi() + { + return $this->getClient()->getAccountApi(); + } + + /** + * @return AccountFactory + */ + public function getFactory() + { + return new AccountFactory(); + } +} diff --git a/modules/Tmdb/Repository/AuthenticationRepository.php b/modules/Tmdb/Repository/AuthenticationRepository.php new file mode 100644 index 00000000..141ba954 --- /dev/null +++ b/modules/Tmdb/Repository/AuthenticationRepository.php @@ -0,0 +1,99 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\AuthenticationFactory; +use Tmdb\RequestToken; + +/** + * Class AuthenticationRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#authentication + */ +class AuthenticationRepository extends AbstractRepository { + + /** + * This method is used to generate a valid request token for user based authentication. + * A request token is required in order to request a session id. + * + * You can generate any number of request tokens but they will expire after 60 minutes. + * As soon as a valid session id has been created the token will be destroyed. + * + * @return RequestToken + */ + public function getRequestToken() + { + $data = $this->getApi()->getNewToken(); + return $this->getFactory()->createRequestToken($data); + } + + /** + * This method is used to generate a session id for user based authentication. + * A session id is required in order to use any of the write methods. + * + * @param RequestToken $requestToken + * @return RequestToken + */ + public function getSessionToken(RequestToken $requestToken) + { + $data = $this->getApi()->getNewSession($requestToken->getToken()); + return $this->getFactory()->createSessionToken($data); + } + + /** + * This method is used to generate a guest session id. + * + * A guest session can be used to rate movies without having a registered TMDb user account. + * You should only generate a single guest session per user (or device) as you will be able to + * attach the ratings to a TMDb user account in the future. + * + * There is also IP limits in place so you should always make sure it's the end user doing the guest session actions. + * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. + * + * @return RequestToken + */ + public function getGuestSessionToken() + { + $data = $this->getApi()->getNewGuestSession(); + return $this->getFactory()->createGuestSessionToken($data); + } + + /** + * Authenticate request token, redirects the user + * + * @param RequestToken $requestToken + * @return void + */ + public function authenticateRequestToken(RequestToken $requestToken) + { + $this->getApi()->authenticateRequestToken($requestToken->getToken()); + } + + /** + * Return the Collection API Class + * + * @return \Tmdb\Api\Authentication + */ + public function getApi() + { + return $this->getClient()->getAuthenticationApi(); + } + + /** + * @return AuthenticationFactory + */ + public function getFactory() + { + return new AuthenticationFactory(); + } +} diff --git a/modules/Tmdb/Repository/CertificationRepository.php b/modules/Tmdb/Repository/CertificationRepository.php new file mode 100644 index 00000000..b7cdb357 --- /dev/null +++ b/modules/Tmdb/Repository/CertificationRepository.php @@ -0,0 +1,57 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\CertificationFactory; +use Tmdb\Model\Collection as ApiCollection; + +/** + * Class CertificationRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#certifications + */ +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(); + } +} diff --git a/modules/Tmdb/Repository/ChangesRepository.php b/modules/Tmdb/Repository/ChangesRepository.php new file mode 100644 index 00000000..a2e34f03 --- /dev/null +++ b/modules/Tmdb/Repository/ChangesRepository.php @@ -0,0 +1,83 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\ChangesFactory; +use Tmdb\Model\Collection\People; +use Tmdb\Model\Query\ChangesQuery; + +/** + * Class ChangesRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#changes + */ +class ChangesRepository extends AbstractRepository { + /** + * 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 ChangesQuery $query + * @param array $headers + * @return \Tmdb\Model\Common\GenericCollection + */ + public function getMovieChanges(ChangesQuery $query, array $headers = array()) { + $data = $this->getApi()->getMovieChanges($query->toArray(), $headers); + + return $this->getFactory()->createResultCollection($data); + } + + /** + * 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 ChangesQuery $query + * @param array $headers + * @return People + */ + public function getPeopleChanges(ChangesQuery $query, array $headers = array()) { + $data = $this->getApi()->getPersonChanges($query->toArray(), $headers); + + return $this->getFactory()->createResultCollection($data); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Changes + */ + public function getApi() + { + return $this->getClient()->getChangesApi(); + } + + /** + * Changes does not support a generic factory + * + * @return ChangesFactory + */ + public function getFactory(){ + return new ChangesFactory(); + } +} diff --git a/modules/Tmdb/Repository/CollectionRepository.php b/modules/Tmdb/Repository/CollectionRepository.php new file mode 100644 index 00000000..68e75cf9 --- /dev/null +++ b/modules/Tmdb/Repository/CollectionRepository.php @@ -0,0 +1,112 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Client; +use Tmdb\Factory\CollectionFactory; +use Tmdb\Factory\ImageFactory; +use Tmdb\Model\Collection as ApiCollection; +use Tmdb\Model\Collection\QueryParameter\AppendToResponse; + +/** + * Class CollectionRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#collections + */ +class CollectionRepository extends AbstractRepository { + + private $imageFactory; + + public function __construct(Client $client) + { + parent::__construct($client); + + $this->imageFactory = new ImageFactory(); + } + + /** + * 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), $headers); + return $this->getFactory()->create($data); + } + + /** + * Get all of the images for a particular collection by collection id. + * + * @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); + $movie = $this->getFactory()->create(array('images' => $data)); + + return $movie->getImages(); + } + + /** + * Return the Collection API Class + * + * @return \Tmdb\Api\Collections + */ + public function getApi() + { + return $this->getClient()->getCollectionsApi(); + } + + /** + * @return CollectionFactory + */ + public function getFactory() + { + return new CollectionFactory(); + } + + /** + * @param mixed $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return mixed + */ + public function getImageFactory() + { + return $this->imageFactory; + } +} diff --git a/modules/Tmdb/Repository/CompanyRepository.php b/modules/Tmdb/Repository/CompanyRepository.php new file mode 100644 index 00000000..76d09e2d --- /dev/null +++ b/modules/Tmdb/Repository/CompanyRepository.php @@ -0,0 +1,103 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\CompanyFactory; +use Tmdb\Factory\MovieFactory; +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Company; +use Tmdb\Model\Movie; + +/** + * Class CompanyRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#movies + */ +class CompanyRepository extends AbstractRepository { + + /** + * Load a company with the given identifier + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Company + */ + public function load($id, array $parameters = array(), array $headers = array()) { + $data = $this->getApi()->getCompany($id, $this->parseQueryParameters($parameters), $headers); + + return $this->getFactory()->create($data); + } + + /** + * Get the list of movies associated with a particular company. + * + * @param integer $id + * @param array $parameters + * @param array $headers + * @return GenericCollection|Movie[] + */ + public function getMovies($id, array $parameters = array(), array $headers = array()) + { + return $this->createMovieCollection( + $this->getApi()->getMovies($id, $this->parseQueryParameters($parameters), $headers) + ); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Companies + */ + public function getApi() + { + return $this->getClient()->getCompaniesApi(); + } + + /** + * @return CompanyFactory + */ + public function getFactory() + { + return new CompanyFactory(); + } + + /** + * @return MovieFactory + */ + public function getMovieFactory() + { + return new MovieFactory(); + } + + /** + * Create an collection of an array + * + * @param $data + * @return Movie[] + */ + public function createMovieCollection($data){ + $collection = new ResultCollection(); + + if (array_key_exists('results', $data)) { + $data = $data['results']; + } + + foreach($data as $item) { + $collection->add(null, $this->getMovieFactory()->create($item)); + } + + return $collection; + } +} diff --git a/modules/Tmdb/Repository/ConfigurationRepository.php b/modules/Tmdb/Repository/ConfigurationRepository.php new file mode 100644 index 00000000..dd630e20 --- /dev/null +++ b/modules/Tmdb/Repository/ConfigurationRepository.php @@ -0,0 +1,54 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\ConfigurationFactory; +use Tmdb\Model\Configuration; + +/** + * Class ConfigurationRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#configuration + */ +class ConfigurationRepository extends AbstractRepository { + + /** + * Load up TMDB Configuration + * + * @param array $headers + * @return Configuration + */ + public function load(array $headers = array()) { + $data = $this->getApi()->getConfiguration($headers); + + return $this->getFactory()->create($data); + } + + /** + * Return the Movies API Class + * + * @return \Tmdb\Api\Configuration + */ + public function getApi() + { + return $this->getClient()->getConfigurationApi(); + } + + /** + * @return ConfigurationFactory + */ + public function getFactory() + { + return new ConfigurationFactory(); + } +} diff --git a/modules/Tmdb/Repository/CreditsRepository.php b/modules/Tmdb/Repository/CreditsRepository.php new file mode 100644 index 00000000..40e51385 --- /dev/null +++ b/modules/Tmdb/Repository/CreditsRepository.php @@ -0,0 +1,58 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\CompanyFactory; +use Tmdb\Factory\CreditsFactory; +use Tmdb\Model\Company; +use Tmdb\Model\Movie; + +/** + * Class CreditsRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#credits + */ +class CreditsRepository extends AbstractRepository { + + /** + * Load a company with the given identifier + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Company + */ + public function load($id, array $parameters = array(), array $headers = array()) { + $data = $this->getApi()->getCredit($id, $this->parseQueryParameters($parameters), $headers); + + return $this->getFactory()->create($data); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Credits + */ + public function getApi() + { + return $this->getClient()->getCreditsApi(); + } + + /** + * @return CompanyFactory + */ + public function getFactory() + { + return new CreditsFactory(); + } +} diff --git a/modules/Tmdb/Repository/DiscoverRepository.php b/modules/Tmdb/Repository/DiscoverRepository.php new file mode 100644 index 00000000..46e468eb --- /dev/null +++ b/modules/Tmdb/Repository/DiscoverRepository.php @@ -0,0 +1,99 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Exception\NotImplementedException; +use Tmdb\Exception\RuntimeException; +use Tmdb\Factory\MovieFactory; +use Tmdb\Factory\TvFactory; +use Tmdb\Model\Movie; +use Tmdb\Model\Query\Discover\DiscoverMoviesQuery; +use Tmdb\Model\Query\Discover\DiscoverTvQuery; +use Tmdb\Model\Tv; + +/** + * Class DiscoverRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#discover + */ +class DiscoverRepository extends AbstractRepository { + /** + * Discover movies by different types of data like average rating, number of votes, genres and certifications. + * + * @param DiscoverMoviesQuery $query + * @param array $headers + * @throws RuntimeException when certification_country is set but certification.lte is not given + * @return Movie[] + */ + public function discoverMovies(DiscoverMoviesQuery $query, array $headers = array()) { + $query = $query->toArray(); + + if (array_key_exists('certification_country', $query) && !array_key_exists('certification.lte', $query)) { + throw new RuntimeException('When the certification_country option is given the certification.lte option is required.'); + } + + $data = $this->getApi()->discoverMovies($query, $headers); + + return $this->getMovieFactory()->createResultCollection($data); + } + + /** + * Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates. + * + * @param DiscoverTvQuery $query + * @param array $headers + * @return Tv[] + * @return \Tmdb\Model\Common\GenericCollection + */ + public function discoverTv(DiscoverTvQuery $query, array $headers = array()) { + $data = $this->getApi()->discoverTv($query->toArray(), $headers); + + return $this->getTvFactory()->createResultCollection($data); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Discover + */ + public function getApi() + { + return $this->getClient()->getDiscoverApi(); + } + + /** + * Discover currently does not offer an factory + * + * @throws NotImplementedException + * @return null|\Tmdb\Factory\FactoryInterface + */ + public function getFactory(){ + throw new NotImplementedException('Discover does not support a generic factory.'); + } + + /** + * @return \Tmdb\Factory\MovieFactory + */ + public function getMovieFactory() + { + return new MovieFactory(); + } + + /** + * @return \Tmdb\Factory\TvFactory + */ + public function getTvFactory() + { + return new TvFactory(); + } +} diff --git a/modules/Tmdb/Repository/FindRepository.php b/modules/Tmdb/Repository/FindRepository.php new file mode 100644 index 00000000..c8282491 --- /dev/null +++ b/modules/Tmdb/Repository/FindRepository.php @@ -0,0 +1,55 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\FindFactory; +use Tmdb\Model\Find; + +/** + * Class FindRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#find + */ +class FindRepository extends AbstractRepository { + /** + * Find something + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Find + */ + public function find($id, array $parameters = array(), array $headers = array()) { + return $this->getFactory()->create( + $this->getApi()->find($id,$parameters, $headers) + ); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Find + */ + public function getApi() + { + return $this->getClient()->getFindApi(); + } + + /** + * @return FindFactory + */ + public function getFactory() + { + return new FindFactory(); + } +} \ No newline at end of file diff --git a/modules/Tmdb/Repository/GenreRepository.php b/modules/Tmdb/Repository/GenreRepository.php new file mode 100644 index 00000000..b82b1fab --- /dev/null +++ b/modules/Tmdb/Repository/GenreRepository.php @@ -0,0 +1,93 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\GenreFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Genre; + +/** + * Class GenreRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#genres + */ +class GenreRepository extends AbstractRepository { + /** + * Load a genre with the given identifier + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Genre + */ + public function load($id, array $parameters = array(), array $headers = array()) { + return $this->loadCollection($parameters, $headers)->filterId($id); + } + + /** + * Get the list of genres. + * + * @param array $parameters + * @param array $headers + * @return GenericCollection + */ + public function loadCollection(array $parameters = array(), array $headers = array()) + { + return $this->createCollection( + $this->getApi()->getGenres($parameters, $headers) + ); + } + + /** + * Get the list of movies for a particular genre by id. By default, only movies with 10 or more votes are included. + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Genre[] + */ + public function getMovies($id, array $parameters = array(), array $headers = array()) { + return $this->getFactory()->createResultCollection( + $this->getApi()->getMovies($id, $parameters, $headers), + 'createMovie' + ); + } + + /** + * Create an collection of an array + * + * @param $data + * @return GenericCollection|Genre[] + */ + private function createCollection($data){ + return $this->getFactory()->createCollection($data); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Genres + */ + public function getApi() + { + return $this->getClient()->getGenresApi(); + } + + /** + * @return GenreFactory + */ + public function getFactory() + { + return new GenreFactory(); + } +} \ No newline at end of file diff --git a/modules/Tmdb/Repository/JobsRepository.php b/modules/Tmdb/Repository/JobsRepository.php new file mode 100644 index 00000000..5444de90 --- /dev/null +++ b/modules/Tmdb/Repository/JobsRepository.php @@ -0,0 +1,75 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\JobsFactory; +use Tmdb\Model\Collection\Jobs; +use Tmdb\Model\Job; + +/** + * Class JobsRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#jobs + */ +class JobsRepository extends AbstractRepository { + /** + * @param array $parameters + * @param array $headers + * @return Job + */ + public function load(array $parameters = array(), array $headers = array()) { + return $this->loadCollection($parameters, $headers); + } + + /** + * Get the list of jobs. + * + * @param array $parameters + * @param array $headers + * @return Jobs|Job[] + */ + public function loadCollection(array $parameters = array(), array $headers = array()) + { + return $this->createCollection( + $this->getApi()->getJobs($parameters, $headers) + ); + } + + /** + * Create an collection of an array + * + * @param $data + * @return Jobs|Job[] + */ + private function createCollection($data){ + return $this->getFactory()->createCollection($data); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Jobs + */ + public function getApi() + { + return $this->getClient()->getJobsApi(); + } + + /** + * @return JobsFactory + */ + public function getFactory() + { + return new JobsFactory(); + } +} \ No newline at end of file diff --git a/modules/Tmdb/Repository/KeywordRepository.php b/modules/Tmdb/Repository/KeywordRepository.php new file mode 100644 index 00000000..b85ba66e --- /dev/null +++ b/modules/Tmdb/Repository/KeywordRepository.php @@ -0,0 +1,71 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\KeywordFactory; +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Keyword; + +/** + * Class KeywordRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#keywords + */ +class KeywordRepository extends AbstractRepository { + /** + * Get the basic information for a specific keyword id. + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Keyword + */ + public function load($id, array $parameters = array(), array $headers = array()) { + return $this->getFactory()->create( + $this->getApi()->getKeyword($id, $parameters, $headers) + ); + } + + /** + * Get the list of movies for a particular keyword by id. By default, only movies with 10 or more votes are included. + * + * @param $id + * @param array $parameters + * @param array $headers + * @return ResultCollection|Keyword[] + */ + public function getMovies($id, array $parameters = array(), array $headers = array()) { + return $this->getFactory()->createResultCollection( + $this->getApi()->getMovies($id, $parameters, $headers), + 'createMovie' + ); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Keywords + */ + public function getApi() + { + return $this->getClient()->getKeywordsApi(); + } + + /** + * @return KeywordFactory + */ + public function getFactory() + { + return new KeywordFactory(); + } +} \ No newline at end of file diff --git a/modules/Tmdb/Repository/ListRepository.php b/modules/Tmdb/Repository/ListRepository.php new file mode 100644 index 00000000..92f90954 --- /dev/null +++ b/modules/Tmdb/Repository/ListRepository.php @@ -0,0 +1,129 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\ListFactory; +use Tmdb\Model\Lists\ItemStatus; +use Tmdb\Model\Lists; + +/** + * Class ListRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#lists + */ +class ListRepository extends AbstractRepository { + /** + * Get a list by id. + * + * @param string $id + * @param array $parameters + * @param array $headers + * @return Lists + */ + public function load($id, array $parameters = array(), array $headers = array()) { + return $this->getFactory()->create( + $this->getApi()->getList($id, $parameters, $headers) + ); + } + + /** + * Check to see if a movie ID is already added to a list. + * + * @param string $id + * @param int $mediaId + * @param array $parameters + * @param array $headers + * @return ItemStatus + */ + public function getItemStatus($id, $mediaId, array $parameters = array(), array $headers = array()) + { + return $this->getFactory()->createItemStatus( + $this->getApi()->getItemStatus($id, $mediaId, $parameters, $headers) + ); + } + + /** + * This method lets users create a new list. A valid session id is required. + * + * @param string $name + * @param string $description + * @param array $parameters + * @param array $headers + * @return string The list id + */ + public function createList($name, $description = null, array $parameters = array(), array $headers = array()) + { + return $this->getFactory()->createResultWithListId( + $this->getApi()->createList($name, $description, $parameters, $headers) + ); + } + + /** + * This method lets users add new movies to a list that they created. A valid session id is required. + * + * @param string $id + * @param int $mediaId + * @return ItemStatus + */ + public function add($id, $mediaId) + { + return $this->getFactory()->createResult( + $this->getApi()->addMediaToList($id, $mediaId) + ); + } + + /** + * This method lets users delete movies from a list that they created. A valid session id is required. + * + * @param string $id + * @param int $mediaId + * @return ItemStatus + */ + public function remove($id, $mediaId) + { + return $this->getFactory()->createResult( + $this->getApi()->removeMediaFromList($id, $mediaId) + ); + } + + /** + * This method lets users delete a list that they created. A valid session id is required. + * + * @param string $id + * @return ItemStatus + */ + public function deleteList($id) + { + return $this->getFactory()->createResult( + $this->getApi()->deleteList($id) + ); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Lists + */ + public function getApi() + { + return $this->getClient()->getListsApi(); + } + + /** + * @return ListFactory + */ + public function getFactory() + { + return new ListFactory(); + } +} \ No newline at end of file diff --git a/modules/Tmdb/Repository/MovieRepository.php b/modules/Tmdb/Repository/MovieRepository.php new file mode 100644 index 00000000..37288a2c --- /dev/null +++ b/modules/Tmdb/Repository/MovieRepository.php @@ -0,0 +1,441 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\ImageFactory; +use Tmdb\Factory\Movie\AlternativeTitleFactory; +use Tmdb\Factory\MovieFactory; +use Tmdb\Factory\PeopleFactory; +use Tmdb\Model\Common\GenericCollection; +use Tmdb\Model\Movie; +use Tmdb\Model\Movie\QueryParameter\AppendToResponse; + +/** + * Class MovieRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#movies + */ +class MovieRepository extends AbstractRepository { + + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * @var AlternativeTitleFactory + */ + private $alternativeTitleFactory; + + /** + * @var PeopleFactory + */ + private $peopleFactory; + + /** + * Load a movie 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 null|\Tmdb\Model\AbstractModel + */ + public function load($id, array $parameters = array(), array $headers = array()) + { + + if (empty($parameters)) { + $parameters = array( + new AppendToResponse(array( + AppendToResponse::ALTERNATIVE_TITLES, + AppendToResponse::CHANGES, + AppendToResponse::CREDITS, + AppendToResponse::IMAGES, + AppendToResponse::KEYWORDS, + AppendToResponse::LISTS, + AppendToResponse::RELEASES, + AppendToResponse::REVIEWS, + AppendToResponse::SIMILAR_MOVIES, + AppendToResponse::TRAILERS, + AppendToResponse::TRANSLATIONS, + )) + ); + } + + $data = $this->getApi()->getMovie($id, $this->parseQueryParameters($parameters), $headers); + + return $this->getFactory()->create($data); + } + + /** + * Get the alternative titles for a specific movie id. + * + * @param $id + * @param $parameters + * @param $headers + * @return GenericCollection + */ + public function getAlternativeTitles($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getAlternativeTitles($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('alternative_titles' => $data)); + + return $movie->getAlternativeTitles(); + } + + /** + * Get the cast and crew information for a specific movie id. + * + * @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); + $movie = $this->getFactory()->create(array('credits' => $data)); + + return $movie->getCredits(); + } + + /** + * Get the images (posters and backdrops) for a specific movie id. + * + * @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); + $movie = $this->getFactory()->create(array('images' => $data)); + + return $movie->getImages(); + } + + /** + * Get the plot keywords for a specific movie id. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getKeywords($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getKeywords($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('keywords' => $data)); + + return $movie->getKeywords(); + } + + /** + * Get the release date and certification information by country for a specific movie id. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getReleases($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getReleases($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('releases' => $data)); + + return $movie->getReleases(); + } + + /** + * Get the trailers for a specific movie id. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getTrailers($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getTrailers($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('trailers' => $data)); + + return $movie->getTrailers(); + } + + /** + * Get the translations for a specific movie id. + * + * @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); + $movie = $this->getFactory()->create(array('translations' => $data)); + + return $movie->getTranslations(); + } + + /** + * Get the similar movies for a specific movie id. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getSimilarMovies($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getSimilarMovies($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('similar_movies' => $data)); + + return $movie->getSimilarMovies(); + } + + /** + * Get the reviews for a particular movie id. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getReviews($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getReviews($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('reviews' => $data)); + + return $movie->getReviews(); + } + + /** + * Get the lists that the movie belongs to. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getLists($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getLists($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('lists' => $data)); + + return $movie->getLists(); + } + + /** + * Get the changes for a specific movie id. + * Changes are grouped by key, and ordered by date in descending order. + * + * By default, only the last 24 hours of changes are returned. + * The maximum number of days that can be returned in a single request is 14. + * + * The language is present on fields that are translatable. + * + * @param $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getChanges($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getChanges($id, $this->parseQueryParameters($parameters), $headers); + $movie = $this->getFactory()->create(array('changes' => $data)); + + return $movie->getChanges(); + } + + + /** + * Get the latest movie. + * + * @param array $options + * @return null|\Tmdb\Model\AbstractModel + */ + public function getLatest(array $options = array()) + { + return $this->getFactory()->create( + $this->getApi()->getLatest($options) + ); + } + + /** + * 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 Movie[] + */ + public function getUpcoming(array $options = array()) + { + return $this->getFactory()->createResultCollection( + $this->getApi()->getUpcoming($options) + ); + } + + /** + * 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 Movie[] + */ + public function getNowPlaying(array $options = array()) + { + return $this->getFactory()->createResultCollection( + $this->getApi()->getNowPlaying($options) + ); + } + + /** + * Get the list of popular movies on The Movie Database. This list refreshes every day. + * + * @param array $options + * @return Movie[] + */ + public function getPopular(array $options = array()) + { + return $this->getFactory()->createResultCollection( + $this->getApi()->getPopular($options) + ); + } + + /** + * 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 Movie[] + */ + public function getTopRated(array $options = array()) + { + return $this->getFactory()->createResultCollection( + $this->getApi()->getTopRated($options) + ); + } + + /** + * This method lets users get the status of whether or not the movie has been rated or added to their favourite or watch lists. A valid session id is required. + * + * @param integer $id + * @return Movie[] + */ + public function getAccountStates($id) + { + return $this->getFactory()->createAccountStates( + $this->getApi()->getAccountStates($id) + ); + } + + /** + * This method lets users rate a movie. A valid session id or guest session id is required. + * + * @param integer $id + * @param float $rating + * @return Movie[] + */ + public function rate($id, $rating) + { + return $this->getFactory()->createResult( + $this->getApi()->rateMovie($id, $rating) + ); + } + + /** + * Return the Movies API Class + * + * @return \Tmdb\Api\Movies + */ + public function getApi() + { + return $this->getClient()->getMoviesApi(); + } + + /** + * Return the Movie Factory + * + * @return MovieFactory + */ + public function getFactory() + { + return new MovieFactory(); + } + + /** + * Create an collection of an array + * + * @param $data + * @return Movie[] + */ + private function createCollection($data){ + return $this->getFactory()->createCollection($data); + } + + /** + * @param mixed $alternativeTitleFactory + * @return $this + */ + public function setAlternativeTitleFactory($alternativeTitleFactory) + { + $this->alternativeTitleFactory = $alternativeTitleFactory; + return $this; + } + + /** + * @return mixed + */ + public function getAlternativeTitleFactory() + { + return $this->alternativeTitleFactory; + } + + /** + * @param mixed $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return mixed + */ + public function getImageFactory() + { + return $this->imageFactory; + } + + /** + * @param mixed $peopleFactory + * @return $this + */ + public function setPeopleFactory($peopleFactory) + { + $this->peopleFactory = $peopleFactory; + return $this; + } + + /** + * @return mixed + */ + public function getPeopleFactory() + { + return $this->peopleFactory; + } + + +} diff --git a/modules/Tmdb/Repository/NetworkRepository.php b/modules/Tmdb/Repository/NetworkRepository.php new file mode 100644 index 00000000..eb6407ee --- /dev/null +++ b/modules/Tmdb/Repository/NetworkRepository.php @@ -0,0 +1,58 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\NetworkFactory; +use Tmdb\Model\Network; + +/** + * Class NetworkRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#networks + */ +class NetworkRepository extends AbstractRepository { + /** + * This method is used to retrieve the basic information about a TV network. + * + * You can use this ID to search for TV shows with the discover. + * At this time we don't have much but this will be fleshed out over time. + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Network + */ + public function load($id, array $parameters = array(), array $headers = array()) { + return $this->getFactory()->create( + $this->getApi()->getNetwork($id, $parameters, $headers) + ); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Networks + */ + public function getApi() + { + return $this->getClient()->getNetworksApi(); + } + + /** + * @return NetworkFactory + */ + public function getFactory() + { + return new NetworkFactory(); + } +} \ No newline at end of file diff --git a/modules/Tmdb/Repository/PeopleRepository.php b/modules/Tmdb/Repository/PeopleRepository.php new file mode 100644 index 00000000..f9fcf4b3 --- /dev/null +++ b/modules/Tmdb/Repository/PeopleRepository.php @@ -0,0 +1,202 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\PeopleFactory; +use Tmdb\Model\Person; +use Tmdb\Model\Person\QueryParameter\AppendToResponse; + +/** + * Class PeopleRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#people + * + * @todo implement the new methods + */ +class PeopleRepository extends AbstractRepository { + /** + * Load a person with the given identifier + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Person + */ + public function load($id, array $parameters = array(), array $headers = array()) { + + if (empty($parameters) && $parameters !== false) { + // Load a no-nonsense default set + $parameters = array( + new AppendToResponse(array( + AppendToResponse::IMAGES, + AppendToResponse::CHANGES, + AppendToResponse::COMBINED_CREDITS, + AppendToResponse::MOVIE_CREDITS, + AppendToResponse::TV_CREDITS, + AppendToResponse::EXTERNAL_IDS + )) + ); + } + + $data = $this->getApi()->getPerson($id, $this->parseQueryParameters($parameters), $headers); + 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(); + } + + /** + * Get the external ids for a specific person id. + * + * @param $id + * @return null|\Tmdb\Model\AbstractModel + */ + public function getExternalIds($id) + { + $data = $this->getApi()->getExternalIds($id); + $person = $this->getFactory()->create(array('external_ids' => $data)); + + return $person->getExternalIds(); + } + + /** + * Get the images for a specific person id. + * + * @param $id + * @return null|\Tmdb\Model\AbstractModel + */ + public function getImages($id) + { + $data = $this->getApi()->getCombinedCredits($id); + $person = $this->getFactory()->create(array('images' => $data)); + + return $person->getImages(); + } + + /** + * Get the changes for a specific person id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * By default, only the last 24 hours of changes are returned. + * The maximum number of days that can be returned in a single request is 14. + * The language is present on fields that are translatable. + * + * @param $id + * @param array $parameters + * @param array $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getChanges($id, array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getChanges($id, $this->parseQueryParameters($parameters), $headers); + $person = $this->getFactory()->create(array('changes' => $data)); + + return $person->getChanges(); + } + + /** + * Get the list of popular people on The Movie Database. + * + * This list refreshes every day. + * + * @param array $parameters + * @param array $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getPopular(array $parameters = array(), array $headers = array()) + { + $data = $this->getApi()->getPopular($parameters, $headers); + return $this->getFactory()->createResultCollection($data); + } + + /** + * Get the latest person id. + * + * @return null|\Tmdb\Model\AbstractModel + */ + public function getLatest() + { + $data = $this->getApi()->getLatest(); + return $this->getFactory()->create($data); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\People + */ + public function getApi() + { + return $this->getClient()->getPeopleApi(); + } + + /** + * @return PeopleFactory + */ + public function getFactory() + { + return new PeopleFactory(); + } +} diff --git a/modules/Tmdb/Repository/ReviewRepository.php b/modules/Tmdb/Repository/ReviewRepository.php new file mode 100644 index 00000000..2695d9fb --- /dev/null +++ b/modules/Tmdb/Repository/ReviewRepository.php @@ -0,0 +1,55 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\ReviewFactory; +use Tmdb\Model\Review; + +/** + * Class ReviewRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#reviews + */ +class ReviewRepository extends AbstractRepository { + /** + * Get the full details of a review by ID. + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Review + */ + public function load($id, array $parameters = array(), array $headers = array()) { + return $this->getFactory()->create( + $this->getApi()->getReview($id, $parameters, $headers) + ); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Reviews + */ + public function getApi() + { + return $this->getClient()->getReviewsApi(); + } + + /** + * @return ReviewFactory + */ + public function getFactory() + { + return new ReviewFactory(); + } +} \ No newline at end of file diff --git a/modules/Tmdb/Repository/SearchRepository.php b/modules/Tmdb/Repository/SearchRepository.php new file mode 100644 index 00000000..f06541c3 --- /dev/null +++ b/modules/Tmdb/Repository/SearchRepository.php @@ -0,0 +1,345 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Client; +use Tmdb\Exception\NotImplementedException; +use Tmdb\Factory\CollectionFactory; +use Tmdb\Factory\CompanyFactory; +use Tmdb\Factory\KeywordFactory; +use Tmdb\Factory\Movie\ListItemFactory; +use Tmdb\Factory\MovieFactory; +use Tmdb\Factory\PeopleFactory; +use Tmdb\Factory\TvFactory; +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Collection; +use Tmdb\Model\Company; +use Tmdb\Model\Keyword; +use Tmdb\Model\Movie; +use Tmdb\Model\Person; +use Tmdb\Model\Search\SearchQuery\CollectionSearchQuery; +use Tmdb\Model\Search\SearchQuery\CompanySearchQuery; +use Tmdb\Model\Search\SearchQuery\KeywordSearchQuery; +use Tmdb\Model\Search\SearchQuery\ListSearchQuery; +use Tmdb\Model\Search\SearchQuery\MovieSearchQuery; +use Tmdb\Model\Search\SearchQuery\PersonSearchQuery; +use Tmdb\Model\Search\SearchQuery\TvSearchQuery; +use Tmdb\Model\Search\SearchQuery; +use Tmdb\Model\Tv; + +/** + * Class SearchRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#search + */ +class SearchRepository extends AbstractRepository { + + /** + * @var MovieFactory + */ + private $movieFactory; + + /** + * @var CollectionFactory + */ + private $collectionFactory; + + /** + * @var TvFactory + */ + private $tvFactory; + + /** + * @var PeopleFactory + */ + private $peopleFactory; + + /** + * @var ListItemFactory + */ + private $listItemFactory; + + /** + * @var CompanyFactory + */ + private $companyFactory; + + /** + * @var KeywordFactory + */ + private $keywordFactory; + + public function __construct(Client $client) + { + parent::__construct($client); + + $this->movieFactory = new MovieFactory(); + $this->collectionFactory = new CollectionFactory(); + $this->tvFactory = new TvFactory(); + $this->peopleFactory = new PeopleFactory(); + $this->listItemFactory = new ListItemFactory(); + $this->companyFactory = new CompanyFactory(); + $this->keywordFactory = new KeywordFactory(); + } + + /** + * @param string $query + * @param MovieSearchQuery $parameters + * @param array $headers + * + * @return ResultCollection|Movie[] + */ + public function searchMovie($query, MovieSearchQuery $parameters, array $headers = array()) { + $data = $this->getApi()->searchMovies($query, $this->getParameters($parameters), $headers); + + return $this->getMovieFactory()->createResultCollection($data); + } + + /** + * @param string $query + * @param CollectionSearchQuery $parameters + * @param array $headers + * + * @return ResultCollection|Collection[] + */ + public function searchCollection($query, CollectionSearchQuery $parameters, array $headers = array()) { + $data = $this->getApi()->searchCollection($query, $this->getParameters($parameters), $headers); + + return $this->getCollectionFactory()->createResultCollection($data); + } + + /** + * @param string $query + * @param TvSearchQuery $parameters + * @param array $headers + * + * @return ResultCollection|Tv[] + */ + public function searchTv($query, TvSearchQuery $parameters, array $headers = array()) { + $data = $this->getApi()->searchTv($query, $this->getParameters($parameters), $headers); + + return $this->getTvFactory()->createResultCollection($data); + } + + /** + * @param string $query + * @param PersonSearchQuery $parameters + * @param array $headers + * + * @return ResultCollection|Person[] + */ + public function searchPerson($query, PersonSearchQuery $parameters, array $headers = array()) { + $data = $this->getApi()->searchPersons($query, $this->getParameters($parameters), $headers); + + return $this->getPeopleFactory()->createResultCollection($data); + } + + /** + * @param string $query + * @param ListSearchQuery $parameters + * @param array $headers + * + * @return ResultCollection + */ + public function searchList($query, ListSearchQuery $parameters, array $headers = array()) { + $data = $this->getApi()->searchList($query, $this->getParameters($parameters), $headers); + + return $this->getListitemFactory()->createResultCollection($data); + } + + /** + * @param string $query + * @param CompanySearchQuery $parameters + * @param array $headers + * + * @return ResultCollection|Company[] + */ + public function searchCompany($query, CompanySearchQuery $parameters, array $headers = array()) { + $data = $this->getApi()->searchTv($query, $this->getParameters($parameters), $headers); + + return $this->getCompanyFactory()->createResultCollection($data); + } + + + /** + * @param string $query + * @param KeywordSearchQuery $parameters + * @param array $headers + * + * @return ResultCollection|Keyword[] + */ + public function searchKeyword($query, KeywordSearchQuery $parameters, array $headers = array()) { + $data = $this->getApi()->searchKeyword($query, $this->getParameters($parameters), $headers); + + return $this->getKeywordFactory()->createResultCollection($data); + } + + /** + * Convert parameters back to an array + * + * @param array $parameters + * @return array + */ + private function getParameters($parameters = array()) { + if ($parameters instanceof SearchQuery) { + return $parameters->toArray(); + } + + return $parameters; + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Search + */ + public function getApi() + { + return $this->getClient()->getSearchApi(); + } + + /** + * SearchRepository does not support a generic factory + * + * @throws NotImplementedException + */ + public function getFactory(){ + throw new NotImplementedException('SearchRepository does not support a generic factory.'); + } + + /** + * @param \Tmdb\Factory\MovieFactory $movieFactory + * @return $this + */ + public function setMovieFactory($movieFactory) + { + $this->movieFactory = $movieFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\MovieFactory + */ + public function getMovieFactory() + { + return $this->movieFactory; + } + + /** + * @param \Tmdb\Factory\CollectionFactory $collectionFactory + * @return $this + */ + public function setCollectionFactory($collectionFactory) + { + $this->collectionFactory = $collectionFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\CollectionFactory + */ + public function getCollectionFactory() + { + return $this->collectionFactory; + } + + /** + * @param \Tmdb\Factory\CompanyFactory $companyFactory + * @return $this + */ + public function setCompanyFactory($companyFactory) + { + $this->companyFactory = $companyFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\CompanyFactory + */ + public function getCompanyFactory() + { + return $this->companyFactory; + } + + /** + * @param \Tmdb\Factory\KeywordFactory $keywordFactory + * @return $this + */ + public function setKeywordFactory($keywordFactory) + { + $this->keywordFactory = $keywordFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\KeywordFactory + */ + public function getKeywordFactory() + { + return $this->keywordFactory; + } + + /** + * @param \Tmdb\Factory\Movie\ListItemFactory $listItemFactory + * @return $this + */ + public function setListItemFactory($listItemFactory) + { + $this->listItemFactory = $listItemFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\Movie\ListItemFactory + */ + public function getListItemFactory() + { + return $this->listItemFactory; + } + + /** + * @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; + } + + /** + * @param \Tmdb\Factory\TvFactory $tvFactory + * @return $this + */ + public function setTvFactory($tvFactory) + { + $this->tvFactory = $tvFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\TvFactory + */ + public function getTvFactory() + { + return $this->tvFactory; + } +} \ No newline at end of file diff --git a/modules/Tmdb/Repository/TvEpisodeRepository.php b/modules/Tmdb/Repository/TvEpisodeRepository.php new file mode 100644 index 00000000..351c1150 --- /dev/null +++ b/modules/Tmdb/Repository/TvEpisodeRepository.php @@ -0,0 +1,184 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Exception\RuntimeException; +use Tmdb\Factory\TvEpisodeFactory; +use Tmdb\Model\Tv\Episode\QueryParameter\AppendToResponse; +use Tmdb\Model\Tv; +use Tmdb\Model\Tv\Season; +use Tmdb\Model\Tv\Episode; + +/** + * Class TvEpisodeRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#tvepisodes + */ +class TvEpisodeRepository extends AbstractRepository { + + /** + * Load a tv season with the given identifier + * + * If you want to optimize the result set/bandwidth you should define the AppendToResponse parameter + * + * @param $tvShow Tv|integer + * @param $season Season|integer + * @param $episode Episode|integer + * @param $parameters + * @param $headers + * @throws RuntimeException + * @return null|\Tmdb\Model\AbstractModel + */ + public function load($tvShow, $season, $episode, array $parameters = array(), array $headers = array()) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if ($episode instanceof Tv\Episode) { + $episode = $episode->getId(); + } + + if (null == $tvShow || null == $season || null == $episode) { + throw new RuntimeException('Not all required parameters to load an tv episode are present.'); + } + + if (empty($parameters)) { + $parameters = array( + new AppendToResponse(array( + AppendToResponse::CREDITS, + AppendToResponse::EXTERNAL_IDS, + AppendToResponse::IMAGES, + )) + ); + } + + $data = $this->getApi()->getEpisode($tvShow, $season, $episode, $this->parseQueryParameters($parameters), $headers); + + 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 $tvShow + * @param $season + * @param $episode + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getCredits($tvShow, $season, $episode, array $parameters = array(), array $headers = array()) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if ($episode instanceof Tv\Episode) { + $episode = $episode->getId(); + } + + $data = $this->getApi()->getCredits($tvShow, $season, $episode, $this->parseQueryParameters($parameters), $headers); + $episode = $this->getFactory()->create(array('credits' => $data)); + + return $episode->getCredits(); + } + + /** + * Get the external ids that we have stored for a TV series. + * + * @param $tvShow + * @param $season + * @param $episode + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getExternalIds($tvShow, $season, $episode, array $parameters = array(), array $headers = array()) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if ($episode instanceof Tv\Episode) { + $episode = $episode->getId(); + } + + $data = $this->getApi()->getExternalIds($tvShow, $season, $episode, $this->parseQueryParameters($parameters), $headers); + $episode = $this->getFactory()->create(array('external_ids' => $data)); + + return $episode->getExternalIds(); + } + + /** + * Get the images (posters and backdrops) for a TV series. + * + * @param $tvShow + * @param $season + * @param $episode + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getImages($tvShow, $season, $episode, array $parameters = array(), array $headers = array()) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if ($episode instanceof Tv\Episode) { + $episode = $episode->getId(); + } + + $data = $this->getApi()->getImages($tvShow, $season, $episode, $this->parseQueryParameters($parameters), $headers); + $episode = $this->getFactory()->create(array('images' => $data)); + + return $episode->getImages(); + } + + /** + * Return the Seasons API Class + * + * @return \Tmdb\Api\TvEpisode + */ + public function getApi() + { + return $this->getClient()->getTvEpisodeApi(); + } + + /** + * @return TvEpisodeFactory + */ + public function getFactory() + { + return new TvEpisodeFactory(); + } +} diff --git a/modules/Tmdb/Repository/TvRepository.php b/modules/Tmdb/Repository/TvRepository.php new file mode 100644 index 00000000..d455c801 --- /dev/null +++ b/modules/Tmdb/Repository/TvRepository.php @@ -0,0 +1,179 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\TvFactory; +use Tmdb\Model\Tv; +use Tmdb\Model\Tv\QueryParameter\AppendToResponse; + +/** + * Class TvRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#tv + */ +class TvRepository extends AbstractRepository { + + /** + * Load a tv with the given identifier + * + * If you want to optimize the result set/bandwidth you should define the AppendToResponse parameter + * + * @param integer $id + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function load($id, array $parameters = array(), array $headers = array()) + { + + if (empty($parameters)) { + $parameters = array( + new AppendToResponse(array( + AppendToResponse::CREDITS, + AppendToResponse::EXTERNAL_IDS, + AppendToResponse::IMAGES, + AppendToResponse::TRANSLATIONS + )) + ); + } + + $data = $this->getApi()->getTvshow($id, $this->parseQueryParameters($parameters), $headers); + + 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 + * + * @return \Tmdb\Api\Tv + */ + public function getApi() + { + return $this->getClient()->getTvApi(); + } + + /** + * @return TvFactory + */ + public function getFactory() + { + return new TvFactory(); + } + + /** + * Get the list of popular tvs on The Tv Database. This list refreshes every day. + * + * @param array $options + * @return Tv[] + */ + public function getPopular(array $options = array()) + { + return $this->getFactory()->createResultCollection( + $this->getApi()->getPopular($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 getTopRated(array $options = array()) + { + 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) + ); + } +} diff --git a/modules/Tmdb/Repository/TvSeasonRepository.php b/modules/Tmdb/Repository/TvSeasonRepository.php new file mode 100644 index 00000000..85c4044e --- /dev/null +++ b/modules/Tmdb/Repository/TvSeasonRepository.php @@ -0,0 +1,165 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Exception\RuntimeException; +use Tmdb\Factory\TvSeasonFactory; + +use \Tmdb\Model\Tv\Season\QueryParameter\AppendToResponse; +use Tmdb\Model\Tv\Season; +use Tmdb\Model\Tv; + +/** + * Class TvSeasonRepository + * @package Tmdb\Repository + * @see http://docs.themoviedb.apiary.io/#tvseasons + */ +class TvSeasonRepository extends AbstractRepository { + + /** + * Load a tv season with the given identifier + * + * If you want to optimize the result set/bandwidth you should define the AppendToResponse parameter + * + * @param $tvShow + * @param $season + * @param $parameters + * @param $headers + * @throws RuntimeException + * @return null|\Tmdb\Model\AbstractModel + */ + public function load($tvShow, $season, array $parameters = array(), array $headers = array()) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + if (null == $tvShow || null == $season) { + throw new RuntimeException('Not all required parameters to load an tv season are present.'); + } + + if (empty($parameters)) { + $parameters = array( + new AppendToResponse(array( + AppendToResponse::CREDITS, + AppendToResponse::EXTERNAL_IDS, + AppendToResponse::IMAGES, + )) + ); + } + + $data = $this->getApi()->getSeason($tvShow, $season, $this->parseQueryParameters($parameters), $headers); + + 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 $tvShow + * @param $season + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getCredits($tvShow, $season, array $parameters = array(), array $headers = array()) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + $data = $this->getApi()->getCredits($tvShow, $season, $this->parseQueryParameters($parameters), $headers); + $season = $this->getFactory()->create(array('credits' => $data)); + + return $season->getCredits(); + } + + /** + * Get the external ids that we have stored for a TV series. + * + * @param $tvShow + * @param $season + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getExternalIds($tvShow, $season, array $parameters = array(), array $headers = array()) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + $data = $this->getApi()->getExternalIds($tvShow, $season, $this->parseQueryParameters($parameters), $headers); + $season = $this->getFactory()->create(array('external_ids' => $data)); + + return $season->getExternalIds(); + } + + /** + * Get the images (posters and backdrops) for a TV series. + * + * @param $tvShow + * @param $season + * @param $parameters + * @param $headers + * @return null|\Tmdb\Model\AbstractModel + */ + public function getImages($tvShow, $season, array $parameters = array(), array $headers = array()) + { + if ($tvShow instanceof Tv) { + $tvShow = $tvShow->getId(); + } + + if ($season instanceof Season) { + $season = $season->getId(); + } + + $data = $this->getApi()->getImages($tvShow, $season, $this->parseQueryParameters($parameters), $headers); + $season = $this->getFactory()->create(array('images' => $data)); + + return $season->getImages(); + } + + /** + * Return the Seasons API Class + * + * @return \Tmdb\Api\TvSeason + */ + public function getApi() + { + return $this->getClient()->getTvSeasonApi(); + } + + /** + * @return TvSeasonFactory + */ + public function getFactory() + { + return new TvSeasonFactory(); + } +} diff --git a/modules/Tmdb/RequestToken.php b/modules/Tmdb/RequestToken.php new file mode 100644 index 00000000..2968fca8 --- /dev/null +++ b/modules/Tmdb/RequestToken.php @@ -0,0 +1,106 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb; + +/** + * Class RequestToken + * @package Tmdb + */ +class RequestToken { + /** + * The token for obtaining a session + * + * @var string + */ + private $token = null; + + /** + * Expiry date UTC + * + * @var + */ + private $expiresAt; + + /** + * @var bool + */ + private $success; + + /** + * Token bag + * + * @param $request_token + */ + public function __construct($request_token = null) + { + $this->token = $request_token; + } + + /** + * @param null $token + * @return $this + */ + public function setToken($token) + { + $this->token = $token; + return $this; + } + + /** + * @return null + */ + public function getToken() + { + return $this->token; + } + + /** + * @param mixed $expiresAt + * @return $this + */ + public function setExpiresAt($expiresAt) + { + if (!$expiresAt instanceof \DateTime) { + $expiresAt = new \DateTime($expiresAt); + } + + $this->expiresAt = $expiresAt; + return $this; + } + + /** + * @return mixed + */ + public function getExpiresAt() + { + return $this->expiresAt; + } + + /** + * @param boolean $success + * @return $this + */ + public function setSuccess($success) + { + $this->success = $success; + return $this; + } + + /** + * @return boolean + */ + public function getSuccess() + { + return $this->success; + } +} diff --git a/modules/Tmdb/SessionToken.php b/modules/Tmdb/SessionToken.php new file mode 100644 index 00000000..8af98252 --- /dev/null +++ b/modules/Tmdb/SessionToken.php @@ -0,0 +1,102 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb; + +/** + * Class SessionToken + * @package Tmdb + */ +class SessionToken { + /** + * @var string + */ + private $sessionToken = null; + + /** + * @var \DateTime + */ + private $expiresAt; + + /** + * @var bool + */ + private $success; + + /** + * Token bag + * + * @param $session_token + */ + public function __construct($session_token = null) + { + $this->sessionToken = $session_token; + } + + /** + * @param null $sessionToken + * @return $this + */ + public function setToken($sessionToken) + { + $this->sessionToken = $sessionToken; + return $this; + } + + /** + * @return null + */ + public function getToken() + { + return $this->sessionToken; + } + + /** + * @param \DateTime $expiresAt + * @return $this + */ + public function setExpiresAt($expiresAt) + { + if (!$expiresAt instanceof \DateTime) { + $expiresAt = new \DateTime($expiresAt); + } + + $this->expiresAt = $expiresAt; + return $this; + } + + /** + * @return \DateTime + */ + public function getExpiresAt() + { + return $this->expiresAt; + } + + /** + * @param mixed $success + * @return $this + */ + public function setSuccess($success) + { + $this->success = $success; + return $this; + } + + /** + * @return mixed + */ + public function getSuccess() + { + return $this->success; + } +}