diff --git a/PROGRESS.md b/PROGRESS.md index c7dc478f..6dcbe79e 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -4,8 +4,8 @@ Overview of the current implementation status. The states for now defined as; - Done, stable? -- Review, requires another review before we can mark it as done. - Partially done, means there are methods and / or classes missing and is intentional. +- Review, requires another review before we can mark it as done. - Todo, requires everything still to be implemented. | API Namespace | Status | @@ -33,4 +33,4 @@ The states for now defined as; | TV Seasons | Done | | TV Episodes | Done | -__* Currently the account related functions are missing from these sections.__ \ No newline at end of file +__* Currently the account related functions are missing from these sections.__ diff --git a/examples/search/model/collection.php b/examples/search/model/collection.php new file mode 100644 index 00000000..49e8bfa6 --- /dev/null +++ b/examples/search/model/collection.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Search\SearchQuery\CollectionSearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchCollection('star wars', $query); + +var_dump($find); \ No newline at end of file diff --git a/examples/search/model/company.php b/examples/search/model/company.php new file mode 100644 index 00000000..c7da9292 --- /dev/null +++ b/examples/search/model/company.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Search\SearchQuery\CompanySearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchCompany('warner bros', $query); + +var_dump($find); \ No newline at end of file diff --git a/examples/search/model/keyword.php b/examples/search/model/keyword.php new file mode 100644 index 00000000..2a64d187 --- /dev/null +++ b/examples/search/model/keyword.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Search\SearchQuery\KeywordSearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchKeyword('scary', $query); + +var_dump($find); \ No newline at end of file diff --git a/examples/search/model/list.php b/examples/search/model/list.php new file mode 100644 index 00000000..a8e01ec3 --- /dev/null +++ b/examples/search/model/list.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Search\SearchQuery\ListSearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchList('award', $query); + +var_dump($find); \ No newline at end of file diff --git a/examples/search/model/movie.php b/examples/search/model/movie.php new file mode 100644 index 00000000..8b9e259c --- /dev/null +++ b/examples/search/model/movie.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Search\SearchQuery\MovieSearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchMovie('batman', $query); + +var_dump($find); \ No newline at end of file diff --git a/examples/search/model/person.php b/examples/search/model/person.php new file mode 100644 index 00000000..41a00b84 --- /dev/null +++ b/examples/search/model/person.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Search\SearchQuery\PersonSearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchPerson('bruce lee', $query); + +var_dump($find); \ No newline at end of file diff --git a/examples/search/model/tv.php b/examples/search/model/tv.php new file mode 100644 index 00000000..ba1d81e6 --- /dev/null +++ b/examples/search/model/tv.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +require_once('../../../vendor/autoload.php'); +require_once('../../../apikey.php'); + +$token = new \Tmdb\ApiToken(TMDB_API_KEY); +$client = new \Tmdb\Client($token); + +$query = new \Tmdb\Model\Search\SearchQuery\TvSearchQuery(); +$query->page(1); + +$repository = new \Tmdb\Repository\SearchRepository($client); + +$find = $repository->searchTv('breaking bad', $query); + +var_dump($find); \ No newline at end of file diff --git a/lib/Tmdb/Model/Search/SearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery.php new file mode 100644 index 00000000..55ff8dc4 --- /dev/null +++ b/lib/Tmdb/Model/Search/SearchQuery.php @@ -0,0 +1,43 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search; + +use Tmdb\Model\Collection\QueryParametersCollection; + +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/lib/Tmdb/Model/Search/SearchQuery/CollectionSearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery/CollectionSearchQuery.php new file mode 100644 index 00000000..37871cfe --- /dev/null +++ b/lib/Tmdb/Model/Search/SearchQuery/CollectionSearchQuery.php @@ -0,0 +1,30 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use 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/lib/Tmdb/Model/Search/SearchQuery/CompanySearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery/CompanySearchQuery.php new file mode 100644 index 00000000..b1545ce4 --- /dev/null +++ b/lib/Tmdb/Model/Search/SearchQuery/CompanySearchQuery.php @@ -0,0 +1,17 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +class CompanySearchQuery extends SearchQuery {} diff --git a/lib/Tmdb/Model/Search/SearchQuery/KeywordSearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery/KeywordSearchQuery.php new file mode 100644 index 00000000..b32a4fbd --- /dev/null +++ b/lib/Tmdb/Model/Search/SearchQuery/KeywordSearchQuery.php @@ -0,0 +1,17 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use Tmdb\Model\Search\SearchQuery; + +class KeywordSearchQuery extends SearchQuery {} diff --git a/lib/Tmdb/Model/Search/SearchQuery/ListSearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery/ListSearchQuery.php new file mode 100644 index 00000000..34a796aa --- /dev/null +++ b/lib/Tmdb/Model/Search/SearchQuery/ListSearchQuery.php @@ -0,0 +1,31 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use 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/lib/Tmdb/Model/Search/SearchQuery/MovieSearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery/MovieSearchQuery.php new file mode 100644 index 00000000..b464005a --- /dev/null +++ b/lib/Tmdb/Model/Search/SearchQuery/MovieSearchQuery.php @@ -0,0 +1,91 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use 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/lib/Tmdb/Model/Search/SearchQuery/PersonSearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery/PersonSearchQuery.php new file mode 100644 index 00000000..2abd9de4 --- /dev/null +++ b/lib/Tmdb/Model/Search/SearchQuery/PersonSearchQuery.php @@ -0,0 +1,49 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use 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/lib/Tmdb/Model/Search/SearchQuery/TvSearchQuery.php b/lib/Tmdb/Model/Search/SearchQuery/TvSearchQuery.php new file mode 100644 index 00000000..d7763864 --- /dev/null +++ b/lib/Tmdb/Model/Search/SearchQuery/TvSearchQuery.php @@ -0,0 +1,65 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Search\SearchQuery; + +use 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/lib/Tmdb/Repository/SearchRepository.php b/lib/Tmdb/Repository/SearchRepository.php new file mode 100644 index 00000000..3b5d8ceb --- /dev/null +++ b/lib/Tmdb/Repository/SearchRepository.php @@ -0,0 +1,327 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +// @todo +use Tmdb\Client; +use Tmdb\Exception\RuntimeException; +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\Tv; + +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, $parameters->toArray(), $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, $parameters->toArray(), $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, $parameters->toArray(), $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, $parameters->toArray(), $headers); + + return $this->getPeopleFactory()->createResultCollection($data); + } + + /** + * @param string $query + * @param ListSearchQuery $parameters + * @param array $headers + * + * @todo fix return docblock + * @return ResultCollection + */ + public function searchList($query, ListSearchQuery $parameters, array $headers = array()) { + $data = $this->getApi()->searchList($query, $parameters->toArray(), $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, $parameters->toArray(), $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, $parameters->toArray(), $headers); + + return $this->getKeywordFactory()->createResultCollection($data); + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Search + */ + public function getApi() + { + return $this->getClient()->getSearchApi(); + } + + /** + * Changes does not support a generic factory + * + * @throws RuntimeException + */ + public function getFactory(){ + throw new RuntimeException(); + } + + /** + * @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