浏览代码

rework a lot of search

/search will eventually search all
/search/anime searches only anime
raylu 14 年之前
父节点
当前提交
657d270864
共有 5 个文件被更改,包括 45 次插入151 次删除
  1. 2 2
      config/bootstrap/connections.php
  2. 14 45
      controllers/SearchController.php
  3. 1 33
      views/anime/index.html.php
  4. 6 26
      views/search/anime.html.php
  5. 22 45
      views/search/index.html.php

+ 2 - 2
config/bootstrap/connections.php

@@ -43,7 +43,7 @@ use lithium\data\Connections;
 Connections::add('default', array(
  	'type' => 'database',
  	'adapter' => 'MySql',
- 	'host' => '127.0.0.1',
+ 	'host' => 'otaku.raylu.net',
  	'login' => 'otakuhub',
  	'password' => 'otakuhub',
  	'database' => 'otakuhub'
@@ -71,4 +71,4 @@ Connections::add('default', array(
 
 
 
-?>
+?>

+ 14 - 45
controllers/SearchController.php

@@ -1,57 +1,26 @@
-<?php 
-
-namespace app\controllers; 
+<?php
+namespace app\controllers;
 
 use app\models\Anime;
 use app\models\Manga;
 use app\models\Kdrama;
 
-
 class SearchController extends \lithium\action\Controller {
-	public $publicActions = array('index');
-
-	protected $_types = array('Anime' => 'app\models\Anime',
-								  'Manga' => 'app\models\Manga',
-								  'Kdrama' => 'app\models\Kdrama',
-
-								  'anime' => 'app\models\Anime',
-								  'manga' => 'app\models\Manga',
-								  'kdrama' => 'app\models\Kdrama');
-
-
-	public function index($type, $by = 'title')
-	{
-		//Regex-ize the search param 
-		$searchParam = (isset($this->request->query['search'])) ?
-		'/' . $this->request->query['search'] . '/i' : "";
-	    
-
-		
-		//Get the page number 		
-		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
+	public $publicActions = array('index', 'anime');
 
-		$headers = array();
-		switch ($type)
+	public function index() {
+		if (isset($this->request->query['q']))
 		{
-			case 'Anime':
-			case 'anime': $headers = array('title' => 'Title',
-											 'episode_count' => 'Episodes',
-											 'view_type' => 'Type', 'mal_score' => 'MAL Score');
-
-			case 'Kdrama':
-			case 'Kdrama': $headers = array('title' => 'Title',
-											'episode_count' => 'Episodes');
-
+			$q = '/' . $this->request->query['q'] . '/i';
+			return Anime::search($q, $page, 'title');
 		}
+		return $this->render(array('template' => 'index'));
+	}
 
-		//If the type part of the URL is a valid type (as defined above),
-		if (isset($this->_types[$type]))
-		{
-			$model = $this->_types[$type];
-
-			//Forcing search to title for now, until the search frontend is done
-			$search = $model::search($searchParam, $page, 'title');
-			return array('content' => $search['content'], 'page' => $search['page'], 'headers' => $headers, 'total' => $search['total'], 'limit' => $search['limit']);
-		}
+	public function anime($by = 'title')
+	{
+		$q = isset($this->request->query['q']) ?  '/' . $this->request->query['q'] . '/i' : '';
+		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
+		return Anime::search($q, $page, 'title');
 	}
 }

+ 1 - 33
views/anime/index.html.php

@@ -6,36 +6,4 @@ $this->styles($this->html->style('pagination'));
 <h2 class="ribbon full">Anime</h2>
 <div class="triangle-ribbon"></div>
 
-<?= $this->Paginator->paginate(array('separator' => '')) ?>
-
-<table>
-<th>Title</th>
-<th>Date</th>
-<th>Type</th>
-<?php foreach ($content as $anime): ?>
-	<tr>
-		<td>
-			<a href="/anime/view/<?= $anime->special_id ?>"><?= $anime->title ?></a>
-			<?php if ($anime->foreign_titles || $anime->alternative_titles): ?>
-				<span class="alt_titles">
-				<?php if ($anime->foreign_titles): ?>
-					<?= $anime->foreign_titles[0] ?>
-				<?php endif ?>
-				<?php if ($anime->alternative_titles): ?>
-					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-					<?= $anime->alternative_titles[0] ?>
-				<?php endif ?>
-				</span>
-			<?php endif ?>
-		</td>
-		<td>
-			<?= $anime->aired ?>
-		</td>
-		<td>
-			<?= $anime->view_type ?>
-		</td>
-	</tr>
-<?php endforeach ?>
-</table>
-
-<?= $this->Paginator->paginate(array('separator' => '')) ?>
+<?= $this->_render('element', 'animetable', compact('anime')) ?>

+ 6 - 26
views/search/anime.html.php

@@ -1,30 +1,10 @@
 <?php
+$this->styles($this->html->style('anime'));
 $this->styles($this->html->style('pagination'));
 ?>
 
-<div class="container_12">
-<div class="grid_4">
-<h2> Search options </h2>
-<hr />
-<?= $this->form->create(null, array('method' => 'get')); ?>
-	<?= $this->form->field('search', array('type' => 'textbox', 'class' => 'sidebar-search', 'style' => 'width:200px')); ?>
-	<?= $this->form->label('type', 'For:'); ?>
-	<?= $this->form->select('type', array('Anime'  => 'Anime',
-								  		  'Manga'  => 'Manga',
-								  		  'Kdrama' => 'Kdrama')); ?>
-	<?= $this->form->submit('Search', array('style' => 'width: 100px')); ?>
-<?= $this->form->end(); ?>
-</div>
-<div class="grid_8">
-<h2>Search Results</h2>
-<hr />
-	<table class="table">
-	<tr><th>img</th><th>Name</th><th>Episodes</th><th>Type</th><th>Score</th></tr>
-		<?php foreach($content as $item): ?>
-			<tr><td>"image"</td><td><a href="/anime/view/<?= $item->special_id ?>"><?= $item->title ?></a></td> <td><?= $item->episode_count ?></td><td><?= $item->view_type ?></td><td><?= $item->mal_score ?></td></tr>
-		<?php endforeach; ?>
-	</table>
-<?=$this->Paginator->paginate(array('separator' => '', 'action' => 'index/anime')); ?>
-</div>
-<br class="cl">
-</div>
+<?= $this->_render('element', 'search') ?>
+
+<h2>Anime Search Results</h2>
+(search instead for ...)
+<?= $this->_render('element', 'animetable', compact('anime')) ?>

+ 22 - 45
views/search/index.html.php

@@ -1,51 +1,28 @@
 <?php 
 $this->styles($this->html->style('pagination'));
+?>
 
-//table helper
-function table($data, array $headers = array(), array $options = array()) {
-	//Create the table 
-	echo '<tr>';
-	foreach ($headers as $k => $v) 
-	{
-		echo "<th>$v</th>";
-	}
-	echo "</tr>\n";
+<?= $this->_render('element', 'search', compact('anime')) ?>
 
+<?= $this->Paginator->paginate(array('separator' => '')) ?>
 
-	foreach ($data as $item)
-	{
-		echo '<tr>';
-		foreach($headers as $key => $value)
-		{
-			echo '<td>';
-			echo $item->$key;
-			echo '</td>';
-		}
-		echo "</tr>\n";
-	}
-}
-?>
+<table>
+<th>Title</th>
+<th>Date</th>
+<th>Type</th>
+<?php foreach ($content as $item): ?>
+	<tr>
+		<td>
+			<a href="/anime/view/<?= $item->special_id ?>"><?= $item->title ?></a>
+		</td>
+		<td>
+			<?= $item->aired ?>
+		</td>
+		<td>
+			<?= $item->view_type ?>
+		</td>
+	</tr>
+<?php endforeach ?>
+</table>
 
-<div class="container_12">
-<div class="grid_4">
-<h2> Search options </h2>
-<hr />
-<?= $this->form->create(null, array('method' => 'get')); ?>
-	<?= $this->form->field('search', array('type' => 'textbox', 'class' => 'sidebar-search', 'style' => 'width:200px')); ?>
-	<?= $this->form->label('type', 'For:'); ?>
-	<?= $this->form->select('type', array('Anime'  => 'Anime',
-								  		  'Manga'  => 'Manga',
-								  		  'Kdrama' => 'Kdrama')); ?>
-	<?= $this->form->submit('Search', array('style' => 'width: 100px')); ?>
-<?= $this->form->end(); ?>
-</div>
-<div class="grid_8">
-<h2>Search Results</h2>
-<hr />
-	<table class="table">
-		<?php table($content, $headers); ?>
-	</table>
-<?=$this->Paginator->paginate(array('separator' => '', 'action' => 'index/anime')); ?>
-</div>
-<br class="cl">
-</div>
+<?= $this->Paginator->paginate(array('separator' => '')) ?>