Quellcode durchsuchen

Implemented / Fixed adding

Michael Francis vor 14 Jahren
Ursprung
Commit
88666d9644

+ 30 - 8
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; 

+ 47 - 0
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));
+
 	}
 }

+ 24 - 17
views/Anime_list/add.html.php

@@ -1,33 +1,40 @@
 <?php if (empty($anime)): ?>
-<p> Anime not found </p>
+<h2 class="ribbon full">Find an Anime:</h2>
+<div class="triangle-ribbon"></div>
+<br class="clear" />
 <?php else: ?>
-<h1><?= $anime->series_title ?></h1>
+<h2 class="ribbon full"><?= $anime->title ?></h2>
+<div class="triangle-ribbon"></div>
+<br class="clear" />
+<?php endif; ?>
 <?php 
 	echo $this->form->create($entry);
-	echo $this->form->hidden('series_animedb_id', array('value' => $anime->special_id));
-					/*
-					<series_title><![CDATA[.hack//Sign]]></series_title>
-					<series_type>TV</series_type>
-					<series_episodes>26</series_episodes>
-					*/
+
+	//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()	//			<my_dvd></my_dvd>
-					//<my_storage></my_storage>
 	echo $this->form->label('my_status', 'Status');
-	echo $this->form->select('my_status', array('Plan to Watch', 'On-Hold', 'Completed', 'Watching'), array('value' => 0));				//<my_status>Plan to Watch</my_status>
+	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!');
-?>
-<?php endif; ?>
+?>

+ 1 - 1
views/Anime_list/view.html.php

@@ -41,7 +41,7 @@ echo "</table>";
 <br class="cl" />	
 </div>
 <div class="grid_2">
-<button class="large" style="margin-left:40px; margin-top:10px"><a href="/animelist/add?iframe=true&height=100%&width=100%">Add</a></button>
+<button class="large" style="margin-left:40px; margin-top:10px"><a href="/animelist/addsearch">Add</a></button>
 </div>
 </div>
 

+ 21 - 0
views/anime_list/addsearch.html.php

@@ -0,0 +1,21 @@
+
+<?= $this->form->create(null, array('method' => 'get')); ?>
+	<?= $this->form->text('Search', array('value' => 'Search for...')); ?>
+	<?= $this->form->submit('Go', array('class' => 'button')); ?>
+<?= $this->form->end(); ?>
+<?php if (isset($content)): ?>
+	<table class="table">
+	<tr><th>Entry #</th><th>Name</th><th>Type</th><th>Episodes</th><th>Score</th><th>Add</th></tr>
+	<?php $i = 1; foreach($content as $result): ?>
+		<tr>
+			<td># <?= $i ?></td>
+			<td><?= $result->title ?></td>
+			<td><?= $result->view_type ?></td>
+			<td><?= $result->episode_count ?></td>
+			<td><?= $result->mal_score ?></td>
+			<td><button class="green"><a href="/animelist/add/<?= $result->special_id ?>">Add</a></button></td>
+			<?php $i++; ?>
+		</tr>
+	<?php endforeach; ?>
+	</table>
+<?php endif; ?>