diff options
Diffstat (limited to 'models/Manga.php')
-rw-r--r-- | models/Manga.php | 34 |
1 files changed, 32 insertions, 2 deletions
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'); + } +} |