Skip to content

Commit

Permalink
Expanding models
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Nov 5, 2013
1 parent f9ca4a4 commit 8d126cd
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 65 deletions.
7 changes: 3 additions & 4 deletions examples/movies/model/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRANSLATIONS,
));

$movie = \Tmdb\Model\Movie::load($client, 87421, array($append, $language));

$movie = \Tmdb\Model\Movie::load($client, 87421, array($append));

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

echo "Cast\n";

foreach($movie->getCast() as $person) {
foreach($movie->credits->cast as $person) {
printf(" - %s as %s\n", $person->getName(), $person->getCharacter());
}

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

Expand Down
42 changes: 33 additions & 9 deletions lib/Tmdb/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
use Tmdb\Client;
use Tmdb\Exception\RuntimeException;

use Tmdb\Model\Common\Collection\Credits\Cast;
use Tmdb\Model\Common\Collection\Credits\Crew;
use Tmdb\Model\Common\Collection\Genres;
use Tmdb\Model\Collection\Credits\Cast;
use Tmdb\Model\Collection\Credits\Crew;
use Tmdb\Model\Collection\Genres;
use Tmdb\Model\Collection\People;

use Tmdb\Model\Common\Collection\Images;
use Tmdb\Model\Common\Collection\People;

use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\QueryParameter\QueryParameterInterface;
use Tmdb\Model\Person\CastMember;
use Tmdb\Model\Person\CrewMember;
Expand Down Expand Up @@ -124,7 +126,7 @@ protected function parseQueryParameters(array $parameters = array())
*
* @param $client
* @param array $collection
* @return Images
* @return Image[]
*/
protected function collectImages($client, array $collection = array())
{
Expand Down Expand Up @@ -152,7 +154,7 @@ protected function collectImages($client, array $collection = array())
*
* @param $client
* @param array $collection
* @return People
* @return Person[]
*/
protected function collectPeople($client, array $collection = array())
{
Expand All @@ -172,7 +174,7 @@ protected function collectPeople($client, array $collection = array())
*
* @param $client
* @param array $collection
* @return People
* @return CastMember[]
*/
protected function collectCast($client, array $collection = array())
{
Expand All @@ -192,7 +194,7 @@ protected function collectCast($client, array $collection = array())
*
* @param $client
* @param array $collection
* @return People
* @return CrewMember[]
*/
protected function collectCrew($client, array $collection = array())
{
Expand All @@ -212,7 +214,7 @@ protected function collectCrew($client, array $collection = array())
*
* @param $client
* @param array $collection
* @return People
* @return Genre[]
*/
protected function collectGenres($client, array $collection = array())
{
Expand All @@ -226,6 +228,28 @@ protected function collectGenres($client, array $collection = array())
return $genres;
}

/**
* Collect all genres from an array
*
* @param $client
* @param array $collection
* @param object $object
* @return Collection
*/
protected function collectGenericCollection($client, array $collection = array(), $object)
{
$collectionObject = new Collection();

foreach($collection as $item) {
$class = get_class($object);
$model = $class::fromArray($client, $item);

$collectionObject->addObject($model);
}

return $collectionObject;
}

/**
* Transforms an under_scored_string to a camelCasedOne
*
Expand Down
11 changes: 10 additions & 1 deletion lib/Tmdb/Model/Collection/Credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ class Credits {
/**
* @var Cast
*/
private $cast;
public $cast;

/**
* @var Crew
*/
private $crew;

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

/**
* @param \Tmdb\Model\Collection\People\Cast $cast
* @return $this
Expand Down
Loading

0 comments on commit 8d126cd

Please sign in to comment.