Skip to content

Commit

Permalink
Adding the reviews section of Movie models
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 8, 2014
1 parent d4e5d7d commit 0da60c8
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/movies/model/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @var \Tmdb\Model\Movie $movie
*/
$movie = $repository->load(87421);

var_dump($movie);exit;
echo $movie->getTitle() . "<br/>";

echo "Alternative Titles<br/>";
Expand Down
52 changes: 52 additions & 0 deletions lib/Tmdb/Factory/Movie/ReviewFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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
*/
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;
}
}
32 changes: 30 additions & 2 deletions lib/Tmdb/Factory/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,6 +47,11 @@ class MovieFactory extends AbstractFactory {
*/
private $changeFactory;

/**
* @var ReviewFactory
*/
private $reviewFactory;

/**
* Constructor
*/
Expand All @@ -56,6 +62,7 @@ public function __construct()
$this->genreFactory = new GenreFactory();
$this->imageFactory = new ImageFactory();
$this->changeFactory = new ChangeFactory();
$this->reviewFactory = new ReviewFactory();
}

/**
Expand Down Expand Up @@ -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)) {
// }
Expand Down Expand Up @@ -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;
}


}
24 changes: 24 additions & 0 deletions lib/Tmdb/Model/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -204,6 +205,11 @@ class Movie extends AbstractModel {
*/
protected $translations;

/**
* @var ResultCollection
*/
protected $reviews;

/**
* Properties that are available in the API
*
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
104 changes: 104 additions & 0 deletions lib/Tmdb/Model/Movie/Review.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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
*/
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;
}


}

0 comments on commit 0da60c8

Please sign in to comment.