diff --git a/lib/Tmdb/Factory/Movie/ListItemFactory.php b/lib/Tmdb/Factory/Movie/ListItemFactory.php new file mode 100644 index 00000000..3d5332fe --- /dev/null +++ b/lib/Tmdb/Factory/Movie/ListItemFactory.php @@ -0,0 +1,82 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Factory\Movie; + +use Tmdb\Factory\AbstractFactory; +use Tmdb\Factory\ImageFactory; +use Tmdb\Model\Collection\ResultCollection; +use Tmdb\Model\Movie\ListItem; + +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()) + { + $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; + } + + /** + * @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/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index c3fbb674..e187201c 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\ListItemFactory; use Tmdb\Factory\Movie\ReviewFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; @@ -52,17 +53,23 @@ class MovieFactory extends AbstractFactory { */ private $reviewFactory; + /** + * @var ListItemFactory + */ + private $listItemFactory; + /** * 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->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(); } /** @@ -138,8 +145,9 @@ public function create(array $data = array()) $movie->setReviews($this->getReviewFactory()->createCollection($data['reviews'])); } -// if (array_key_exists('lists', $data)) { -// } + if (array_key_exists('lists', $data)) { + $movie->setLists($this->getListItemFactory()->createCollection($data['lists'])); + } if (array_key_exists('changes', $data)) { $movie->setChanges($this->getChangeFactory()->createCollection($data['changes'])); @@ -274,5 +282,21 @@ 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; + } } \ No newline at end of file diff --git a/lib/Tmdb/Model/Movie/ListItem.php b/lib/Tmdb/Model/Movie/ListItem.php new file mode 100644 index 00000000..46bdf62a --- /dev/null +++ b/lib/Tmdb/Model/Movie/ListItem.php @@ -0,0 +1,215 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Model\Movie; + +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Image\PosterImage; + +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; + } + + +}