/** * Create an collection of an array * * @param $data * @return ResultCollection */ public function createMovieCollection($data) { $collection = new ResultCollection(); if (array_key_exists('results', $data)) { $data = $data['results']; } foreach ($data as $item) { $collection->add(null, $this->getMovieFactory()->create($item)); } return $collection; }
/** * Create a result collection * * @param array $data * @param string $method * @return ResultCollection */ public function createResultCollection($data = array(), $method = 'create') { $collection = new ResultCollection(); if (null === $data) { return $collection; } if (array_key_exists('page', $data)) { $collection->setPage($data['page']); } if (array_key_exists('total_pages', $data)) { $collection->setTotalPages($data['total_pages']); } if (array_key_exists('total_results', $data)) { $collection->setTotalResults($data['total_results']); } if (array_key_exists('results', $data)) { $data = $data['results']; } foreach ($data as $item) { $collection->add(null, $this->{$method}($item)); } return $collection; }
/** * @param string $query * @param KeywordSearchQuery $parameters * @param array $headers * * @return ResultCollection|Keyword[] */ public function searchMulti($query, KeywordSearchQuery $parameters, array $headers = array()) { $data = $this->getApi()->searchMulti($query, $this->getParameters($parameters), $headers); $collection = new ResultCollection(); if (null === $data) { return $collection; } if (array_key_exists('page', $data)) { $collection->setPage($data['page']); } if (array_key_exists('total_pages', $data)) { $collection->setTotalPages($data['total_pages']); } if (array_key_exists('total_results', $data)) { $collection->setTotalResults($data['total_results']); } if (array_key_exists('results', $data)) { foreach ($data['results'] as $item) { if ($item) { $collection->add(null, $this->processSearchMultiItem($item)); } } } return $collection; }
/** * @param ResultCollection $resultSet * @param int $selection * * @return Tv|Movie */ private function getResultSelection(ResultCollection $resultSet, $selection = 1) { $keys = $resultSet->getKeys(); if (--$selection > count($keys)) { $selection = 0; } if (!array_key_exists($selection, $keys)) { return null; } return $resultSet->get($keys[$selection]); }