HummingBirdAnimeClient/src/AnimeClient/Controller/History.php

107 lines
2.3 KiB
PHP
Raw Normal View History

2020-04-21 19:22:56 -04:00
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu to manage anime and manga watch lists
*
2021-02-04 11:57:01 -05:00
* PHP version 8
2020-04-21 19:22:56 -04:00
*
2022-03-04 15:50:35 -05:00
* @copyright 2015 - 2022 Timothy J. Warren <tim@timshome.page>
2020-04-21 19:22:56 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2022-03-04 15:50:35 -05:00
* @link https://git.timshome.page/timw4mail/HummingBirdAnimeClient
2020-04-21 19:22:56 -04:00
*/
namespace Aviat\AnimeClient\Controller;
use Aviat\Ion\Attribute\Controller;
use Aviat\Ion\Attribute\Route;
use Aviat\AnimeClient\{Controller as BaseController, Model};
2020-04-21 19:22:56 -04:00
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
2020-04-21 19:22:56 -04:00
/**
* Controller for Anime-related pages
*/
#[Controller]
final class History extends BaseController
{
2020-04-21 19:22:56 -04:00
/**
* The anime list model
*/
protected Model\Anime $animeModel;
2020-04-21 19:22:56 -04:00
/**
* The manga list model
*/
protected Model\Manga $mangaModel;
2020-04-21 19:22:56 -04:00
/**
* Constructor
*
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->animeModel = $container->get('anime-model');
$this->mangaModel = $container->get('manga-model');
}
#[Route('history', '/history/{type}')]
public function index(string $type = 'anime'): void
2020-04-21 19:22:56 -04:00
{
if (method_exists($this, $type))
{
$this->{$type}();
return;
}
$this->notFound(
$this->config->get('whose_list') .
"'s List &middot; History &middot; " .
'History Not Found',
'History Not Found'
);
}
private function anime(): void
{
$this->baseData = array_merge($this->baseData, [
'menu_name' => 'anime_list',
'other_type' => 'manga',
'url_type' => 'anime',
]);
$this->outputHTML('history', [
2020-04-21 19:22:56 -04:00
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Anime',
'Watching History'
),
'items' => $this->animeModel->getHistory(),
]);
}
private function manga(): void
2020-04-21 19:22:56 -04:00
{
$this->baseData = array_merge($this->baseData, [
'menu_name' => 'manga_list',
'other_type' => 'anime',
'url_type' => 'manga',
]);
$this->outputHTML('history', [
2020-04-21 19:22:56 -04:00
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List",
'Manga',
'Reading History'
),
'items' => $this->mangaModel->getHistory(),
]);
}
}