1<?php
2/**
3 * This file is part of the Tmdb PHP API created by Michael Roterman.
4 *
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
7 *
8 * @package Tmdb
9 * @author Michael Roterman <michael@wtfz.net>
10 * @copyright (c) 2013, Michael Roterman
11 * @version 0.0.1
12 */
13namespace Tmdb\Model;
14
15use Tmdb\Model\Collection\CreditsCollection;
16use Tmdb\Model\Common\ExternalIds;
17use Tmdb\Model\Common\GenericCollection;
18use Tmdb\Model\Collection\Images;
19use Tmdb\Model\Collection\People\PersonInterface;
20use Tmdb\Model\Image\ProfileImage;
21
22/**
23 * Class Person
24 * @package Tmdb\Model
25 */
26class Person extends AbstractModel implements PersonInterface
27{
28    /**
29     * @var bool
30     */
31    private $adult;
32
33    /**
34     * @var array
35     */
36    private $alsoKnownAs = [];
37
38    /**
39     * @var string
40     */
41    private $biography;
42    /**
43     * @var \DateTime
44     */
45    private $birthday;
46
47    /**
48     * @var \DateTime|boolean
49     */
50    private $deathday;
51
52    /**
53     * @var string
54     */
55    private $homepage;
56
57    /**
58     * @var integer
59     */
60    private $id;
61
62    /**
63     * @var string
64     */
65    private $name;
66
67    /**
68     * @var string
69     */
70    private $placeOfBirth;
71
72    /**
73     * @var string
74     */
75    private $profilePath;
76
77    /**
78     * @var ProfileImage
79     */
80    private $profileImage;
81
82    /**
83     * @var float
84     */
85    private $popularity;
86
87    /**
88     * @var Common\GenericCollection
89     */
90    protected $knownFor;
91
92    /**
93     * @var CreditsCollection\MovieCredits
94     */
95    protected $movieCredits;
96
97    /**
98     * @var CreditsCollection\TvCredits
99     */
100    protected $tvCredits;
101
102    /**
103     * @var CreditsCollection\CombinedCredits
104     */
105    protected $combinedCredits;
106
107    /**
108     * @var Collection\Images
109     */
110    protected $images;
111
112    /**
113     * @var Common\GenericCollection
114     */
115    protected $changes;
116
117    /**
118     * External Ids
119     *
120     * @var ExternalIds
121     */
122    protected $externalIds;
123
124    /**
125     * @var GenericCollection
126     */
127    protected $taggedImages;
128
129    protected $gender = 0;
130
131    public static $properties = [
132        'adult',
133        'also_known_as',
134        'biography',
135        'birthday',
136        'deathday',
137        'homepage',
138        'id',
139        'name',
140        'place_of_birth',
141        'profile_path',
142        'gender',
143        'popularity'
144    ];
145
146    /**
147     * Constructor
148     *
149     * Set all default collections
150     */
151    public function __construct()
152    {
153        $this->movieCredits    = new CreditsCollection\MovieCredits();
154        $this->tvCredits       = new CreditsCollection\TvCredits();
155        $this->combinedCredits = new CreditsCollection\CombinedCredits();
156        $this->images          = new Images();
157        $this->changes         = new GenericCollection();
158        $this->externalIds     = new ExternalIds();
159        $this->knownFor        = new GenericCollection();
160    }
161
162    /**
163     * @param  boolean $adult
164     * @return $this
165     */
166    public function setAdult($adult)
167    {
168        $this->adult = $adult;
169
170        return $this;
171    }
172
173    /**
174     * @return boolean
175     */
176    public function getAdult()
177    {
178        return $this->adult;
179    }
180
181    /**
182     * @param  array $alsoKnownAs
183     * @return $this
184     */
185    public function setAlsoKnownAs($alsoKnownAs)
186    {
187        $this->alsoKnownAs = $alsoKnownAs;
188
189        return $this;
190    }
191
192    /**
193     * @return mixed
194     */
195    public function getAlsoKnownAs()
196    {
197        return $this->alsoKnownAs;
198    }
199
200    /**
201     * @param  string $biography
202     * @return $this
203     */
204    public function setBiography($biography)
205    {
206        $this->biography = $biography;
207
208        return $this;
209    }
210
211    /**
212     * @return string
213     */
214    public function getBiography()
215    {
216        return $this->biography;
217    }
218
219    /**
220     * @param  mixed $birthday
221     * @return $this
222     */
223    public function setBirthday($birthday)
224    {
225        if (!$birthday instanceof \DateTime) {
226            $birthday = new \DateTime($birthday);
227        }
228
229        $this->birthday = $birthday;
230
231        return $this;
232    }
233
234    /**
235     * @return \DateTime
236     */
237    public function getBirthday()
238    {
239        return $this->birthday;
240    }
241
242    /**
243     * @param  GenericCollection $changes
244     * @return $this
245     */
246    public function setChanges(GenericCollection $changes)
247    {
248        $this->changes = $changes;
249
250        return $this;
251    }
252
253    /**
254     * @return GenericCollection
255     */
256    public function getChanges()
257    {
258        return $this->changes;
259    }
260
261    /**
262     * @param  mixed $deathday
263     * @return $this
264     */
265    public function setDeathday($deathday)
266    {
267        if (!$deathday instanceof \DateTime && !empty($deathday)) {
268        	// Is the format Y-m-d ?
269        	if(strtotime($deathday) === false) {
270        		$deathday = \DateTime::createFromFormat('Y-d-m', $deathday);
271        	} else {
272        		$deathday = new \DateTime($deathday);
273        	}
274        }
275
276        if (empty($deathday)) {
277            $deathday = false;
278        }
279
280        $this->deathday = $deathday;
281
282        return $this;
283    }
284
285    /**
286     * @return mixed
287     */
288    public function getDeathday()
289    {
290        return $this->deathday;
291    }
292
293    /**
294     * @param  string $homepage
295     * @return $this
296     */
297    public function setHomepage($homepage)
298    {
299        $this->homepage = $homepage;
300
301        return $this;
302    }
303
304    /**
305     * @return string
306     */
307    public function getHomepage()
308    {
309        return $this->homepage;
310    }
311
312    /**
313     * @param  mixed $id
314     * @return $this
315     */
316    public function setId($id)
317    {
318        $this->id = (int) $id;
319
320        return $this;
321    }
322
323    /**
324     * @return integer
325     */
326    public function getId()
327    {
328        return $this->id;
329    }
330
331    /**
332     * @param  Images $images
333     * @return $this
334     */
335    public function setImages($images)
336    {
337        $this->images = $images;
338
339        return $this;
340    }
341
342    /**
343     * @return Images
344     */
345    public function getImages()
346    {
347        return $this->images;
348    }
349
350    /**
351     * @param  string $name
352     * @return $this
353     */
354    public function setName($name)
355    {
356        $this->name = $name;
357
358        return $this;
359    }
360
361    /**
362     * @return string
363     */
364    public function getName()
365    {
366        return $this->name;
367    }
368
369    /**
370     * @param  string $placeOfBirth
371     * @return $this
372     */
373    public function setPlaceOfBirth($placeOfBirth)
374    {
375        $this->placeOfBirth = $placeOfBirth;
376
377        return $this;
378    }
379
380    /**
381     * @return string
382     */
383    public function getPlaceOfBirth()
384    {
385        return $this->placeOfBirth;
386    }
387
388    /**
389     * @param  string $profilePath
390     * @return $this
391     */
392    public function setProfilePath($profilePath)
393    {
394        $this->profilePath = $profilePath;
395
396        return $this;
397    }
398
399    /**
400     * @return string
401     */
402    public function getProfilePath()
403    {
404        return $this->profilePath;
405    }
406
407    /**
408     * @param  ProfileImage $profileImage
409     * @return $this
410     */
411    public function setProfileImage(ProfileImage $profileImage)
412    {
413        $this->profileImage = $profileImage;
414
415        return $this;
416    }
417
418    /**
419     * @return ProfileImage
420     */
421    public function getProfileImage()
422    {
423        return $this->profileImage;
424    }
425
426    /**
427     * @param  \Tmdb\Model\Collection\CreditsCollection\CombinedCredits $combinedCredits
428     * @return $this
429     */
430    public function setCombinedCredits($combinedCredits)
431    {
432        $this->combinedCredits = $combinedCredits;
433
434        return $this;
435    }
436
437    /**
438     * @return \Tmdb\Model\Collection\CreditsCollection\CombinedCredits
439     */
440    public function getCombinedCredits()
441    {
442        return $this->combinedCredits;
443    }
444
445    /**
446     * @param  \Tmdb\Model\Collection\CreditsCollection\MovieCredits $movieCredits
447     * @return $this
448     */
449    public function setMovieCredits($movieCredits)
450    {
451        $this->movieCredits = $movieCredits;
452
453        return $this;
454    }
455
456    /**
457     * @return \Tmdb\Model\Collection\CreditsCollection\MovieCredits
458     */
459    public function getMovieCredits()
460    {
461        return $this->movieCredits;
462    }
463
464    /**
465     * @param  \Tmdb\Model\Collection\CreditsCollection\TvCredits $tvCredits
466     * @return $this
467     */
468    public function setTvCredits($tvCredits)
469    {
470        $this->tvCredits = $tvCredits;
471
472        return $this;
473    }
474
475    /**
476     * @return \Tmdb\Model\Collection\CreditsCollection\TvCredits
477     */
478    public function getTvCredits()
479    {
480        return $this->tvCredits;
481    }
482
483    /**
484     * @param  \Tmdb\Model\Common\ExternalIds $externalIds
485     * @return $this
486     */
487    public function setExternalIds($externalIds)
488    {
489        $this->externalIds = $externalIds;
490
491        return $this;
492    }
493
494    /**
495     * @return \Tmdb\Model\Common\ExternalIds
496     */
497    public function getExternalIds()
498    {
499        return $this->externalIds;
500    }
501
502    /**
503     * @param  GenericCollection $taggedImages
504     * @return $this
505     */
506    public function setTaggedImages($taggedImages)
507    {
508        $this->taggedImages = $taggedImages;
509
510        return $this;
511    }
512
513    /**
514     * @return GenericCollection
515     */
516    public function getTaggedImages()
517    {
518        return $this->taggedImages;
519    }
520
521    /**
522     * @return GenericCollection
523     */
524    public function getKnownFor()
525    {
526        return $this->knownFor;
527    }
528
529    /**
530     * @param  GenericCollection $knownFor
531     * @return $this
532     */
533    public function setKnownFor($knownFor)
534    {
535        $this->knownFor = $knownFor;
536
537        return $this;
538    }
539
540    /**
541     * @return bool
542     */
543    public function isMale()
544    {
545        return $this->gender === 2;
546    }
547
548    /**
549     * @return bool
550     */
551    public function isFemale()
552    {
553        return $this->gender === 1;
554    }
555
556    /**
557     * @return bool
558     */
559    public function isUnknownGender()
560    {
561        return $this->gender === 0;
562    }
563
564    /**
565     * @param int $gender
566     */
567    public function setGender($gender)
568    {
569        $this->gender = (int) $gender;
570    }
571
572    /**
573     * @return float
574     */
575    public function getPopularity()
576    {
577        return $this->popularity;
578    }
579
580    /**
581     * @param float $popularity
582     */
583    public function setPopularity($popularity)
584    {
585        $this->popularity = $popularity;
586    }
587}
588