diff options
author | Michael Francis <edude03@gmail.com> | 2011-06-20 19:01:25 -0400 |
---|---|---|
committer | Michael Francis <edude03@gmail.com> | 2011-06-20 19:01:25 -0400 |
commit | 4dd797ca029ca5d0486c24395c2bf6133f5f3d39 (patch) | |
tree | a389942da6e4a9e1bf2b473e80e03b55b80abe8d | |
parent | 01cb2f0517070dd867cd9ea23812965a8a621499 (diff) | |
download | otakuhub-4dd797ca029ca5d0486c24395c2bf6133f5f3d39.tar.xz |
Fixed issue with special_id, since special_id isn't a regex, we drop 'like' from the search params
-rw-r--r-- | models/Anime.php | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/models/Anime.php b/models/Anime.php index 5a2cf00..34b999e 100644 --- a/models/Anime.php +++ b/models/Anime.php @@ -7,21 +7,35 @@ class Anime extends \lithium\data\Model { public static function search($query, $page = 1, $by = 'title') { - $defaults = array( - 'limit' => 20 - ); + $defaults = array('limit' => 20); $limit = 20; - $content = self::find('all', - array( - 'conditions' => array( - $by => array('like' => $query) - ), - 'limit' => $limit, - 'page' => $page - )); - - $total = Anime::count(array('title' => array('like' => $query))); - return compact('content', 'by', 'limit', 'total', 'page'); + switch($by) { + case 'special_id': + + $content = self::find('first', + array('conditions' => array( + $by => $query + ), + 'limit' => $limit, + 'page' => $page + )); + + + + $total = Anime::count(array($by => $query)); + break; + + default: + $content = self::find('all', + array('conditions' => array( + $by => array('like' => $query) + ), + 'limit' => $limit, + 'page' => $page + )); + $total = Anime::count(array($by => array('like' => $query))); + } + return compact('content', 'by', 'limit', 'total', 'page'); } }
\ No newline at end of file |