Skip to content

Commit

Permalink
Adding Lists in Movies
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 8, 2014
1 parent 0da60c8 commit 3dec74d
Show file tree
Hide file tree
Showing 3 changed files with 329 additions and 8 deletions.
82 changes: 82 additions & 0 deletions lib/Tmdb/Factory/Movie/ListItemFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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\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;
}
}
40 changes: 32 additions & 8 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\ListItemFactory;
use Tmdb\Factory\Movie\ReviewFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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']));
Expand Down Expand Up @@ -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;
}
}
215 changes: 215 additions & 0 deletions lib/Tmdb/Model/Movie/ListItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?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;
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;
}


}

0 comments on commit 3dec74d

Please sign in to comment.