summaryrefslogtreecommitdiffstats
path: root/controllers/AnimeController.php
blob: 3a40ceea24255ea258f315b75f424a52e5680f59 (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;

class AnimeController extends \lithium\action\Controller {
	public $publicActions = array('index', 'view', 'cast');

	public function index()
	{
		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
		$anime = Anime::find('all', array('limit' => '10'), compact('page'));
		return compact('page', 'anime');
	}

	public function view($id = null)
	{
		if (is_numeric($id))
		{
			$data = Anime::search($id, null, 'special_id');
			$related = $data['anime']->related;
			$str = '';
			for ($i = 0; $i < count($related); $i++)
			{
				if ($i > 0) $str .= ', ';
				$ra = Anime::search($related[$i], null, 'special_id');
				$str .= '<a href="' . $related[$i] . '">' . $ra['anime']->title .  '</a>';
			}
			$data['related'] = $str;
			return $data;
		}
		else
		{
			return $this->redirect(array('controller' => 'search','q' => array('search' => $id)));
		}
	}

	public function cast($id = null)
	{
		if (is_numeric($id))
		{
			return Anime::search($id, null, 'special_id');
		}
	}
}