From 1f30528f63a7fc1f33cfa99eaef5117b71d716a5 Mon Sep 17 00:00:00 2001 From: Michael Francis Date: Sun, 5 Jun 2011 11:58:55 -0400 Subject: Fixed issue when add page reloads due to error (anime wasn't being returned, so the view would say "Find an anime" and would not have anime data in the hidden fields) --- controllers/AnimelistController.php | 63 +++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'controllers') diff --git a/controllers/AnimelistController.php b/controllers/AnimelistController.php index 7eb8c4c..874ba7f 100644 --- a/controllers/AnimelistController.php +++ b/controllers/AnimelistController.php @@ -65,34 +65,57 @@ class AnimeListController extends \lithium\action\Controller { //Ensure the correct user here public function add($id = null) { - if (empty($this->request->data)) + //If id is null, + if ('id' == null) { + //Redirect them to the search page + return $this->redirect('Animelist::addsearch'); + } + + //Find the requested anime + $anime = Anime::find('first', array('conditions' => array('special_id' => $id))); + $entry = null; + + + //If data was submitted + if ($this->request->data) { - if ('id' != null) + //Create an entry with the data + $entry = Entry::create($this->request->data); + + //Get the current user + $user = Auth::check('default'); + $username = $user['username']; + + //Break the tags into an array + if (isset($this->request->data['tags'])) { - $anime = Anime::find('first', array('conditions' => array('special_id' => $id))); - $entry = null; - return compact('anime', 'entry'); + $entry->my_tags = explode(',', $this->request->data['tags']); + unset($this->request->data['tags']); + } + + //If the entry is valid + if ($entry->validates()) { + //Store it, :TODO: make sure this passes at some point, silent failure sucks + $entry->add($username); + + //Redirect the user to their anime list + return $this->redirect("/animelist/view/$username"); } - return array('anime' => null, 'entry' => null); } - $entry = Entry::create($this->request->data); - $user = Auth::check('default'); - $username = $user['username']; - if (isset($this->request->data['tags'])) + return compact('entry', 'anime'); + } + + public function edit($id = null) + { + if (id != null) { - $entry->my_tags = explode(' ', $this->request->data['tags']); - unset($this->request->data['tags']); + //Get the ani } - - if ($entry->validates()) { - $entry->add($username); - - return $this->redirect("/animelist/view/$username"); + else + { + //Error message } - - return $entry; - } -- cgit v1.2.3