diff --git a/examples/movies/model/all.php b/examples/movies/model/all.php index 2648d813..70bba794 100644 --- a/examples/movies/model/all.php +++ b/examples/movies/model/all.php @@ -28,7 +28,7 @@ * @var \Tmdb\Model\Movie $movie */ $movie = $repository->load(87421); - +var_dump($movie);exit; echo $movie->getTitle() . "
"; echo "Alternative Titles
"; diff --git a/lib/Tmdb/Factory/Movie/ReviewFactory.php b/lib/Tmdb/Factory/Movie/ReviewFactory.php new file mode 100644 index 00000000..c8ebb0ba --- /dev/null +++ b/lib/Tmdb/Factory/Movie/ReviewFactory.php @@ -0,0 +1,52 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\Movie; + +use Tmdb\Factory\AbstractFactory; +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Movie\Review; + +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()) + { + $collection = new ResultCollection(); + + $collection->setPage($data['page']); + $collection->setTotalPages($data['total_pages']); + $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/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 25ce818c..c3fbb674 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -13,6 +13,7 @@ namespace Tmdb\Factory; use Tmdb\Factory\Common\ChangeFactory; +use Tmdb\Factory\Movie\ReviewFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; use Tmdb\Model\Common\GenericCollection; @@ -46,6 +47,11 @@ class MovieFactory extends AbstractFactory { */ private $changeFactory; + /** + * @var ReviewFactory + */ + private $reviewFactory; + /** * Constructor */ @@ -56,6 +62,7 @@ public function __construct() $this->genreFactory = new GenreFactory(); $this->imageFactory = new ImageFactory(); $this->changeFactory = new ChangeFactory(); + $this->reviewFactory = new ReviewFactory(); } /** @@ -127,8 +134,9 @@ public function create(array $data = array()) $movie->setSimilarMovies($this->createCollection($data['similar_movies']['results'])); } -// if (array_key_exists('reviews', $data)) { -// } + if (array_key_exists('reviews', $data)) { + $movie->setReviews($this->getReviewFactory()->createCollection($data['reviews'])); + } // if (array_key_exists('lists', $data)) { // } @@ -247,4 +255,24 @@ public function getChangeFactory() { return $this->changeFactory; } + + /** + * @param \Tmdb\Factory\Movie\ReviewFactory $reviewFactory + * @return $this + */ + public function setReviewFactory($reviewFactory) + { + $this->reviewFactory = $reviewFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\Movie\ReviewFactory + */ + public function getReviewFactory() + { + return $this->reviewFactory; + } + + } \ No newline at end of file diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index dc8d1d00..4861562a 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Model; +use Tmdb\Model\Collection\ResultCollection; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Collection\Credits; use Tmdb\Model\Collection\Genres; @@ -204,6 +205,11 @@ class Movie extends AbstractModel { */ protected $translations; + /** + * @var ResultCollection + */ + protected $reviews; + /** * Properties that are available in the API * @@ -891,4 +897,22 @@ 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/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php b/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php index 3191ff36..b29c68b8 100644 --- a/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php +++ b/lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php @@ -23,7 +23,7 @@ final class AppendToResponse extends BaseAppendToResponse { const TRAILERS = 'trailers'; const TRANSLATIONS = 'translations'; const SIMILAR_MOVIES = 'similar_movies'; - const REVIEWS = 'movies_reviews'; + const REVIEWS = 'reviews'; const LISTS = 'lists'; const CHANGES = 'changes'; } diff --git a/lib/Tmdb/Model/Movie/Review.php b/lib/Tmdb/Model/Movie/Review.php new file mode 100644 index 00000000..ade97c90 --- /dev/null +++ b/lib/Tmdb/Model/Movie/Review.php @@ -0,0 +1,104 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; + +class Review extends AbstractModel { + + private $id; + private $author; + private $content; + private $url; + + public static $_properties = array( + 'id', + 'author', + 'content', + '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 $url + * @return $this + */ + public function setUrl($url) + { + $this->url = $url; + return $this; + } + + /** + * @return mixed + */ + public function getUrl() + { + return $this->url; + } + + +}