diff options
-rw-r--r-- | controllers/SearchController.php | 18 | ||||
-rw-r--r-- | models/Kdrama.php | 10 | ||||
-rw-r--r-- | models/Manga.php | 34 | ||||
-rw-r--r-- | views/search/kdrama.html.php | 16 | ||||
-rw-r--r-- | views/search/manga.html.php | 16 |
5 files changed, 84 insertions, 10 deletions
diff --git a/controllers/SearchController.php b/controllers/SearchController.php index abcaabd..efd25f3 100644 --- a/controllers/SearchController.php +++ b/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'); } } diff --git a/models/Kdrama.php b/models/Kdrama.php index f1eee22..12c136d 100644 --- a/models/Kdrama.php +++ b/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'); } -}
\ No newline at end of file +} diff --git a/models/Manga.php b/models/Manga.php index 03c2d29..5f79bef 100644 --- a/models/Manga.php +++ b/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'); - -}
\ No newline at end of file + 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'); + } +} diff --git a/views/search/kdrama.html.php b/views/search/kdrama.html.php new file mode 100644 index 0000000..8736902 --- /dev/null +++ b/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' => '')) ?> diff --git a/views/search/manga.html.php b/views/search/manga.html.php new file mode 100644 index 0000000..181994b --- /dev/null +++ b/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' => '')) ?> |