Skip to content

Commit

Permalink
Updating Models
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 20, 2014
1 parent deab27c commit d43d291
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 38 deletions.
50 changes: 20 additions & 30 deletions lib/Tmdb/Model/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
*/
namespace Tmdb\Model;

use Tmdb\Client;
use Tmdb\Model\Image\LogoImage;

class Company extends AbstractModel {

private $description;
private $headquarters;
private $homepage;
private $id;
private $logo;
private $logoPath;
private $name;
private $parentCompany;
Expand All @@ -34,35 +35,6 @@ class Company extends AbstractModel {
'parent_company'
);

/**
* Convert an array to an hydrated object
*
* @param Client $client
* @param array $data
* @return $this
*/
public static function fromArray(Client $client, array $data)
{
$genre = new Company($data['id']);
//$genre->setClient($client);

return $genre->hydrate($data);
}

/**
* Load a company with the given identifier
*
* @param Client $client
* @param $id
* @param $options
* @return $this
*/
public static function load(Client $client, $id, array $options = array()) {
$data = $client->api('companies')->getCompany($id, $options);

return Company::fromArray($client, $data);
}

/**
* @param mixed $description
* @return $this
Expand Down Expand Up @@ -135,6 +107,24 @@ public function getId()
return $this->id;
}

/**
* @param LogoImage $logo
* @return $this
*/
public function setLogo(LogoImage $logo)
{
$this->logo = $logo;
return $this;
}

/**
* @return LogoImage
*/
public function getLogo()
{
return $this->logo;
}

/**
* @param mixed $logoPath
* @return $this
Expand Down
13 changes: 6 additions & 7 deletions lib/Tmdb/Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
namespace Tmdb\Model;

use Tmdb\Client;
use Tmdb\Model\Common\GenericCollection;

class Configuration extends AbstractModel {
Expand All @@ -33,35 +32,35 @@ class Configuration extends AbstractModel {
);

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

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

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

/**
* @return \Tmdb\Model\Common\Collection
* @return GenericCollection
*/
public function getImages()
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Model/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function getJob()
* @param ProfileImage $profile
* @return $this
*/
public function setProfile($profile)
public function setProfile(ProfileImage $profile)
{
$this->profile = $profile;
return $this;
Expand Down
38 changes: 38 additions & 0 deletions lib/Tmdb/Repository/CompanyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
namespace Tmdb\Repository;

use Tmdb\Factory\CompanyFactory;
use Tmdb\Factory\MovieFactory;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Company;
use Tmdb\Model\Movie;

class CompanyRepository extends AbstractRepository {
/**
Expand All @@ -31,6 +33,22 @@ public function load($id, array $parameters = array(), array $headers = array())
return CompanyFactory::create($data);
}


/**
* Get the list of movies associated with a particular company.
*
* @param integer $id
* @param array $parameters
* @param array $headers
* @return Movie[]
*/
public function getMovies($id, array $parameters = array(), array $headers = array())
{
return $this->createMovieCollection(
$this->getApi()->getMovies($id, $this->parseQueryParameters($parameters), $this->parseHeaders($headers))
);
}

/**
* Return the related API class
*
Expand All @@ -40,4 +58,24 @@ public function getApi()
{
return $this->getClient()->getCompaniesApi();
}

/**
* Create an collection of an array
*
* @param $data
* @return Movie[]
*/
private function createMovieCollection($data){
$collection = new GenericCollection();

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

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

return $collection;
}
}

0 comments on commit d43d291

Please sign in to comment.