Skip to content

Commit

Permalink
Adding guest stars to tv episodes, fixes #126
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Nov 8, 2016
1 parent 19bfa63 commit 3ecf3d0
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 2 deletions.
44 changes: 44 additions & 0 deletions lib/Tmdb/Factory/People/GuestStarFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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\People;

use Tmdb\Factory\PeopleFactory;
use Tmdb\Model\Collection\People\GuestStars;

/**
* Class GuestStarFactory
* @package Tmdb\Factory\People
*/
class GuestStarFactory extends PeopleFactory
{
/**
* {@inheritdoc}
* @param \Tmdb\Model\Person\CastMember $person
*/
public function createCollection(array $data = [], $person = null)
{
$collection = new GuestStars();

if (is_object($person)) {
$class = get_class($person);
} else {
$class = '\Tmdb\Model\Person\GuestStar';
}

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

return $collection;
}
}
39 changes: 39 additions & 0 deletions lib/Tmdb/Factory/TvEpisodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
use Tmdb\Factory\Common\VideoFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Factory\People\GuestStarFactory;
use Tmdb\HttpClient\HttpClient;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Person\CastMember;
use Tmdb\Model\Person\CrewMember;
use Tmdb\Model\Common\ExternalIds;
use Tmdb\Model\Person\GuestStar;
use Tmdb\Model\Tv\Episode;

/**
Expand Down Expand Up @@ -54,6 +56,11 @@ class TvEpisodeFactory extends AbstractFactory
*/
private $changesFactory;

/**
* @var GuestStarFactory
*/
private $guestStarFactory;

/**
* Constructor
*
Expand All @@ -66,6 +73,7 @@ public function __construct(HttpClient $httpClient)
$this->imageFactory = new ImageFactory($httpClient);
$this->videoFactory = new VideoFactory($httpClient);
$this->changesFactory = new ChangeFactory($httpClient);
$this->guestStarFactory = new GuestStarFactory($httpClient);

parent::__construct($httpClient);
}
Expand Down Expand Up @@ -102,6 +110,18 @@ public function create(array $data = [])
)
);
}

if (array_key_exists('guest_stars', $data['credits'])) {
$tvEpisode
->getCredits()
->setGuestStars(
$this->getGuestStarFactory()
->createCollection(
$data['credits']['guest_stars'],
new GuestStar()
)
);
}
}

/** External ids */
Expand Down Expand Up @@ -183,6 +203,25 @@ public function getCrewFactory()
return $this->crewFactory;
}

/**
* @return GuestStarFactory
*/
public function getGuestStarFactory()
{
return $this->guestStarFactory;
}

/**
* @param GuestStarFactory $guestStarFactory
* @return $this
*/
public function setGuestStarFactory($guestStarFactory)
{
$this->guestStarFactory = $guestStarFactory;

return $this;
}

/**
* @param \Tmdb\Factory\ImageFactory $imageFactory
* @return $this
Expand Down
25 changes: 23 additions & 2 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\Collection\People\GuestStars;

/**
* Class CreditsCollection
Expand All @@ -31,13 +32,17 @@ class CreditsCollection
*/
private $crew;


private $guestStars;

/**
* Constructor
*/
public function __construct()
{
$this->cast = new Cast();
$this->crew = new Crew();
$this->cast = new Cast();
$this->crew = new Crew();
$this->guestStars = new GuestStars();
}

/**
Expand Down Expand Up @@ -77,4 +82,20 @@ public function getCrew()
{
return $this->crew;
}

/**
* @return GuestStars
*/
public function getGuestStars()
{
return $this->guestStars;
}

/**
* @param GuestStars $guestStars
*/
public function setGuestStars($guestStars)
{
$this->guestStars = $guestStars;
}
}
44 changes: 44 additions & 0 deletions lib/Tmdb/Model/Collection/People/GuestStars.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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\Collection\People;

use Tmdb\Model\Collection\People;
use Tmdb\Model\Person;

/**
* Class GuestStars
* @package Tmdb\Model\Collection\People
*/
class GuestStars extends People
{
/**
* Returns all people
*
* @return Person[]
*/
public function getGuestStars()
{
return parent::getPeople();
}

/**
* Retrieve a cast member from the collection
*
* @param $id
* @return Person
*/
public function getGuestStar($id)
{
return parent::getPerson($id);
}
}
21 changes: 21 additions & 0 deletions lib/Tmdb/Model/Person/GuestStar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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;

/**
* Class GuestStar
* @package Tmdb\Model\Person
*/
class GuestStar extends CastMember
{
}

0 comments on commit 3ecf3d0

Please sign in to comment.