HummingBirdAnimeClient/src/AnimeClient/Controller/History.php

105 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
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
2021-01-13 01:52:03 -05:00
* @copyright 2015 - 2021 Timothy J. Warren
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
2020-04-21 19:22:56 -04:00
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
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
*/
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');
}
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(),
]);
}
}