summaryrefslogtreecommitdiffstats
path: root/controllers/SearchController.php
blob: efd25f31e247edfe6afd67184490b8db61d7db16 (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
<?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', 'anime', 'manga', 'kdrama');

	public function index() {
		if (isset($this->request->query['q']))
		{
			$q = $this->request->query['q'];
			$conditions = array('title' => array('like' => "/$q/i"));
			$limit = 7;

			$anime = Anime::find('all', compact('conditions', 'limit'));
			$manga = Manga::find('all', compact('conditions', 'limit'));
			$kdrama = Kdrama::find('all', compact('conditions', 'limit'));

			return compact('q', 'anime', 'manga', 'kdrama');
		}
	}

	public function anime($by = 'title')
	{
		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
		return Anime::search("/$q/i", $page, 'title');
	}

	public function manga($by = 'title')
	{
		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
		return Manga::search("/$q/i", $page, 'title');
	}

	public function kdrama($by = 'title')
	{
		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
		return Kdrama::search("/$q/i", $page, 'title');
	}
}