summaryrefslogtreecommitdiffstats
path: root/controllers/SearchController.php
blob: b6a95e65f8845c14e171fff9ccc2097af205eed2 (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\controllers; 

use app\models\anime;
use \MongoRegex;

class SearchController extends \lithium\action\Controller {
	public $publicActions = array('index');

	public function index($type, $by = "series_title")
	{

		if (empty($this->request->query['search'])) {
			//Redirect them or something 
		}


		$searchParam = '/' . $this->request->query['search'] . '/i';
		
		$content;
		$limit = 20; 
		$page = $this->request->page ?: 1;
		$total; //<-- number of search results


		switch($type)
		{
			case "anime": $content = Anime::find('all', array('conditions' => array('title' => array('like' => $searchParam)), $limit, $page)); 
			$total = Anime::count(array('title' => array('like' => $searchParam)));
			break;
			case "kdrama": break;
			case "manga": break; 
		}
		return compact('content', 'type', 'by', 'limit', 'total', 'page');
	}


}