summaryrefslogtreecommitdiffstats
path: root/controllers/SearchController.php
blob: f09f446d47c88bcdc8401f02e6be0e2262836a98 (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
50
51
52
53
54
55
56
57
<?php 

namespace app\controllers; 

use app\models\Anime;
use app\models\Manga;
use app\models\Kdrama;


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

	protected $_types = array('Anime' => 'app\models\Anime',
								  'Manga' => 'app\models\Manga',
								  'Kdrama' => 'app\models\Kdrama',

								  'anime' => 'app\models\Anime',
								  'manga' => 'app\models\Manga',
								  'kdrama' => 'app\models\Kdrama');


	public function index($type, $by = 'title')
	{
		//Regex-ize the search param 
		$searchParam = (isset($this->request->query['search'])) ?
		'/' . $this->request->query['search'] . '/i' : "";
	    

		
		//Get the page number 		
		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;

		$headers = array();
		switch ($type)
		{
			case 'Anime':
			case 'anime': $headers = array('title' => 'Title',
											 'episode_count' => 'Episodes',
											 'view_type' => 'Type', 'mal_score' => 'MAL Score');

			case 'kdrama':
			case 'Kdrama': $headers = array('title' => 'Title',
											'episode_count' => 'Episodes');

		}

		//If the type part of the URL is a valid type (as defined above),
		if (isset($this->_types[$type]))
		{
			$model = $this->_types[$type];

			//Forcing search to title for now, until the search frontend is done
			$search = $model::search($searchParam, $page, 'title');
			return array('content' => $search['content'], 'page' => $search['page'], 'headers' => $headers, 'total' => $search['total'], 'limit' => $search['limit']);
		}
	}
}