summaryrefslogtreecommitdiffstats
path: root/controllers
diff options
context:
space:
mode:
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;
-
}