Skip to content

Commit b77383a

Browse files
committed
Merge pull request #68 from wtfzdotnet/issue-54
Adding known_for to person
2 parents 2117952 + 2077a8f commit b77383a

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

lib/Tmdb/Factory/AbstractFactory.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,36 @@ protected function createCustomCollection($data = [], $class, $collection)
158158
return $collection;
159159
}
160160

161+
/**
162+
* Create an generic collection of an array that consists out of a mix of movies and tv shows
163+
*
164+
* @param array $data
165+
* @return GenericCollection
166+
*/
167+
protected function createGenericCollectionFromMediaTypes($data = [])
168+
{
169+
$movieFactory = new MovieFactory($this->getHttpClient());
170+
$tvFactory = new TvFactory($this->getHttpClient());
171+
$collection = new GenericCollection();
172+
173+
foreach ($data as $item) {
174+
switch ($item['media_type']) {
175+
case "movie":
176+
$collection->add(null, $movieFactory->create($item));
177+
break;
178+
179+
case "tv":
180+
$collection->add(null, $tvFactory->create($item));
181+
break;
182+
183+
default:
184+
throw new \RuntimeException('Unknown media type "%s"', $item['media_type']);
185+
}
186+
}
187+
188+
return $collection;
189+
}
190+
161191
/**
162192
* Create rating
163193
*

lib/Tmdb/Factory/PeopleFactory.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public function create(array $data = [], $person = null)
9898
);
9999
}
100100

101+
/** External ids */
102+
if (array_key_exists('known_for', $data)) {
103+
$person->setKnownFor(
104+
$this->createGenericCollectionFromMediaTypes($data['known_for'])
105+
);
106+
}
107+
101108
/** Credits */
102109
$this->applyCredits($data, $person);
103110
}

lib/Tmdb/Model/Person.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class Person extends AbstractModel implements PersonInterface
7979
*/
8080
private $profileImage;
8181

82+
/**
83+
* @var Common\GenericCollection
84+
*/
85+
protected $knownFor;
86+
8287
/**
8388
* @var CreditsCollection\MovieCredits
8489
*/
@@ -142,6 +147,7 @@ public function __construct()
142147
$this->images = new Images();
143148
$this->changes = new GenericCollection();
144149
$this->externalIds = new ExternalIds();
150+
$this->knownFor = new GenericCollection();
145151
}
146152

147153
/**
@@ -497,4 +503,23 @@ public function getTaggedImages()
497503
{
498504
return $this->taggedImages;
499505
}
506+
507+
/**
508+
* @return GenericCollection
509+
*/
510+
public function getKnownFor()
511+
{
512+
return $this->knownFor;
513+
}
514+
515+
/**
516+
* @param GenericCollection $knownFor
517+
* @return $this
518+
*/
519+
public function setKnownFor($knownFor)
520+
{
521+
$this->knownFor = $knownFor;
522+
523+
return $this;
524+
}
500525
}

0 commit comments

Comments
 (0)