diff options
author | Michael Francis <edude03@gmail.com> | 2011-05-29 16:36:11 -0400 |
---|---|---|
committer | Michael Francis <edude03@gmail.com> | 2011-05-29 16:36:11 -0400 |
commit | b1629b5d2fbe13717fcf32fc83f40ea2e85f572f (patch) | |
tree | 459737f27e8afcc25d89422d19a80c77e2b88023 /controllers/SearchController.php | |
parent | 3f7353eb51c90ce94081197f879637cb21da758a (diff) | |
download | otakuhub-b1629b5d2fbe13717fcf32fc83f40ea2e85f572f.tar.xz |
Moved search into the model
Diffstat (limited to 'controllers/SearchController.php')
-rw-r--r-- | controllers/SearchController.php | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/controllers/SearchController.php b/controllers/SearchController.php index b6a95e6..496dec5 100644 --- a/controllers/SearchController.php +++ b/controllers/SearchController.php @@ -2,38 +2,35 @@ namespace app\controllers; -use app\models\anime; -use \MongoRegex; +use app\models\Anime; +use app\models\Manga; +use app\models\Kdrama; + class SearchController extends \lithium\action\Controller { public $publicActions = array('index'); - public function index($type, $by = "series_title") - { + protected $_types = array('Anime' => 'app\models\Anime', + 'Manga' => 'app\models\Manga', + 'Kdrama' => 'app\models\Kdrama', - if (empty($this->request->query['search'])) { - //Redirect them or something - } + 'anime' => 'app\models\Anime', + 'manga' => 'app\models\Manga', + 'kdrama' => 'app\models\Kdrama'); - - $searchParam = '/' . $this->request->query['search'] . '/i'; + public function index($type, $by = 'title') + { - $content; - $limit = 20; - $page = $this->request->page ?: 1; - $total; //<-- number of search results + $searchParam = '/' . $this->request->query['search'] . '/i'; + $page = $this->request->query['page'] ?: 1; - - switch($type) + //If the type part of the URL is a valid type (as defined above), + if (isset($this->_types[$type])) { - case "anime": $content = Anime::find('all', array('conditions' => array('title' => array('like' => $searchParam)), $limit, $page)); - $total = Anime::count(array('title' => array('like' => $searchParam))); - break; - case "kdrama": break; - case "manga": break; + $model = $this->_types[$type]; + + //Forcing search to title for now, until the search frontend is done + return $model::search($searchParam, $page, 'title'); } - return compact('content', 'type', 'by', 'limit', 'total', 'page'); } - - }
\ No newline at end of file |