Skip to content

Commit

Permalink
Fixing up Genres, added missing Repository method. Updated PROGRESS.m…
Browse files Browse the repository at this point in the history
…d to reflect current state.
  • Loading branch information
wtfzdotnet committed Feb 8, 2014
1 parent 8edc085 commit c97faef
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The states for now defined as;
| Credits | **TODO** |
| Discover | Done |
| Find | Review |
| Genres | Review |
| Genres | Done |
| Jobs | Done |
| Keywords | Review |
| Lists | Partially Done * |
Expand Down
22 changes: 22 additions & 0 deletions examples/genres/model/movies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
require_once('../../../vendor/autoload.php');
require_once('../../../apikey.php');

$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$repository = new \Tmdb\Repository\GenreRepository($client);
$genre = $repository->getMovies(18);

var_dump($genre);
5 changes: 3 additions & 2 deletions lib/Tmdb/Factory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ protected function createGenericCollection(array $data = array(), $class)
* Create a result collection
*
* @param array $data
* @param string $method
* @return GenericCollection
*/
public function createResultCollection(array $data = array())
public function createResultCollection(array $data = array(), $method = 'create')
{
$collection = new ResultCollection();

Expand All @@ -83,7 +84,7 @@ public function createResultCollection(array $data = array())
}

foreach($data as $item) {
$collection->add(null, $this->create($item));
$collection->add(null, $this->$method($item));
}

return $collection;
Expand Down
15 changes: 14 additions & 1 deletion lib/Tmdb/Factory/GenreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,30 @@

use Tmdb\Model\Collection\Genres;
use Tmdb\Model\Genre;
use Tmdb\Model\Movie;

class GenreFactory extends AbstractFactory
{
/**
* {@inheritdoc}
* @param array $data
*
* @return Genre
*/
public function create(array $data = array())
{
return $this->hydrate(new Genre(), $data);
}

/**
* @param array $data
*
* @return Movie
*/
public function createMovie(array $data = array())
{
return $this->hydrate(new Movie(), $data);
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions lib/Tmdb/Repository/GenreRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Tmdb\Factory\GenreFactory;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Genre;

class GenreRepository extends AbstractRepository {
/**
Expand Down Expand Up @@ -42,6 +43,21 @@ public function loadCollection(array $parameters = array(), array $headers = arr
);
}

/**
* 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
*
Expand Down

0 comments on commit c97faef

Please sign in to comment.