summaryrefslogtreecommitdiffstats
path: root/models/Manga.php
blob: 5f79befaadbc79fc17ead56ed459cabeb5beb179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

namespace app\models;

class Manga extends \lithium\data\Model {
	protected $_meta = array('key' => '_id', 'source' => 'manga', 'connection' => 'mongo');

	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');
	}
}