Skip to content

Commit

Permalink
Adding Credits API and renaming the Credits Collection to CreditsColl…
Browse files Browse the repository at this point in the history
…ection
  • Loading branch information
wtfzdotnet committed Feb 9, 2014
1 parent 00f58cb commit fa7bad2
Show file tree
Hide file tree
Showing 25 changed files with 719 additions and 74 deletions.
22 changes: 22 additions & 0 deletions examples/collection/model/images.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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
*/
require_once('../../../vendor/autoload.php');
require_once('../../../apikey.php');

$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$repository = new \Tmdb\Repository\CollectionRepository($client);
$collection = $repository->load(10);

var_dump($collection);
22 changes: 22 additions & 0 deletions examples/credits/model/get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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
*/
require_once('../../../vendor/autoload.php');
require_once('../../../apikey.php');

$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$repository = new \Tmdb\Repository\CreditsRepository($client);
$credits = $repository->load('52542282760ee313280017f9');

var_dump($credits);
160 changes: 160 additions & 0 deletions lib/Tmdb/Factory/CreditsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?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;

use Tmdb\Model\Collection\Genres;
use Tmdb\Model\Genre;
use Tmdb\Model\Movie;
use Tmdb\Model\Credits as Credits;

class CreditsFactory extends AbstractFactory
{
/**
* @var TvSeasonFactory
*/
private $tvSeasonFactory;

/**
* @var TvEpisodeFactory
*/
private $tvEpisodeFactory;

/**
* @var PeopleFactory
*/
private $peopleFactory;

public function __construct()
{
$this->tvSeasonFactory = new TvSeasonFactory();
$this->tvEpisodeFactory = new TvEpisodeFactory();
$this->peopleFactory = new PeopleFactory();
}

/**
* @param array $data
*
* @return Genre
*/
public function create(array $data = array())
{
$credits = new Credits();

if (array_key_exists('media', $data)) {

$credits->setMedia(
$this->hydrate($credits->getMedia(), $data['media'])
);

if (array_key_exists('seasons', $data['media'])) {
$episodes = $this->getTvSeasonFactory()->createCollection($data['media']['seasons']);
$credits->getMedia()->setSeasons($episodes);
}

if (array_key_exists('episodes', $data['media'])) {
$episodes = $this->getTvEpisodeFactory()->createCollection($data['media']['episodes']);
$credits->getMedia()->setEpisodes($episodes);
}
}

if (array_key_exists('person', $data)) {
$credits->setPerson(
$this->getPeopleFactory()->create($data['person'])
);
}

return $this->hydrate($credits, $data);
}

/**
* @param array $data
*
* @return Movie
*/
public function createMovie(array $data = array())
{
return $this->hydrate(new Movie(), $data);
}

/**
* {@inheritdoc}
*/
public function createCollection(array $data = array())
{
$collection = new Genres();

if (array_key_exists('genres', $data)) {
$data = $data['genres'];
}

foreach($data as $item) {
$collection->addGenre($this->create($item));
}

return $collection;
}

/**
* @param \Tmdb\Factory\TvEpisodeFactory $tvEpisodeFactory
* @return $this
*/
public function setTvEpisodeFactory($tvEpisodeFactory)
{
$this->tvEpisodeFactory = $tvEpisodeFactory;
return $this;
}

/**
* @return \Tmdb\Factory\TvEpisodeFactory
*/
public function getTvEpisodeFactory()
{
return $this->tvEpisodeFactory;
}

/**
* @param \Tmdb\Factory\TvSeasonFactory $tvSeasonFactory
* @return $this
*/
public function setTvSeasonFactory($tvSeasonFactory)
{
$this->tvSeasonFactory = $tvSeasonFactory;
return $this;
}

/**
* @return \Tmdb\Factory\TvSeasonFactory
*/
public function getTvSeasonFactory()
{
return $this->tvSeasonFactory;
}

/**
* @param \Tmdb\Factory\PeopleFactory $peopleFactory
* @return $this
*/
public function setPeopleFactory($peopleFactory)
{
$this->peopleFactory = $peopleFactory;
return $this;
}

/**
* @return \Tmdb\Factory\PeopleFactory
*/
public function getPeopleFactory()
{
return $this->peopleFactory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Tmdb\Model\Collection\People\Cast;
use Tmdb\Model\Collection\People\Crew;

class Credits {
class CreditsCollection {
/**
* @var Cast
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Collection\Credits;
namespace Tmdb\Model\Collection\CreditsCollection;

use Tmdb\Model\Collection\Credits;
use Tmdb\Model\Collection\CreditsCollection;

class CombinedCredits extends Credits {}
class CombinedCredits extends CreditsCollection {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Collection\Credits;
namespace Tmdb\Model\Collection\CreditsCollection;

use Tmdb\Model\Collection\Credits;
use Tmdb\Model\Collection\CreditsCollection;

class MovieCredits extends Credits {}
class MovieCredits extends CreditsCollection {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Collection\Credits;
namespace Tmdb\Model\Collection\CreditsCollection;

use Tmdb\Model\Collection\Credits;
use Tmdb\Model\Collection\CreditsCollection;

class TvCredits extends Credits {}
class TvCredits extends CreditsCollection {}
Loading

0 comments on commit fa7bad2

Please sign in to comment.