Skip to content

Commit

Permalink
Adding the video method, fixes php-tmdb#24
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Apr 5, 2014
1 parent d3a4041 commit e3a5319
Show file tree
Hide file tree
Showing 32 changed files with 871 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/movies/model/videos.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\MovieRepository($client);
$collection = $repository->getVideos(87421);

var_dump($collection);
22 changes: 22 additions & 0 deletions examples/tv/model/episode/videos.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\TvEpisodeRepository($client);
$videos = $repository->getVideos(1396, 1, 1);

var_dump($videos);
22 changes: 22 additions & 0 deletions examples/tv/model/season/videos.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\TvSeasonRepository($client);
$videos = $repository->getVideos(1396, 1);

var_dump($videos);
22 changes: 22 additions & 0 deletions examples/tv/model/tv/videos.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\TvRepository($client);
$videos = $repository->getVideos(1396);

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

use Tmdb\Factory\AbstractFactory;
use Tmdb\Model\Collection\Videos;
use Tmdb\Model\Common\Video;

/**
* Class VideoFactory
* @package Tmdb\Factory\Common
*/
class VideoFactory extends AbstractFactory
{
/**
* {@inheritdoc}
*/
public function create(array $data = array())
{
$videoType = $this->resolveVideoType($data);

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

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

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

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

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

return $collection;
}

private function resolveVideoType($data)
{
if (array_key_exists('site', $data) && !empty($data['site'])) {
$site = strtolower($data['site']);

switch ($site) {
case 'youtube':
return new Video\Youtube();
break;
default:
return new Video();
break;
}
}
}
}
30 changes: 30 additions & 0 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\Common\VideoFactory;
use Tmdb\Factory\Movie\ListItemFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
Expand Down Expand Up @@ -68,6 +69,11 @@ class MovieFactory extends AbstractFactory
*/
private $keywordFactory;

/**
* @var Common\VideoFactory
*/
private $videoFactory;

/**
* Constructor
*/
Expand All @@ -81,6 +87,7 @@ public function __construct()
$this->reviewFactory = new ReviewFactory();
$this->listItemFactory = new ListItemFactory();
$this->keywordFactory = new KeywordFactory();
$this->videoFactory = new VideoFactory();
}

/**
Expand Down Expand Up @@ -146,6 +153,10 @@ public function create(array $data = array())
$movie->setTrailers($this->createGenericCollection($data['trailers']['youtube'], new Youtube()));
}

if (array_key_exists('videos', $data)) {
$movie->setVideos($this->getVideoFactory()->createCollection($data['videos']));
}

if (array_key_exists('translations', $data) && array_key_exists('translations', $data['translations'])) {
$movie->setTranslations(
$this->createGenericCollection(
Expand Down Expand Up @@ -384,4 +395,23 @@ public function getKeywordFactory()
{
return $this->keywordFactory;
}

/**
* @param \Tmdb\Factory\Common\VideoFactory $videoFactory
* @return $this
*/
public function setVideoFactory($videoFactory)
{
$this->videoFactory = $videoFactory;

return $this;
}

/**
* @return \Tmdb\Factory\Common\VideoFactory
*/
public function getVideoFactory()
{
return $this->videoFactory;
}
}
30 changes: 30 additions & 0 deletions lib/Tmdb/Factory/TvEpisodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
namespace Tmdb\Factory;

use Tmdb\Factory\Common\VideoFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Model\Common\GenericCollection;
Expand Down Expand Up @@ -41,6 +42,11 @@ class TvEpisodeFactory extends AbstractFactory
*/
private $imageFactory;

/**
* @var Common\VideoFactory
*/
private $videoFactory;

/**
* Constructor
*/
Expand All @@ -49,6 +55,7 @@ public function __construct()
$this->castFactory = new CastFactory();
$this->crewFactory = new CrewFactory();
$this->imageFactory = new ImageFactory();
$this->videoFactory = new VideoFactory();
}

/**
Expand Down Expand Up @@ -101,6 +108,10 @@ public function create(array $data = array())
$tvEpisode->setStillImage($this->getImageFactory()->createFromPath($data['still_path'], 'still_path'));
}

if (array_key_exists('videos', $data)) {
$tvEpisode->setVideos($this->getVideoFactory()->createCollection($data['videos']));
}

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

Expand Down Expand Up @@ -174,4 +185,23 @@ public function getImageFactory()
{
return $this->imageFactory;
}

/**
* @param \Tmdb\Factory\Common\VideoFactory $videoFactory
* @return $this
*/
public function setVideoFactory($videoFactory)
{
$this->videoFactory = $videoFactory;

return $this;
}

/**
* @return \Tmdb\Factory\Common\VideoFactory
*/
public function getVideoFactory()
{
return $this->videoFactory;
}
}
30 changes: 30 additions & 0 deletions lib/Tmdb/Factory/TvFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
namespace Tmdb\Factory;

use Tmdb\Factory\Common\VideoFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Model\Common\GenericCollection;
Expand Down Expand Up @@ -57,6 +58,11 @@ class TvFactory extends AbstractFactory
*/
private $networkFactory;

/**
* @var Common\VideoFactory
*/
private $videoFactory;

/**
* Constructor
*/
Expand All @@ -68,6 +74,7 @@ public function __construct()
$this->imageFactory = new ImageFactory();
$this->tvSeasonFactory = new TvSeasonFactory();
$this->networkFactory = new NetworkFactory();
$this->videoFactory = new VideoFactory();
}

/**
Expand Down Expand Up @@ -158,6 +165,10 @@ public function create(array $data = array())
$tvShow->setNetworks($this->getNetworkFactory()->createCollection($data['networks']));
}

if (array_key_exists('videos', $data)) {
$tvShow->setVideos($this->getVideoFactory()->createCollection($data['videos']));
}

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

Expand Down Expand Up @@ -292,4 +303,23 @@ public function getNetworkFactory()
{
return $this->networkFactory;
}

/**
* @param \Tmdb\Factory\Common\VideoFactory $videoFactory
* @return $this
*/
public function setVideoFactory($videoFactory)
{
$this->videoFactory = $videoFactory;

return $this;
}

/**
* @return \Tmdb\Factory\Common\VideoFactory
*/
public function getVideoFactory()
{
return $this->videoFactory;
}
}
Loading

0 comments on commit e3a5319

Please sign in to comment.