summaryrefslogtreecommitdiffstats
path: root/models/Kdrama.php
blob: 9d3ddf76a24a4eff4527e6c32790cd04ba32ddc8 (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
40
41
<?php 

namespace app\models;

class Kdrama extends \lithium\data\Model {
	protected $_meta = array('key' => '_id', 'source' => 'kdrama');

	public static function search($query, $page = 1, $by = 'title') 
	{
		$defaults = array('limit' => 20);
		$limit = 20;

		switch($by) {
			case 'special_id':
			
			$content = parent::find('first',
				array('conditions' => array(
						$by => $query
					),
					'limit' => $limit,
					'page' => $page
				));


		
			$total = parent::count(array($by => $query)); 
			break;
			
			default:
			$content = parent::find('all',
				array('conditions' => array(
						$by => array('like' => $query)
					),
					'limit' => $limit,
					'page' => $page
				));
				$total = parent::count(array($by => array('like' => $query)));
	}
	return compact('content', 'by', 'limit', 'total', 'page');
	}
}