public function get(RESTApiRequest $request) { $genres = new \VideoGenre(); $genres->setLocale($request->getLanguage()); if (!empty($this->categories)) { $response = array(); if (count($this->categories) == 1) { $response = $this->filter($genres->getByCategoryId($this->categories[0]['id'], true)); } else { foreach ($this->categories as $category) { $response[] = array('id' => $category['id'], 'genres' => $this->filter($genres->getByCategoryId($category['id'], true))); } } return $response; } else { return $this->filter($genres->getAll(true)); } }
public function __construct(array $nested_params, array $external_params) { parent::__construct($nested_params, $external_params); $this->document = new RESTApiVideoDocument($this, $this->external_params); $this->document->controllers->add(new RESTApiVideoLink($this->nested_params)); $this->document->controllers->add(new RESTApiVideoNotEnded($this->nested_params)); $this->fields_map = array_fill_keys(array('id', "name", "description", "director", "actors", "year", "censored", "added", "genres", "genres_ids", "cover", "hd"), true); $this->manager = new \Video(); if (!empty($this->nested_params['users.id'])) { $user_id = $this->nested_params['users.id']; $user = \Stb::getById($user_id); if (empty($user)) { throw new RESTNotFound("User nor found"); } $user_obj = \User::getInstance(); $this->favorites = $user_obj->getVideoFavorites(); $this->not_ended = $user_obj->getNotEndedVideo(); } if (!empty($this->nested_params['video.category']) && empty($this->nested_params['video.genre'])) { $category_id = $this->nested_params['video.category']; $genre = new \VideoGenre(); $genres = $genre->getByCategoryId($category_id, true); if (empty($genres)) { throw new RESTNotFound("Genres list is empty"); } $this->genres_ids = array_map(function ($genre) { return (int) $genre['_id']; }, $genres); } else { if (!empty($this->nested_params['video.genre']) && empty($this->nested_params['video.category'])) { $genre = new \VideoGenre(); $genres = $genre->getById($this->nested_params['video.genre'], true); if (empty($genres)) { throw new RESTNotFound("Genres list is empty"); } $genres = array_map(function ($genre) { return (int) $genre['id']; }, $genres); $this->genres_ids = $genres; } else { if (!empty($this->nested_params['video.genre']) && !empty($this->nested_params['video.category'])) { $genre = new \VideoGenre(); $genres = $genre->getByIdAndCategory($this->nested_params['video.genre'], $this->nested_params['video.category'], true); if (empty($genres)) { throw new RESTNotFound("Genres list is empty"); } $this->genres_ids = array($genres['id']); } } } }