summaryrefslogtreecommitdiffstats
path: root/models/Anime.php
blob: 8281ea758c8eb295d1fd974f6c2872872eb70180 (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
42
43
44
45
46
47
48
49
<?php

namespace app\models;

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

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

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


			$total = self::count(array($by => $query)); 
			break;
			
		default:
			if ($query)
			{
				$conditions = null; // TODO
				$content = self::find('all', array(
					'conditions' => array($by => array('like' => $query)),
					'limit' => $limit,
					'page' => $page
				));
				$total = Anime::count(array($by => array('like' => $query)));
			}
			else
			{
				$content = self::find('all', array(
					'limit' => $limit,
					'page' => $page
				));
				$total = Anime::count();
			}
		}
		return compact('content', 'by', 'limit', 'total', 'page');
	}
}