1 | <?php |
||
25 | class Anime extends BaseController { |
||
26 | |||
27 | use \Aviat\Ion\StringWrapper; |
||
28 | |||
29 | /** |
||
30 | * The anime list model |
||
31 | * @var object $model |
||
32 | */ |
||
33 | protected $model; |
||
34 | |||
35 | /** |
||
36 | * Data to ve sent to all routes in this controller |
||
37 | * @var array $base_data |
||
38 | */ |
||
39 | protected $base_data; |
||
40 | |||
41 | /** |
||
42 | * Constructor |
||
43 | * |
||
44 | * @param ContainerInterface $container |
||
45 | */ |
||
46 | public function __construct(ContainerInterface $container) |
||
47 | { |
||
48 | parent::__construct($container); |
||
49 | |||
50 | $this->model = $container->get('anime-model'); |
||
51 | |||
52 | $this->base_data = array_merge($this->base_data, [ |
||
53 | 'menu_name' => 'anime_list', |
||
54 | 'url_type' => 'anime', |
||
55 | 'other_type' => 'manga', |
||
56 | 'config' => $this->config, |
||
57 | ]); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Show a portion, or all of the anime list |
||
62 | * |
||
63 | * @param string $type - The section of the list |
||
64 | * @param string $view - List or cover view |
||
65 | * @return void |
||
66 | */ |
||
67 | public function index($type = "watching", $view = '') |
||
68 | { |
||
69 | $type_title_map = [ |
||
70 | 'all' => 'All', |
||
71 | 'watching' => 'Currently Watching', |
||
72 | 'plan_to_watch' => 'Plan to Watch', |
||
73 | 'on_hold' => 'On Hold', |
||
74 | 'dropped' => 'Dropped', |
||
75 | 'completed' => 'Completed' |
||
76 | ]; |
||
77 | |||
78 | $model_map = [ |
||
79 | 'watching' => AnimeWatchingStatus::WATCHING, |
||
80 | 'plan_to_watch' => AnimeWatchingStatus::PLAN_TO_WATCH, |
||
81 | 'on_hold' => AnimeWatchingStatus::ON_HOLD, |
||
82 | 'all' => 'all', |
||
83 | 'dropped' => AnimeWatchingStatus::DROPPED, |
||
84 | 'completed' => AnimeWatchingStatus::COMPLETED |
||
85 | ]; |
||
86 | |||
87 | if (array_key_exists($type, $type_title_map)) |
||
88 | { |
||
89 | $title = $this->config->get('whose_list') . |
||
90 | "'s Anime List · {$type_title_map[$type]}"; |
||
91 | } |
||
92 | else |
||
93 | { |
||
94 | $title = ''; |
||
95 | } |
||
96 | |||
97 | $view_map = [ |
||
98 | '' => 'cover', |
||
99 | 'list' => 'list' |
||
100 | ]; |
||
101 | |||
102 | $data = ($type != 'all') |
||
103 | ? $this->model->get_list($model_map[$type]) |
||
104 | : $this->model->get_all_lists(); |
||
105 | |||
106 | $this->outputHTML('anime/' . $view_map[$view], [ |
||
107 | 'title' => $title, |
||
108 | 'sections' => $data |
||
109 | ]); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Form to add an anime |
||
114 | * |
||
115 | * @return void |
||
116 | */ |
||
117 | public function add_form() |
||
139 | |||
140 | /** |
||
141 | * Add an anime to the list |
||
142 | * |
||
143 | * @return void |
||
144 | */ |
||
145 | public function add() |
||
166 | |||
167 | /** |
||
168 | * Form to edit details about a series |
||
169 | * |
||
170 | * @param int $id |
||
171 | * @param string $status |
||
172 | * @return void |
||
173 | */ |
||
174 | public function edit($id, $status = "all") |
||
200 | |||
201 | /** |
||
202 | * Search for anime |
||
203 | * |
||
204 | * @return void |
||
205 | */ |
||
206 | public function search() |
||
211 | |||
212 | /** |
||
213 | * Update an anime item via a form submission |
||
214 | * |
||
215 | * @return void |
||
216 | */ |
||
217 | public function form_update() |
||
244 | |||
245 | /** |
||
246 | * Update an anime item |
||
247 | * |
||
248 | * @return boolean|null |
||
249 | */ |
||
250 | public function update() |
||
258 | |||
259 | /** |
||
260 | * View details of an anime |
||
261 | * |
||
262 | * @param string anime_id |
||
263 | * @return void |
||
264 | */ |
||
265 | public function details($anime_id) |
||
274 | } |
||
275 | // End of AnimeController.php |