diff options
author | raylu <raylu@mixpanel.com> | 2011-07-12 00:50:00 -0700 |
---|---|---|
committer | raylu <raylu@mixpanel.com> | 2011-07-12 00:50:00 -0700 |
commit | 657d270864c6f8f77d083fe4aa6ba636ecbbd372 (patch) | |
tree | 1dc4ecd23df4486f6ea637c608513dc87c1e1b50 /controllers/SearchController.php | |
parent | fa1c7d7646da4552dd5894f7c8440f89d1c10c53 (diff) | |
download | otakuhub-657d270864c6f8f77d083fe4aa6ba636ecbbd372.tar.xz |
rework a lot of search
/search will eventually search all
/search/anime searches only anime
Diffstat (limited to 'controllers/SearchController.php')
-rw-r--r-- | controllers/SearchController.php | 59 |
1 files changed, 14 insertions, 45 deletions
diff --git a/controllers/SearchController.php b/controllers/SearchController.php index 8deaf07..421efb6 100644 --- a/controllers/SearchController.php +++ b/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'); } } |