summaryrefslogtreecommitdiffstats
path: root/controllers/AnimelistController.php
diff options
context:
space:
mode:
authorMichael Francis <edude03@gmail.com>2011-05-28 13:28:16 -0400
committerMichael Francis <edude03@gmail.com>2011-05-28 13:28:16 -0400
commit2389d66da849798f8d4ec5f10e3b07c11da49185 (patch)
treee22556d12982395b469a23420c662662e3e064cc /controllers/AnimelistController.php
downloadotakuhub-2389d66da849798f8d4ec5f10e3b07c11da49185.tar.xz
Initial Commit
Diffstat (limited to 'controllers/AnimelistController.php')
-rw-r--r--controllers/AnimelistController.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/controllers/AnimelistController.php b/controllers/AnimelistController.php
new file mode 100644
index 0000000..c61577a
--- /dev/null
+++ b/controllers/AnimelistController.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace app\controllers;
+
+use app\models\contentList;
+use app\models\User;
+use app\models\Anime;
+
+
+class AnimeListController extends \lithium\action\Controller {
+ public $publicActions = array('view');
+ public function view($username, $sort = "all")
+ {
+ $user = User::find('first', array('conditions' => compact('username')));
+
+
+ $watching = array();
+ $paused = array();
+ $dropped = array();
+ $planning = array();
+ $finished = array();
+
+
+ foreach($user->animelist as $entry)
+ {
+ switch($entry->my_status)
+ {
+ case "Completed": $finished[] = $entry; break;
+ case "Watching": $watching[] = $entry; break;
+ case "On-Hold" : $paused[] = $entry; break;
+ case "Dropped" : $dropped[] = $entry; break;
+ case "Plan to Watch": $planning[] = $entry; break;
+ }
+ }
+
+
+ //In the future we can use set or something
+ switch($sort)
+ {
+ case "planning" : return compact('user', 'planning'); break;
+ case "completed" : return compact('user', 'finished'); break;
+ case "onhold": return compact('user', 'paused'); break;
+ case "watching" : return compact('user', 'watching'); break;
+ case "dropped": return compact('user', 'dropped');
+ default: return compact('user', 'watching', 'paused', 'dropped', 'planning', 'finished'); break;
+ }
+ }
+
+ public function add($id)
+ {
+ if (empty($this->request->data))
+ {
+ $anime = Anime::find('first', array('conditions' => array('special_id' => $id)));
+ $entry = null;
+ return compact('anime', 'entry');
+ }
+
+ $entry = Entry::create($this->request->data);
+
+ if (isset($this->request->data['tags']))
+ {
+ $entry->my_tags = explode(' ', $this->request->data['tags']);
+ unset($this->request->data['tags']);
+ }
+
+ if ($entry->validates()) {
+ $entry->add($username);
+
+ return $this->redirects('Animelist::Index');
+ }
+
+ return $entry;
+
+ }
+
+
+} \ No newline at end of file