From 212c779552fd673a0bc1fdc299885ab6f07f5bab Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Mon, 11 Jan 2016 13:33:56 -0500 Subject: [PATCH] Update collection to use flash messages and more intelligent redirects --- .../AnimeClient/Controller/Collection.php | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Aviat/AnimeClient/Controller/Collection.php b/src/Aviat/AnimeClient/Controller/Collection.php index 52dec4e3..8b31a0f7 100644 --- a/src/Aviat/AnimeClient/Controller/Collection.php +++ b/src/Aviat/AnimeClient/Controller/Collection.php @@ -110,11 +110,13 @@ class Collection extends BaseController { */ public function form($id = NULL) { + $this->set_session_redirect(); + $action = (is_null($id)) ? "Add" : "Edit"; $this->outputHTML('collection/' . strtolower($action), [ 'action' => $action, - 'action_url' => $this->urlGenerator->full_url("collection/" . strtolower($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) : [] @@ -129,14 +131,17 @@ class Collection extends BaseController { public function edit() { $data = $this->request->post->get(); - if ( ! array_key_exists('hummingbird_id', $data)) + if (array_key_exists('hummingbird_id', $data)) { - $this->redirect("collection/view", 303); + $this->anime_collection_model->update($data); + $this->set_flash_message('Successfully updated collection item.', 'success'); + } + else + { + $this->set_flash_message('Failed to update collection item', 'error'); } - $this->anime_collection_model->update($data); - - $this->redirect("collection/view", 303); + $this->session_redirect(); } /** @@ -147,14 +152,17 @@ class Collection extends BaseController { public function add() { $data = $this->request->post->get(); - if ( ! array_key_exists('id', $data)) + if (array_key_exists('id', $data)) { - $this->redirect("collection/view", 303); + $this->anime_collection_model->add($data); + $this->set_flash_message('Successfully added collection item', 'success'); + } + else + { + $this->set_flash_message('Failed to add collection item.', 'error'); } - $this->anime_collection_model->add($data); - - $this->redirect("collection/view", 303); + $this->session_redirect(); } /**