/** * Create an Media/Image type which is used in calls like person/tagged_images, which contains an getMedia() * reference either referring to movies / tv shows etc. * * @param array $data * @return Image * * @throws \RuntimeException */ public function createMediaImage(array $data = array()) { if (!array_key_exists('image_type', $data)) { throw new \RuntimeException('Unable to detect the image type.'); } $type = $this->resolveImageType($data['image_type']); $image = $this->hydrate($type, $data); if (array_key_exists('media', $data) && array_key_exists('media_type', $data)) { switch ($data['media_type']) { case "movie": $factory = new MovieFactory(); break; case "tv": $factory = new TvFactory(); break; // I don't think this ever occurs, but just in case.. // I don't think this ever occurs, but just in case.. case "person": $factory = new PeopleFactory(); break; default: throw new RuntimeException(sprintf('Unrecognized media_type "%s" for method "%s::%s".', $data['media_type'], __CLASS__, __METHOD__)); } $media = $factory->create($data['media']); $image->setMedia($media); } return $this->hydrate($type, $data); }
/** * {@inheritdoc} */ public function create(array $data = array(), $person = null) { return parent::create($data, $person); }
/** * @param array $data * * @return Tv */ public function create(array $data = array()) { if (!$data) { return null; } $tvShow = new Tv(); if (array_key_exists('credits', $data)) { if (array_key_exists('cast', $data['credits'])) { $tvShow->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast'], new CastMember())); } if (array_key_exists('crew', $data['credits'])) { $tvShow->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew'], new CrewMember())); } } /** External ids */ if (array_key_exists('external_ids', $data)) { $tvShow->setExternalIds($this->hydrate(new ExternalIds(), $data['external_ids'])); } /** Genres */ if (array_key_exists('genres', $data)) { $tvShow->setGenres($this->getGenreFactory()->createCollection($data['genres'])); } /** Images */ if (array_key_exists('images', $data)) { $tvShow->setImages($this->getImageFactory()->createCollectionFromTv($data['images'])); } if (array_key_exists('backdrop_path', $data)) { $tvShow->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); } if (array_key_exists('poster_path', $data)) { $tvShow->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); } /** Translations */ if (array_key_exists('translations', $data) && null !== $data['translations']) { if (array_key_exists('translations', $data['translations'])) { $translations = $data['translations']['translations']; } else { $translations = $data['translations']; } $tvShow->setTranslations($this->createGenericCollection($translations, new Translation())); } /** Seasons */ if (array_key_exists('seasons', $data)) { $tvShow->setSeasons($this->getTvSeasonFactory()->createCollection($data['seasons'])); } /** Networks */ if (array_key_exists('networks', $data)) { $tvShow->setNetworks($this->getNetworkFactory()->createCollection($data['networks'])); } if (array_key_exists('videos', $data)) { $tvShow->setVideos($this->getVideoFactory()->createCollection($data['videos'])); } if (array_key_exists('keywords', $data) && array_key_exists('results', $data['keywords'])) { $tvShow->setKeywords($this->getKeywordFactory()->createCollection($data['keywords']['results'])); } if (array_key_exists('changes', $data)) { $tvShow->setChanges($this->getChangesFactory()->createCollection($data['changes'])); } if (array_key_exists('similar', $data)) { $tvShow->setSimilar($this->createResultCollection($data['similar'])); } if (array_key_exists('languages', $data)) { $collection = new GenericCollection(); foreach ($data['languages'] as $iso6391) { $object = new SpokenLanguage(); $object->setIso6391($iso6391); $collection->add(null, $object); } $tvShow->setLanguages($collection); } if (array_key_exists('origin_country', $data)) { $collection = new GenericCollection(); foreach ($data['origin_country'] as $iso31661) { $object = new Country(); $object->setIso31661($iso31661); $collection->add(null, $object); } $tvShow->setOriginCountry($collection); } if (array_key_exists('created_by', $data)) { $collection = new GenericCollection(); $factory = new PeopleFactory(); foreach ($data['created_by'] as $castMember) { $object = $factory->create($castMember, new CastMember()); $collection->add(null, $object); } $tvShow->setCreatedBy($collection); } return $this->hydrate($tvShow, $data); }