Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 16, 2014
1 parent 414be8b commit 3312c27
Show file tree
Hide file tree
Showing 5 changed files with 277 additions and 18 deletions.
32 changes: 24 additions & 8 deletions lib/Tmdb/Factory/PeopleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,39 @@ protected function applyCredits(array $data = array(), Person $person) {
$method = $hydrator->camelize(sprintf('get_%s', $type));

if (array_key_exists('cast', $data[$type])) {
$person->$method()->setCast($this->createCollection(
$cast = $this->createGenericCollection(
$data[$type]['cast'],
new CastMember(),
new Cast())
new Person\MovieCredit()
);

foreach($cast as $member) {
$member->setPosterImage($member->getPosterPath());
}

$person->$method()->setCast($cast);
}

if (array_key_exists('crew', $data[$type])) {
$person->$method()->setCrew($this->createCollection(
$crew = $this->createGenericCollection(
$data[$type]['crew'],
new CrewMember(),
new Crew())
new Person\MovieCredit()
);

foreach($crew as $member) {
$member->setPosterImage($member->getPosterPath());
}

$person->$method()->setCrew($crew);
}
}
}
}

protected function getPosterImageForCredit($posterPath)
{
return $this->getImageFactory()->createFromPath($posterPath, 'poster_path');
}

/**
* {@inheritdoc}
*/
Expand All @@ -138,10 +153,11 @@ public function createCollection(array $data = array(), Person\AbstractMember $p
$data = $data['results'];
}

$class = get_class($person);

foreach($data as $item) {
$collection->add(null, $this->create($item, $person));
$collection->add(null, $this->create($item, new $class()));
}

return $collection;
}

Expand Down
9 changes: 5 additions & 4 deletions lib/Tmdb/Model/Collection/CreditsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Tmdb\Model\Collection\People\Cast;
use Tmdb\Model\Collection\People\Crew;
use Tmdb\Model\Common\GenericCollection;

class CreditsCollection {
/**
Expand All @@ -36,10 +37,10 @@ public function __construct()
}

/**
* @param Cast $cast
* @param Cast|GenericCollection $cast
* @return $this
*/
public function setCast(Cast $cast)
public function setCast(GenericCollection $cast)
{
$this->cast = $cast;
return $this;
Expand All @@ -54,10 +55,10 @@ public function getCast()
}

/**
* @param Crew $crew
* @param Crew|GenericCollection $crew
* @return $this
*/
public function setCrew(Crew $crew)
public function setCrew(GenericCollection $crew)
{
$this->crew = $crew;
return $this;
Expand Down
10 changes: 5 additions & 5 deletions lib/Tmdb/Model/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Person extends AbstractModel implements PersonInterface {
/**
* @var ProfileImage
*/
private $profile;
private $profileImage;

/**
* @var Collection\CreditsCollection
Expand Down Expand Up @@ -389,12 +389,12 @@ public function getProfilePath()
}

/**
* @param ProfileImage $profile
* @param ProfileImage $profileImage
* @return $this
*/
public function setProfileImage(ProfileImage $profile)
public function setProfileImage(ProfileImage $profileImage)
{
$this->profile = $profile;
$this->profileImage = $profileImage;
return $this;
}

Expand All @@ -403,7 +403,7 @@ public function setProfileImage(ProfileImage $profile)
*/
public function getProfileImage()
{
return $this->profile;
return $this->profileImage;
}

/**
Expand Down
243 changes: 243 additions & 0 deletions lib/Tmdb/Model/Person/MovieCredit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<?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\Person;

use Tmdb\Model\AbstractModel;
use Tmdb\Model\Image\PosterImage;

class MovieCredit extends AbstractModel {

/**
* @var bool
*/
private $adult;

/**
* @var string
*/
private $character;

/**
* @var string
*/
private $creditId;

/**
* @var int
*/
private $id;

/**
* @var string
*/
private $originalTitle;

/**
* @var string
*/
private $posterPath;

/**
* @var \DateTime
*/
private $releaseDate;

/**
* @var string
*/
private $title;

/**
* @var PosterImage
*/
private $posterImage;

public static $_properties = array(
'adult',
'character',
'credit_id',
'id',
'original_title',
'poster_path',
'release_date',
'title'
);

/**
* @param boolean $adult
* @return $this
*/
public function setAdult($adult)
{
$this->adult = $adult;
return $this;
}

/**
* @return boolean
*/
public function getAdult()
{
return $this->adult;
}

/**
* @param string $character
* @return $this
*/
public function setCharacter($character)
{
$this->character = $character;
return $this;
}

/**
* @return string
*/
public function getCharacter()
{
return $this->character;
}

/**
* @param string $creditId
* @return $this
*/
public function setCreditId($creditId)
{
$this->creditId = $creditId;
return $this;
}

/**
* @return string
*/
public function getCreditId()
{
return $this->creditId;
}

/**
* @param int $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}

/**
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* @param string $originalTitle
* @return $this
*/
public function setOriginalTitle($originalTitle)
{
$this->originalTitle = $originalTitle;
return $this;
}

/**
* @return string
*/
public function getOriginalTitle()
{
return $this->originalTitle;
}

/**
* @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;
}

/**
* @param \DateTime $releaseDate
* @return $this
*/
public function setReleaseDate($releaseDate)
{
if (!$releaseDate instanceof \DateTime) {
$releaseDate = new \DateTime($releaseDate);
}

$this->releaseDate = $releaseDate;
return $this;
}

/**
* @return \DateTime
*/
public function getReleaseDate()
{
return $this->releaseDate;
}

/**
* @param string $title
* @return $this
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}

/**
* @return string
*/
public function getTitle()
{
return $this->title;
}


}
1 change: 0 additions & 1 deletion lib/Tmdb/Repository/PeopleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function load($id, array $parameters = array(), array $headers = array())
}

$data = $this->getApi()->getPerson($id, $this->parseQueryParameters($parameters), $headers);

return $this->getFactory()->create($data);
}

Expand Down

0 comments on commit 3312c27

Please sign in to comment.