vfalies /
tmdb
| 1 | <?php declare(strict_types=1); |
||
| 2 | /** |
||
| 3 | * This file is part of the Tmdb package. |
||
| 4 | * |
||
| 5 | * (c) Vincent Faliès <[email protected]> |
||
| 6 | * |
||
| 7 | * For the full copyright and license information, please view the LICENSE |
||
| 8 | * file that was distributed with this source code. |
||
| 9 | * |
||
| 10 | * @author Vincent Faliès <[email protected]> |
||
| 11 | * @copyright Copyright (c) 2017 |
||
| 12 | */ |
||
| 13 | |||
| 14 | |||
| 15 | namespace VfacTmdb\Items; |
||
| 16 | |||
| 17 | use VfacTmdb\Abstracts\Item; |
||
| 18 | use VfacTmdb\Interfaces\Items\CollectionInterface; |
||
| 19 | |||
| 20 | use VfacTmdb\Exceptions\NotFoundException; |
||
| 21 | use VfacTmdb\Traits\ElementTrait; |
||
| 22 | use VfacTmdb\Results; |
||
| 23 | use VfacTmdb\Interfaces\TmdbInterface; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Class to manipulate a collection |
||
| 27 | * @package Tmdb |
||
| 28 | * @author Vincent Faliès <[email protected]> |
||
| 29 | * @copyright Copyright (c) 2017 |
||
| 30 | */ |
||
| 31 | class Collection extends Item implements CollectionInterface |
||
| 32 | { |
||
| 33 | use ElementTrait; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 34 | |||
| 35 | /** |
||
| 36 | * Configuration |
||
| 37 | * @var \stdClass |
||
| 38 | */ |
||
| 39 | protected $conf = null; |
||
| 40 | /** |
||
| 41 | * Id |
||
| 42 | * @var int |
||
| 43 | */ |
||
| 44 | protected $id = null; |
||
| 45 | /** |
||
| 46 | * Tmdb object |
||
| 47 | * @var TmdbInterface |
||
| 48 | */ |
||
| 49 | protected $tmdb = null; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Constructor |
||
| 53 | * @param TmdbInterface $tmdb |
||
| 54 | * @param int $collection_id |
||
| 55 | * @param array $options |
||
| 56 | */ |
||
| 57 | 57 | public function __construct(TmdbInterface $tmdb, int $collection_id, array $options = array()) |
|
| 58 | { |
||
| 59 | 57 | parent::__construct($tmdb, $collection_id, $options, 'collection'); |
|
| 60 | |||
| 61 | 54 | $this->setElementTrait($this->data); |
|
| 62 | 54 | } |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Get collection ID |
||
| 66 | * @return int |
||
| 67 | */ |
||
| 68 | 6 | public function getId() : int |
|
| 69 | { |
||
| 70 | 6 | return $this->id; |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get collection name |
||
| 75 | * @return string |
||
| 76 | * @throws NotFoundException |
||
| 77 | */ |
||
| 78 | 6 | public function getName() : string |
|
| 79 | { |
||
| 80 | 6 | if (isset($this->data->name)) { |
|
| 81 | 3 | return $this->data->name; |
|
| 82 | } |
||
| 83 | 3 | $this->logger->error('Collection name not found', array('collection_id' => $this->id)); |
|
| 84 | 3 | throw new NotFoundException; |
|
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Get collection parts |
||
| 89 | * @return \Generator |
||
| 90 | */ |
||
| 91 | 6 | public function getParts() : \Generator |
|
| 92 | { |
||
| 93 | 6 | if (!empty($this->data->parts)) { |
|
| 94 | 3 | foreach ($this->data->parts as $part) { |
|
| 95 | 3 | $movie = new Results\Movie($this->tmdb, $part); |
|
| 96 | 3 | yield $movie; |
|
| 97 | } |
||
| 98 | } |
||
| 99 | 6 | } |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Get collection backdrops |
||
| 103 | * @return \Generator|Results\Image |
||
| 104 | */ |
||
| 105 | 27 | public function getBackdrops() : \Generator |
|
| 106 | { |
||
| 107 | 27 | $params = []; |
|
| 108 | 27 | $this->tmdb->checkOptionLanguage($this->params, $params); |
|
| 109 | 27 | $data = $this->tmdb->getRequest('collection/' . (int) $this->id . '/images', $params); |
|
| 110 | |||
| 111 | 27 | foreach ($data->backdrops as $b) { |
|
| 112 | 27 | $image = new Results\Image($this->tmdb, $this->id, $b); |
|
| 113 | 27 | yield $image; |
|
| 114 | } |
||
| 115 | 3 | } |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Get collection posters |
||
| 119 | * @return \Generator|Results\Image |
||
| 120 | */ |
||
| 121 | 3 | public function getPosters() : \Generator |
|
| 122 | { |
||
| 123 | 3 | $params = []; |
|
| 124 | 3 | $this->tmdb->checkOptionLanguage($this->params, $params); |
|
| 125 | 3 | $data = $this->tmdb->getRequest('collection/' . (int) $this->id . '/images', $params); |
|
| 126 | |||
| 127 | 3 | foreach ($data->posters as $b) { |
|
| 128 | 3 | $image = new Results\Image($this->tmdb, $this->id, $b); |
|
| 129 | 3 | yield $image; |
|
| 130 | } |
||
| 131 | 3 | } |
|
| 132 | } |
||
| 133 |