Skip to content

Commit

Permalink
Adding first state of config with simple use case of the image helper
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 9, 2014
1 parent a897abe commit c3926cc
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 43 deletions.
56 changes: 35 additions & 21 deletions examples/movies/model/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,66 +36,80 @@
$repository = new \Tmdb\Repository\MovieRepository($client);
$movie = $repository->load(87421, array($append));

echo $movie->getTitle() . "\n";
echo $movie->getTitle() . "<br/>";

echo "Alternative Titles\n";
echo "Alternative Titles<br/>";

foreach($movie->getAlternativeTitles() as $title) {
printf(" - %s [%s]\n", $title->getTitle(), $title->getIso31661());
printf(" - %s [%s]<br/>", $title->getTitle(), $title->getIso31661());
}

echo "Cast\n";
echo "Cast<br/>";

foreach($movie->getCredits()->getCast() as $person) {
printf(" - %s as %s\n", $person->getName(), $person->getCharacter());
printf(" - %s as %s<br/>", $person->getName(), $person->getCharacter());
}

echo "Crew\n";
echo "Crew<br/>";

foreach($movie->getCredits()->getCrew() as $person) {
printf(" - %s as %s\n", $person->getName(), $person->getJob());
printf(" - %s as %s<br/>", $person->getName(), $person->getJob());
}

echo "Images\n";
echo "Images<br/>";

$configRepository = new \Tmdb\Repository\ConfigurationRepository($client);
$config = $configRepository->load();

$imageHelper = new \Tmdb\Model\Helper\ImageHelper($config);
foreach($movie->getImages() as $image) {
printf(" - %s\n", $image->getFilePath());
echo $imageHelper->getHtml($image);

printf(" - %s<br/>", $image->getFilePath());
}

echo "Genres\n";
echo "Genres<br/>";

foreach($movie->getGenres() as $genre) {
printf(" - %s\n", $genre->getName());
printf(" - %s<br/>", $genre->getName());
}

echo "Keywords\n";
echo "Keywords<br/>";

foreach($movie->getKeywords() as $keyword) {
printf(" - %s [%s]\n", $keyword->getName(), $keyword->getId());
printf(" - %s [%s]<br/>", $keyword->getName(), $keyword->getId());
}

echo "Releases\n";
echo "Releases<br/>";

foreach($movie->getReleases() as $release) {
printf(" - %s on %s\n", $release->getIso31661(), $release->getReleaseDate()->format('d-m-Y'));
printf(" - %s on %s<br/>", $release->getIso31661(), $release->getReleaseDate()->format('d-m-Y'));
}

echo "Translations\n";
echo "Translations<br/>";

foreach($movie->getTranslations() as $translation) {
printf(" - %s\n", $translation->getName());
printf(" - %s<br/>", $translation->getName());
}

echo "Trailers\n";
echo "Trailers<br/>";

foreach($movie->getTrailers() as $trailer) {
printf(" - %s\n", $trailer->getUrl());
printf(" - %s<br/>", $trailer->getUrl());
}

$popular = $repository->getPopular();

echo "Popular titles\n";
echo "Popular titles<br/>";

foreach($popular as $p) {
printf(" - %s\n", $p->getTitle());
printf(" - %s<br/>", $p->getTitle());
}

$topRated = $repository->getTopRated(array('page' => 3));

echo "Top rated<br/>";

foreach($topRated as $t) {
printf(" - %s<br/>", $t->getTitle());
}
25 changes: 15 additions & 10 deletions lib/Tmdb/Api/Movies.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,51 +164,56 @@ public function getChanges($movie_id, array $options = array())
/**
* Get the latest movie id.
*
* @param array $options
* @return mixed
*/
public function getLatest()
public function getLatest(array $options = array())
{
return $this->get('movie/latest');
return $this->get('movie/latest', $options);
}

/**
* Get the list of upcoming movies. This list refreshes every day. The maximum number of items this list will include is 100.
*
* @param array $options
* @return mixed
*/
public function getUpcoming()
public function getUpcoming(array $options = array())
{
return $this->get('movie/upcoming');
return $this->get('movie/upcoming', $options);
}

/**
* Get the list of movies playing in theatres. This list refreshes every day. The maximum number of items this list will include is 100.
*
* @param array $options
* @return mixed
*/
public function getNowPlaying()
public function getNowPlaying(array $options = array())
{
return $this->get('movie/now_playing');
return $this->get('movie/now_playing', $options);
}

/**
* Get the list of popular movies on The Movie Database. This list refreshes every day.
*
* @param array $options
* @return mixed
*/
public function getPopular()
public function getPopular(array $options = array())
{
return $this->get('movie/popular');
return $this->get('movie/popular', $options);
}

/**
* Get the list of top rated movies. By default, this list will only include movies that have 10 or more votes. This list refreshes every day.
*
* @param array $options
* @return mixed
*/
public function getTopRated()
public function getTopRated(array $options = array())
{
return $this->get('movie/top_rated');
return $this->get('movie/top_rated', $options);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions lib/Tmdb/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public function getPersonApi()
return new Api\People($this);
}

/**
* @return Api\Configuration
*/
public function getConfigurationApi()
{
return new Api\Configuration($this);
}


/**
* Return the relevant API object
*
Expand Down
45 changes: 45 additions & 0 deletions lib/Tmdb/Factory/ConfigurationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\Client;
use Tmdb\Model\Common\Collection;
use Tmdb\Model\Configuration;

class ConfigurationFactory extends AbstractFactory
{
/**
* {@inheritdoc}
*/
public static function create(array $data = array())
{
$config = new Configuration();

return parent::hydrate($config, $data);
}

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

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

return $collection;
}

}
2 changes: 1 addition & 1 deletion lib/Tmdb/Model/Common/Collection/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function getImage($id) {
*/
public function addImage(Image $image)
{
$this->data[] = $image;
$this->add(null, $image);
}
}
70 changes: 70 additions & 0 deletions lib/Tmdb/Model/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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;

use Tmdb\Client;
use Tmdb\Model\Common\Collection;

class Configuration extends AbstractModel {

/**
* @var Collection
*/
private $images;

/**
* @var Collection
*/
private $change_keys;

public static $_properties = array(
'images',
'change_keys',
);

/**
* @param \Tmdb\Model\Common\Collection $change_keys
* @return $this
*/
public function setChangeKeys($change_keys)
{
$this->change_keys = $change_keys;
return $this;
}

/**
* @return \Tmdb\Model\Common\Collection
*/
public function getChangeKeys()
{
return $this->change_keys;
}

/**
* @param \Tmdb\Model\Common\Collection $images
* @return $this
*/
public function setImages($images)
{
$this->images = $images;
return $this;
}

/**
* @return \Tmdb\Model\Common\Collection
*/
public function getImages()
{
return $this->images;
}
}
46 changes: 46 additions & 0 deletions lib/Tmdb/Model/Helper/ImageHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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\Helper;

use Tmdb\Model\Configuration;
use Tmdb\Model\Image;

class ImageHelper {

private $config;

public function __construct(Configuration $config)
{
$this->config = $config;
}

public function getImageConfiguration()
{
return $this->config->getImages();
}

public function getUrl(Image $image, $size = 'original') {
$config = $this->getImageConfiguration();

return sprintf('%s%s%s', $config['base_url'] , $size, $image->getFilePath());
}

public function getHtml(Image $image, $size = 'original') {
return sprintf(
'<img src="%s" height="%s" width="%s" />',
$this->getUrl($image, $size),
$image->getHeight(),
$image->getWidth()
);
}
}
Loading

0 comments on commit c3926cc

Please sign in to comment.