Browse Source

manga/kdrama individual search pages

raylu 14 years ago
parent
commit
dcc965ab29
5 changed files with 84 additions and 10 deletions
  1. 16 2
      controllers/SearchController.php
  2. 4 6
      models/Kdrama.php
  3. 32 2
      models/Manga.php
  4. 16 0
      views/search/kdrama.html.php
  5. 16 0
      views/search/manga.html.php

+ 16 - 2
controllers/SearchController.php

@@ -25,8 +25,22 @@ class SearchController extends \lithium\action\Controller {
 
 	public function anime($by = 'title')
 	{
-		$q = isset($this->request->query['q']) ?  '/' . $this->request->query['q'] . '/i' : '';
+		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
 		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
-		return Anime::search($q, $page, 'title');
+		return Anime::search("/$q/i", $page, 'title');
+	}
+
+	public function manga($by = 'title')
+	{
+		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
+		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
+		return Manga::search("/$q/i", $page, 'title');
+	}
+
+	public function kdrama($by = 'title')
+	{
+		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
+		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
+		return Kdrama::search("/$q/i", $page, 'title');
 	}
 }

+ 4 - 6
models/Kdrama.php

@@ -13,7 +13,7 @@ class Kdrama extends \lithium\data\Model {
 		switch($by) {
 			case 'special_id':
 			
-			$content = parent::find('first',
+			$kdrama = parent::find('first',
 				array('conditions' => array(
 						$by => $query
 					),
@@ -21,13 +21,11 @@ class Kdrama extends \lithium\data\Model {
 					'page' => $page
 				));
 
-
-		
 			$total = parent::count(array($by => $query)); 
 			break;
 			
 			default:
-			$content = parent::find('all',
+			$kdrama = parent::find('all',
 				array('conditions' => array(
 						$by => array('like' => $query)
 					),
@@ -36,6 +34,6 @@ class Kdrama extends \lithium\data\Model {
 				));
 				$total = parent::count(array($by => array('like' => $query)));
 	}
-	return compact('content', 'by', 'limit', 'total', 'page');
+	return compact('kdrama', 'by', 'limit', 'total', 'page');
 	}
-}
+}

+ 32 - 2
models/Manga.php

@@ -5,5 +5,35 @@ namespace app\models;
 class Manga extends \lithium\data\Model {
 	protected $_meta = array('key' => '_id', 'source' => 'manga', 'connection' => 'mongo');
 
-	
-}
+	public static function search($query, $page = 1, $by = 'title') 
+	{
+		$defaults = array('limit' => 20);
+		$limit = 20;
+
+		switch($by) {
+			case 'special_id':
+			
+			$manga = parent::find('first',
+				array('conditions' => array(
+						$by => $query
+					),
+					'limit' => $limit,
+					'page' => $page
+				));
+
+			$total = parent::count(array($by => $query)); 
+			break;
+			
+			default:
+			$manga = parent::find('all',
+				array('conditions' => array(
+						$by => array('like' => $query)
+					),
+					'limit' => $limit,
+					'page' => $page
+				));
+				$total = parent::count(array($by => array('like' => $query)));
+	}
+	return compact('manga', 'by', 'limit', 'total', 'page');
+	}
+}

+ 16 - 0
views/search/kdrama.html.php

@@ -0,0 +1,16 @@
+<?php
+$this->styles($this->html->style('pagination'));
+$this->styles($this->html->style('table'));
+$this->styles($this->html->style('search'));
+?>
+
+<?= $this->_render('element', 'search') ?>
+
+<h2>K-Drama Search Results</h2>
+(search instead for ...)
+
+<?= $this->Paginator->paginate(array('separator' => '')) ?>
+
+<?= $this->_render('element', 'kdramatable') ?>
+
+<?= $this->Paginator->paginate(array('separator' => '')) ?>

+ 16 - 0
views/search/manga.html.php

@@ -0,0 +1,16 @@
+<?php
+$this->styles($this->html->style('pagination'));
+$this->styles($this->html->style('table'));
+$this->styles($this->html->style('search'));
+?>
+
+<?= $this->_render('element', 'search') ?>
+
+<h2>Manga Search Results</h2>
+(search instead for ...)
+
+<?= $this->Paginator->paginate(array('separator' => '')) ?>
+
+<?= $this->_render('element', 'mangatable') ?>
+
+<?= $this->Paginator->paginate(array('separator' => '')) ?>