From 88666d9644f06f2dd37516c95661f24d9f2eadbe Mon Sep 17 00:00:00 2001 From: Michael Francis Date: Sun, 29 May 2011 16:35:13 -0400 Subject: Implemented / Fixed adding --- controllers/AnimelistController.php | 38 +++++++++++++++++++++++------- models/Entry.php | 47 +++++++++++++++++++++++++++++++++++++ views/Anime_list/add.html.php | 41 ++++++++++++++++++-------------- views/Anime_list/view.html.php | 2 +- views/anime_list/addsearch.html.php | 21 +++++++++++++++++ 5 files changed, 123 insertions(+), 26 deletions(-) create mode 100644 views/anime_list/addsearch.html.php diff --git a/controllers/AnimelistController.php b/controllers/AnimelistController.php index c61577a..7eb8c4c 100644 --- a/controllers/AnimelistController.php +++ b/controllers/AnimelistController.php @@ -5,24 +5,29 @@ namespace app\controllers; use app\models\contentList; use app\models\User; use app\models\Anime; +use app\models\Entry; +use \lithium\security\Auth; 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(); - + //The anime list comes back as a DocumentArray, so we can + //parse through them with a foreach + //For each entry, foreach($user->animelist as $entry) { + //Sort it based on status switch($entry->my_status) { case "Completed": $finished[] = $entry; break; @@ -46,16 +51,33 @@ class AnimeListController extends \lithium\action\Controller { } } - public function add($id) + public function addsearch() + { + if (isset($this->request->query['Search'])) { + $searchParam = '/' . $this->request->query['Search'] . '/i'; + if($this->request->query['Search']) + { + return Anime::search($searchParam); + } + } + } + + //Ensure the correct user here + public function add($id = null) { if (empty($this->request->data)) { - $anime = Anime::find('first', array('conditions' => array('special_id' => $id))); - $entry = null; - return compact('anime', 'entry'); + if ('id' != null) + { + $anime = Anime::find('first', array('conditions' => array('special_id' => $id))); + $entry = null; + return compact('anime', 'entry'); + } + 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'])) { @@ -66,7 +88,7 @@ class AnimeListController extends \lithium\action\Controller { if ($entry->validates()) { $entry->add($username); - return $this->redirects('Animelist::Index'); + return $this->redirect("/animelist/view/$username"); } return $entry; diff --git a/models/Entry.php b/models/Entry.php index 3b27393..e7d089b 100644 --- a/models/Entry.php +++ b/models/Entry.php @@ -2,8 +2,55 @@ namespace app\models; +use app\models\Users; + Class entry extends \lithium\data\Model { public static function __init() { parent::__init(); + + //Validators go here + } + + /* Things to validate: + ["my_watched_episodes"]=> + string(2) "12" is equal to or less than anime->episode_count + ["my_start_date"]=> + string(5) "today" is a date + ["my_finish_date"]=> + string(5) "today" is a date later than start date + ["my_score"]=> + string(3) "15 " is between 0 and 10 + ["my_status"]=> + string(1) "3" + ["my_comments"]=> + string(18) "This anime is tits" + ["my_times_watched"]=> + string(1) "2" is int + ["rewatch_value"]=> + string(1) "2" + ["tags"]=> + string(46) "winning tigerblood childrens_show your_grandma" + ["rewatching"]=> + string(0) "" + **/ + + /* + public function add($entity, $username) + { + var_dump($entity->_data); + exit(); + $updateData = array('$push' => array('animelist' => $entity)); + $conditions = array('username' => $username); + $result = Entry::update($updateData, $conditions, array('atomic' => false)); + return $result; + } + */ + + public function add($entity, $username) + { + $user = User::find('first', array('conditions' => compact('username'))); + $user->animelist[] = $entity; + return $user->save(null, array('validate' => false)); + } } \ No newline at end of file diff --git a/views/Anime_list/add.html.php b/views/Anime_list/add.html.php index 5e9699a..c5e2fea 100644 --- a/views/Anime_list/add.html.php +++ b/views/Anime_list/add.html.php @@ -1,33 +1,40 @@ -

Anime not found

+

Find an Anime:

+
+
-

series_title ?>

+

title ?>

+
+
+ form->create($entry); - echo $this->form->hidden('series_animedb_id', array('value' => $anime->special_id)); - /* - - TV - 26 - */ + + //Hidden because the user can't change these. + //These are stored in the anime list for faster lookup times, + //So we can avoid getting this data live for every anime. + if (isset($anime)) { + echo $this->form->hidden('series_animedb_id', array('value' => $anime->special_id)); + echo $this->form->hidden('series_title', array('value' => $anime->title)); + echo $this->form->hidden('series_type', array('value' => $anime->view_type)); + echo $this->form->hidden('series_episodes', array('value' => $anime->episode_count)); + } echo $this->form->field('my_watched_episodes', array('label' => 'Watched Episodes')); echo $this->form->field('my_start_date', array('label' => 'Start Date')); echo $this->form->field('my_finish_date', array('label' => 'Finish Date')); - //Make this Ajax in the future, but it will have to be removed - //If we partner with CR or otherwise - //echo $this->form->field('my_fansub_group', ); echo $this->form->field('my_score', array('label' => 'Score')); - //echo $this->form->field() // - // echo $this->form->label('my_status', 'Status'); - echo $this->form->select('my_status', array('Plan to Watch', 'On-Hold', 'Completed', 'Watching'), array('value' => 0)); //Plan to Watch + echo $this->form->select('my_status', array('Plan to Watch' => 'Plan to Watch', + 'On-Hold' => 'On-Hold', + 'Completed' => 'Completed', + 'Watching' => 'Watching', + 'Dropped' => 'Dropped')); echo $this->form->field('my_comments', array('label' => 'Comments')); echo $this->form->field('my_times_watched', array('label' => 'Times Watched')); echo $this->form->label('rewatch_value', 'Rewatch Value'); echo $this->form->select('rewatch_value', array('High', 'Medium', 'Low', 'None'), array('value' => 0)); echo $this->form->field('tags', array('type' => 'textarea')); - echo $this->form->field('rewatching', array('value' => false)); + echo $this->form->checkbox('rewatching', array('label' =>'Rewatching?', 'value' => false)); echo $this->form->submit('Save!'); -?> - \ No newline at end of file +?> \ No newline at end of file diff --git a/views/Anime_list/view.html.php b/views/Anime_list/view.html.php index 2dec697..4c552d8 100644 --- a/views/Anime_list/view.html.php +++ b/views/Anime_list/view.html.php @@ -41,7 +41,7 @@ echo "";
- +
diff --git a/views/anime_list/addsearch.html.php b/views/anime_list/addsearch.html.php new file mode 100644 index 0000000..eb5cbe1 --- /dev/null +++ b/views/anime_list/addsearch.html.php @@ -0,0 +1,21 @@ + +form->create(null, array('method' => 'get')); ?> + form->text('Search', array('value' => 'Search for...')); ?> + form->submit('Go', array('class' => 'button')); ?> +form->end(); ?> + + + + + + + + + + + + + + +
Entry #NameTypeEpisodesScoreAdd
# title ?>view_type ?>episode_count ?>mal_score ?>
+ \ No newline at end of file -- cgit v1.2.3