summaryrefslogtreecommitdiffstats
path: root/controllers
diff options
context:
space:
mode:
authorMichael Francis <edude03@gmail.com>2011-06-05 11:58:55 -0400
committerMichael Francis <edude03@gmail.com>2011-06-05 11:58:55 -0400
commit1f30528f63a7fc1f33cfa99eaef5117b71d716a5 (patch)
tree99e298aeaaa53b96480dbefb6e20b0e4fb08538c /controllers
parenta4cd3894c10332df8dd42c60c0680490d47e1e66 (diff)
downloadotakuhub-1f30528f63a7fc1f33cfa99eaef5117b71d716a5.tar.xz
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)
Diffstat (limited to 'controllers')
-rw-r--r--controllers/AnimelistController.php63
1 files changed, 43 insertions, 20 deletions
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;
-
}