forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0da60c8
commit 3dec74d
Showing
3 changed files
with
329 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |