urlGenerator = $container->get('url-generator'); $this->anime_model = $container->get('anime-model'); $this->anime_collection_model = $container->get('anime-collection-model'); $this->base_data = array_merge($this->base_data, [ 'menu_name' => 'collection', 'url_type' => 'anime', 'other_type' => 'manga', 'config' => $this->config, ]); } /** * Search for anime * * @return void */ public function search() { $query = $this->request->query->get('query'); $this->outputJSON($this->anime_model->search($query)); } /** * Show the anime collection page * * @param string $view * @return void */ public function index($view) { $view_map = [ '' => 'cover', 'list' => 'list' ]; $data = $this->anime_collection_model->get_collection(); $this->outputHTML('collection/' . $view_map[$view], [ 'title' => $this->config->get('whose_list') . "'s Anime Collection", 'sections' => $data, 'genres' => $this->anime_collection_model->get_genre_list() ]); } /** * Show the anime collection add/edit form * * @param integer|null $id * @return void */ public function form($id = NULL) { $action = (is_null($id)) ? "Add" : "Edit"; $this->outputHTML('collection/' . strtolower($action), [ 'action' => $action, 'action_url' => $this->urlGenerator->full_url("collection/" . strtolower($action)), 'title' => $this->config->get('whose_list') . " Anime Collection · {$action}", 'media_items' => $this->anime_collection_model->get_media_type_list(), 'item' => ($action === "Edit") ? $this->anime_collection_model->get($id) : [] ]); } /** * Update a collection item * * @return void */ public function edit() { $data = $this->request->post->get(); if ( ! array_key_exists('hummingbird_id', $data)) { $this->redirect("collection/view", 303); } $this->anime_collection_model->update($data); $this->redirect("collection/view", 303); } /** * Add a collection item * * @return void */ public function add() { $data = $this->request->post->get(); if ( ! array_key_exists('id', $data)) { $this->redirect("collection/view", 303); } $this->anime_collection_model->add($data); $this->redirect("collection/view", 303); } /** * Remove a collection item * * @return void */ public function delete() { $data = $this->request->post->get(); if ( ! array_key_exists('id', $data)) { $this->redirect("collection/view", 303); } $this->anime_collection_model->delete($data); $this->redirect("collection/view", 303); } } // End of CollectionController.php