From dcc965ab293655136c251afe4fb6f4f41ac5cb75 Mon Sep 17 00:00:00 2001 From: raylu Date: Sat, 16 Jul 2011 23:08:10 -0700 Subject: manga/kdrama individual search pages --- models/Kdrama.php | 10 ++++------ models/Manga.php | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 8 deletions(-) (limited to 'models') 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'); + } +} -- cgit v1.2.3