Version 5.1 - All the GraphQL #32
@ -105,7 +105,7 @@ class RoboFile extends Tasks {
|
|||||||
*/
|
*/
|
||||||
public function coverage()
|
public function coverage()
|
||||||
{
|
{
|
||||||
$this->_run(['vendor/bin/phpunit -c build']);
|
$this->_run(['phpdbg -qrr -- vendor/bin/phpunit -c build']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,7 +114,7 @@ class RoboFile extends Tasks {
|
|||||||
public function docs()
|
public function docs()
|
||||||
{
|
{
|
||||||
$cmd_parts = [
|
$cmd_parts = [
|
||||||
'phpdox',
|
'vendor/bin/phpdox',
|
||||||
];
|
];
|
||||||
$this->_run($cmd_parts, ' && ');
|
$this->_run($cmd_parts, ' && ');
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<main>
|
<main>
|
||||||
<h1>404</h1>
|
<h1>404</h1>
|
||||||
<h2>Page Not Found</h2>
|
<h2><?= $message ?></h2>
|
||||||
</main>
|
</main>
|
||||||
|
@ -35,4 +35,26 @@
|
|||||||
<p><?= nl2br($data['synopsis']) ?></p>
|
<p><?= nl2br($data['synopsis']) ?></p>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<section>
|
||||||
|
<?php if (count($characters) > 0): ?>
|
||||||
|
<h2>Characters</h2>
|
||||||
|
<div class="flex flex-wrap">
|
||||||
|
<?php foreach($characters as $char): ?>
|
||||||
|
<?php if ( ! empty($char['image']['original'])): ?>
|
||||||
|
<div class="character">
|
||||||
|
<?php $link = $url->generate('character', ['slug' => $char['slug']]) ?>
|
||||||
|
<?= $helper->a($link, $char['name']); ?>
|
||||||
|
<br />
|
||||||
|
<a href="<?= $link ?>">
|
||||||
|
<?= $helper->img($char['image']['original'], [
|
||||||
|
'width' => '225'
|
||||||
|
]) ?>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
|
</section>
|
||||||
|
|
||||||
</main>
|
</main>
|
@ -22,7 +22,6 @@
|
|||||||
"aura/session": "^2.0",
|
"aura/session": "^2.0",
|
||||||
"aviat/banker": "^1.0.0",
|
"aviat/banker": "^1.0.0",
|
||||||
"aviat/ion": "dev-master",
|
"aviat/ion": "dev-master",
|
||||||
"filp/whoops": "^2.1.5",
|
|
||||||
"monolog/monolog": "^1.0",
|
"monolog/monolog": "^1.0",
|
||||||
"psr/http-message": "~1.0",
|
"psr/http-message": "~1.0",
|
||||||
"psr/log": "~1.0",
|
"psr/log": "~1.0",
|
||||||
@ -34,19 +33,21 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"pdepend/pdepend": "^2.2",
|
"pdepend/pdepend": "^2.2",
|
||||||
"sebastian/phpcpd": "^3.0",
|
"sebastian/phpcpd": "^3.0",
|
||||||
"theseer/phpdox": "0.9.0",
|
"theseer/phpdox": "dev-master",
|
||||||
"phploc/phploc": "^3.0",
|
"phploc/phploc": "^3.0",
|
||||||
"phpmd/phpmd": "^2.4",
|
"phpmd/phpmd": "^2.4",
|
||||||
"phpunit/phpunit": "^6.0",
|
"phpunit/phpunit": "^6.0",
|
||||||
"robmorgan/phinx": "~0.6.4",
|
"robmorgan/phinx": "~0.6.4",
|
||||||
"consolidation/robo": "~1.0",
|
"consolidation/robo": "~1.0",
|
||||||
"henrikbjorn/lurker": "^1.1.0",
|
"henrikbjorn/lurker": "^1.1.0",
|
||||||
"symfony/var-dumper": "^3.1",
|
"symfony/var-dumper": "^3.2",
|
||||||
"squizlabs/php_codesniffer": "^3.0.0@beta",
|
"squizlabs/php_codesniffer": "^3.0.0@beta",
|
||||||
"phpstan/phpstan": "^0.6.4"
|
"phpstan/phpstan": "^0.6.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "vendor/bin/robo build",
|
||||||
"build:css": "cd public && npm run build && cd ..",
|
"build:css": "cd public && npm run build && cd ..",
|
||||||
|
"clean": "vendor/bin/robo clean",
|
||||||
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
|
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
|
||||||
"docs": "vendor/bin/phpdox",
|
"docs": "vendor/bin/phpdox",
|
||||||
"phpstan": "phpstan analyse src tests",
|
"phpstan": "phpstan analyse src tests",
|
||||||
|
28
console
28
console
@ -1,19 +1,10 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
if ( ! function_exists('_dir'))
|
// Set up autoloader for third-party dependencies
|
||||||
{
|
require_once realpath(__DIR__ . '/vendor/autoload.php');
|
||||||
/**
|
|
||||||
* Joins paths together. Variadic to take an
|
use Aviat\AnimeClient\Command;
|
||||||
* arbitrary number of arguments
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function _dir()
|
|
||||||
{
|
|
||||||
return implode(DIRECTORY_SEPARATOR, func_get_args());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||||
|
|
||||||
@ -22,9 +13,6 @@ $APP_DIR = __DIR__ . '/app/';
|
|||||||
$SRC_DIR = __DIR__ . '/src/';
|
$SRC_DIR = __DIR__ . '/src/';
|
||||||
$CONF_DIR = realpath("${APP_DIR}/config/");
|
$CONF_DIR = realpath("${APP_DIR}/config/");
|
||||||
|
|
||||||
// Set up autoloader for third-party dependencies
|
|
||||||
require_once realpath(__DIR__ . '/vendor/autoload.php');
|
|
||||||
|
|
||||||
// Unset 'constants'
|
// Unset 'constants'
|
||||||
unset($APP_DIR);
|
unset($APP_DIR);
|
||||||
unset($SRC_DIR);
|
unset($SRC_DIR);
|
||||||
@ -34,10 +22,10 @@ unset($CONF_DIR);
|
|||||||
// Start console script
|
// Start console script
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
$console = new \ConsoleKit\Console([
|
$console = new \ConsoleKit\Console([
|
||||||
'cache-prime' => '\Aviat\AnimeClient\Command\CachePrime',
|
'cache-prime' => Command\CachePrime::class,
|
||||||
'cache-clear' => '\Aviat\AnimeClient\Command\CacheClear',
|
'cache-clear' => Command\CacheClear::class,
|
||||||
'clear-cache' => '\Aviat\AnimeClient\Command\CacheClear',
|
'clear-cache' => Command\CacheClear::class,
|
||||||
'sync-lists' => '\Aviat\AnimeClient\Command\SyncKitsuWithMal',
|
'sync-lists' => Command\SyncKitsuWithMal::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$console->run();
|
$console->run();
|
14
index.php
14
index.php
@ -18,8 +18,6 @@ namespace Aviat\AnimeClient;
|
|||||||
use function Aviat\AnimeClient\loadToml;
|
use function Aviat\AnimeClient\loadToml;
|
||||||
|
|
||||||
use Aviat\AnimeClient\AnimeClient;
|
use Aviat\AnimeClient\AnimeClient;
|
||||||
use Whoops\Handler\PrettyPageHandler;
|
|
||||||
use Whoops\Run;
|
|
||||||
|
|
||||||
// Work around the silly timezone error
|
// Work around the silly timezone error
|
||||||
$timezone = ini_get('date.timezone');
|
$timezone = ini_get('date.timezone');
|
||||||
@ -36,18 +34,6 @@ $APP_DIR = _dir(__DIR__, 'app');
|
|||||||
$APPCONF_DIR = _dir($APP_DIR, 'appConf');
|
$APPCONF_DIR = _dir($APP_DIR, 'appConf');
|
||||||
$CONF_DIR = _dir($APP_DIR, 'config');
|
$CONF_DIR = _dir($APP_DIR, 'config');
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
// Setup error handling
|
|
||||||
// -------------------------------------------------------------------------
|
|
||||||
$whoops = new Run();
|
|
||||||
|
|
||||||
// Set up default handler for general errors
|
|
||||||
$defaultHandler = new PrettyPageHandler();
|
|
||||||
$whoops->pushHandler($defaultHandler);
|
|
||||||
|
|
||||||
// Register as the error handler
|
|
||||||
$whoops->register();
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Dependency Injection setup
|
// Dependency Injection setup
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -24,7 +24,7 @@ use Aviat\Ion\Enum;
|
|||||||
class Kitsu extends Enum {
|
class Kitsu extends Enum {
|
||||||
const WATCHING = 'current';
|
const WATCHING = 'current';
|
||||||
const PLAN_TO_WATCH = 'planned';
|
const PLAN_TO_WATCH = 'planned';
|
||||||
const COMPLETED = 'completed';
|
|
||||||
const ON_HOLD = 'on_hold';
|
const ON_HOLD = 'on_hold';
|
||||||
const DROPPED = 'dropped';
|
const DROPPED = 'dropped';
|
||||||
|
const COMPLETED = 'completed';
|
||||||
}
|
}
|
@ -196,8 +196,13 @@ class Model {
|
|||||||
*/
|
*/
|
||||||
public function getAnime(string $slug): array
|
public function getAnime(string $slug): array
|
||||||
{
|
{
|
||||||
// @TODO catch non-existent anime
|
|
||||||
$baseData = $this->getRawMediaData('anime', $slug);
|
$baseData = $this->getRawMediaData('anime', $slug);
|
||||||
|
|
||||||
|
if (empty($baseData))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$transformed = $this->animeTransformer->transform($baseData);
|
$transformed = $this->animeTransformer->transform($baseData);
|
||||||
$transformed['included'] = $baseData['included'];
|
$transformed['included'] = $baseData['included'];
|
||||||
return $transformed;
|
return $transformed;
|
||||||
@ -252,7 +257,15 @@ class Model {
|
|||||||
public function getManga(string $mangaId): array
|
public function getManga(string $mangaId): array
|
||||||
{
|
{
|
||||||
$baseData = $this->getRawMediaData('manga', $mangaId);
|
$baseData = $this->getRawMediaData('manga', $mangaId);
|
||||||
return $this->mangaTransformer->transform($baseData);
|
|
||||||
|
if (empty($baseData))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$transformed = $this->mangaTransformer->transform($baseData);
|
||||||
|
$transformed['included'] = $baseData['included'];
|
||||||
|
return $transformed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -386,13 +399,15 @@ class Model {
|
|||||||
|
|
||||||
if ( ! $cacheItem->isHit())
|
if ( ! $cacheItem->isHit())
|
||||||
{
|
{
|
||||||
$output = [
|
$output = [];
|
||||||
Title::WATCHING => $this->getAnimeList(KitsuWatchingStatus::WATCHING),
|
|
||||||
Title::PLAN_TO_WATCH => $this->getAnimeList(KitsuWatchingStatus::PLAN_TO_WATCH),
|
$statuses = KitsuWatchingStatus::getConstList();
|
||||||
Title::ON_HOLD => $this->getAnimeList(KitsuWatchingStatus::ON_HOLD),
|
|
||||||
Title::DROPPED => $this->getAnimeList(KitsuWatchingStatus::DROPPED),
|
foreach ($statuses as $key => $status)
|
||||||
Title::COMPLETED => $this->getAnimeList(KitsuWatchingStatus::COMPLETED)
|
{
|
||||||
];
|
$mappedStatus = AnimeWatchingStatus::KITSU_TO_TITLE[$status];
|
||||||
|
$output[$mappedStatus] = $this->getAnimeList($status) ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
$cacheItem->set($output);
|
$cacheItem->set($output);
|
||||||
$cacheItem->save();
|
$cacheItem->save();
|
||||||
@ -413,7 +428,16 @@ class Model {
|
|||||||
|
|
||||||
if ( ! $cacheItem->isHit())
|
if ( ! $cacheItem->isHit())
|
||||||
{
|
{
|
||||||
$data = $this->getRawAnimeList($status);
|
$data = $this->getRawAnimeList($status) ?? [];
|
||||||
|
|
||||||
|
// Bail out on no data
|
||||||
|
if (empty($data))
|
||||||
|
{
|
||||||
|
$cacheItem->set([]);
|
||||||
|
$cacheItem->save();
|
||||||
|
return $cacheItem->get();
|
||||||
|
}
|
||||||
|
|
||||||
$included = JsonAPI::organizeIncludes($data['included']);
|
$included = JsonAPI::organizeIncludes($data['included']);
|
||||||
$included = JsonAPI::inlineIncludedRelationships($included, 'anime');
|
$included = JsonAPI::inlineIncludedRelationships($included, 'anime');
|
||||||
|
|
||||||
@ -616,6 +640,12 @@ class Model {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$data = $this->getRequest("{$type}/{$id}", $options);
|
$data = $this->getRequest("{$type}/{$id}", $options);
|
||||||
|
|
||||||
|
if (empty($data['data']))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$baseData = $data['data']['attributes'];
|
$baseData = $data['data']['attributes'];
|
||||||
$baseData['included'] = $data['included'];
|
$baseData['included'] = $data['included'];
|
||||||
return $baseData;
|
return $baseData;
|
||||||
@ -637,11 +667,17 @@ class Model {
|
|||||||
],
|
],
|
||||||
'include' => ($type === 'anime')
|
'include' => ($type === 'anime')
|
||||||
? 'genres,mappings,streamingLinks,animeCharacters.character'
|
? 'genres,mappings,streamingLinks,animeCharacters.character'
|
||||||
: 'genres,mappings',
|
: 'genres,mappings,mangaCharacters.character,castings.character',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$data = $this->getRequest($type, $options);
|
$data = $this->getRequest($type, $options);
|
||||||
|
|
||||||
|
if (empty($data['data']))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$baseData = $data['data'][0]['attributes'];
|
$baseData = $data['data'][0]['attributes'];
|
||||||
$baseData['included'] = $data['included'];
|
$baseData['included'] = $data['included'];
|
||||||
return $baseData;
|
return $baseData;
|
||||||
|
@ -24,6 +24,10 @@ use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\{
|
|||||||
};
|
};
|
||||||
use Aviat\Ion\Enum;
|
use Aviat\Ion\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anime watching status mappings, among Kitsu, MAL, Page titles
|
||||||
|
* and url route segments
|
||||||
|
*/
|
||||||
class AnimeWatchingStatus extends Enum {
|
class AnimeWatchingStatus extends Enum {
|
||||||
const KITSU_TO_MAL = [
|
const KITSU_TO_MAL = [
|
||||||
Kitsu::WATCHING => MAL::WATCHING,
|
Kitsu::WATCHING => MAL::WATCHING,
|
||||||
|
@ -24,6 +24,10 @@ use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{
|
|||||||
};
|
};
|
||||||
use Aviat\Ion\Enum;
|
use Aviat\Ion\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manga reading status mappings, among Kitsu, MAL, Page titles
|
||||||
|
* and url route segments
|
||||||
|
*/
|
||||||
class MangaReadingStatus extends Enum {
|
class MangaReadingStatus extends Enum {
|
||||||
const MAL_TO_KITSU = [
|
const MAL_TO_KITSU = [
|
||||||
Kitsu::READING => MAL::READING,
|
Kitsu::READING => MAL::READING,
|
||||||
|
@ -55,23 +55,23 @@ class SyncKitsuWithMal extends BaseCommand {
|
|||||||
$this->kitsuModel = $this->container->get('kitsu-model');
|
$this->kitsuModel = $this->container->get('kitsu-model');
|
||||||
$this->malModel = $this->container->get('mal-model');
|
$this->malModel = $this->container->get('mal-model');
|
||||||
|
|
||||||
$malCount = count($this->getMALList());
|
$malCount = count($this->getMALAnimeList());
|
||||||
$kitsuCount = $this->getKitsuAnimeListPageCount();
|
$kitsuCount = $this->getKitsuAnimeListPageCount();
|
||||||
|
|
||||||
$this->echoBox("Number of MAL list items: {$malCount}");
|
$this->echoBox("Number of MAL list items: {$malCount}");
|
||||||
$this->echoBox("Number of Kitsu list items: {$kitsuCount}");
|
$this->echoBox("Number of Kitsu list items: {$kitsuCount}");
|
||||||
|
|
||||||
$data = $this->diffLists();
|
$data = $this->diffAnimeLists();
|
||||||
$this->echoBox("Number of items that need to be added to MAL: " . count($data));
|
$this->echoBox("Number of items that need to be added to MAL: " . count($data));
|
||||||
|
|
||||||
if ( ! empty($data['addToMAL']))
|
if ( ! empty($data['addToMAL']))
|
||||||
{
|
{
|
||||||
$this->echoBox("Adding missing list items to MAL");
|
$this->echoBox("Adding missing list items to MAL");
|
||||||
$this->createMALListItems($data['addToMAL']);
|
$this->createMALAnimeListItems($data['addToMAL']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getKitsuList()
|
public function getKitsuAnimeList()
|
||||||
{
|
{
|
||||||
$count = $this->getKitsuAnimeListPageCount();
|
$count = $this->getKitsuAnimeListPageCount();
|
||||||
$size = 100;
|
$size = 100;
|
||||||
@ -100,7 +100,7 @@ class SyncKitsuWithMal extends BaseCommand {
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMALList()
|
public function getMALAnimeList()
|
||||||
{
|
{
|
||||||
return $this->malModel->getFullList();
|
return $this->malModel->getFullList();
|
||||||
}
|
}
|
||||||
@ -120,9 +120,9 @@ class SyncKitsuWithMal extends BaseCommand {
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formatMALList()
|
public function formatMALAnimeList()
|
||||||
{
|
{
|
||||||
$orig = $this->getMALList();
|
$orig = $this->getMALAnimeList();
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
||||||
foreach($orig as $item)
|
foreach($orig as $item)
|
||||||
@ -148,7 +148,7 @@ class SyncKitsuWithMal extends BaseCommand {
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filterKitsuList()
|
public function filterKitsuAnimeList()
|
||||||
{
|
{
|
||||||
$data = $this->kitsuModel->getFullAnimeList();
|
$data = $this->kitsuModel->getFullAnimeList();
|
||||||
$includes = JsonAPI::organizeIncludes($data['included']);
|
$includes = JsonAPI::organizeIncludes($data['included']);
|
||||||
@ -191,14 +191,14 @@ class SyncKitsuWithMal extends BaseCommand {
|
|||||||
return $this->kitsuModel->getAnimeListCount();
|
return $this->kitsuModel->getAnimeListCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function diffLists()
|
public function diffAnimeLists()
|
||||||
{
|
{
|
||||||
// Get libraryEntries with media.mappings from Kitsu
|
// Get libraryEntries with media.mappings from Kitsu
|
||||||
// Organize mappings, and ignore entries without mappings
|
// Organize mappings, and ignore entries without mappings
|
||||||
$kitsuList = $this->filterKitsuList();
|
$kitsuList = $this->filterKitsuAnimeList();
|
||||||
|
|
||||||
// Get MAL list data
|
// Get MAL list data
|
||||||
$malList = $this->formatMALList();
|
$malList = $this->formatMALAnimeList();
|
||||||
|
|
||||||
$itemsToAddToMAL = [];
|
$itemsToAddToMAL = [];
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ class SyncKitsuWithMal extends BaseCommand {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createMALListItems($itemsToAdd)
|
public function createMALAnimeListItems($itemsToAdd)
|
||||||
{
|
{
|
||||||
$transformer = new ALT();
|
$transformer = new ALT();
|
||||||
$requests = [];
|
$requests = [];
|
||||||
@ -261,5 +261,4 @@ class SyncKitsuWithMal extends BaseCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -94,7 +94,6 @@ class Controller {
|
|||||||
/**
|
/**
|
||||||
* Show the login form
|
* Show the login form
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
|
||||||
* @param string $status
|
* @param string $status
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -82,8 +82,10 @@ class Anime extends BaseController {
|
|||||||
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL)
|
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL)
|
||||||
{
|
{
|
||||||
$title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE))
|
$title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE))
|
||||||
? $this->config->get('whose_list') .
|
? $this->formatTitle(
|
||||||
"'s Anime List · " . AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
|
$this->config->get('whose_list') . "'s Anime List",
|
||||||
|
AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
|
||||||
|
)
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
$viewMap = [
|
$viewMap = [
|
||||||
@ -110,8 +112,10 @@ class Anime extends BaseController {
|
|||||||
{
|
{
|
||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
$this->outputHTML('anime/add', [
|
$this->outputHTML('anime/add', [
|
||||||
'title' => $this->config->get('whose_list') .
|
'title' => $this->formatTitle(
|
||||||
"'s Anime List · Add",
|
$this->config->get('whose_list') . "'s Anime List",
|
||||||
|
'Add'
|
||||||
|
),
|
||||||
'action_url' => $this->urlGenerator->url('anime/add'),
|
'action_url' => $this->urlGenerator->url('anime/add'),
|
||||||
'status_list' => AnimeWatchingStatus::KITSU_TO_TITLE
|
'status_list' => AnimeWatchingStatus::KITSU_TO_TITLE
|
||||||
]);
|
]);
|
||||||
@ -158,8 +162,10 @@ class Anime extends BaseController {
|
|||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
|
|
||||||
$this->outputHTML('anime/edit', [
|
$this->outputHTML('anime/edit', [
|
||||||
'title' => $this->config->get('whose_list') .
|
'title' => $this->formatTitle(
|
||||||
"'s Anime List · Edit",
|
$this->config->get('whose_list') . "'s Anime List",
|
||||||
|
'Edit'
|
||||||
|
),
|
||||||
'item' => $item,
|
'item' => $item,
|
||||||
'statuses' => AnimeWatchingStatus::KITSU_TO_TITLE,
|
'statuses' => AnimeWatchingStatus::KITSU_TO_TITLE,
|
||||||
'action' => $this->container->get('url-generator')
|
'action' => $this->container->get('url-generator')
|
||||||
@ -263,6 +269,16 @@ class Anime extends BaseController {
|
|||||||
$data = $this->model->getAnime($animeId);
|
$data = $this->model->getAnime($animeId);
|
||||||
$characters = [];
|
$characters = [];
|
||||||
|
|
||||||
|
if (empty($data))
|
||||||
|
{
|
||||||
|
return $this->notFound(
|
||||||
|
$this->config->get('whose_list') .
|
||||||
|
"'s Anime List · Anime · " .
|
||||||
|
'Anime not found',
|
||||||
|
'Anime Not Found'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
foreach($data['included'] as $included)
|
foreach($data['included'] as $included)
|
||||||
{
|
{
|
||||||
if ($included['type'] === 'characters')
|
if ($included['type'] === 'characters')
|
||||||
@ -272,7 +288,11 @@ class Anime extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->outputHTML('anime/details', [
|
$this->outputHTML('anime/details', [
|
||||||
'title' => 'Anime · ' . $data['titles'][0],
|
'title' => $this->formatTitle(
|
||||||
|
$this->config->get('whose_list') . "'s Anime List",
|
||||||
|
'Anime',
|
||||||
|
$data['titles'][0]
|
||||||
|
),
|
||||||
'characters' => $characters,
|
'characters' => $characters,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
|
@ -18,6 +18,9 @@ namespace Aviat\AnimeClient\Controller;
|
|||||||
|
|
||||||
use Aviat\AnimeClient\Controller as BaseController;
|
use Aviat\AnimeClient\Controller as BaseController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for character description pages
|
||||||
|
*/
|
||||||
class Character extends BaseController {
|
class Character extends BaseController {
|
||||||
|
|
||||||
public function index(string $slug)
|
public function index(string $slug)
|
||||||
@ -26,15 +29,22 @@ class Character extends BaseController {
|
|||||||
|
|
||||||
$data = $model->getCharacter($slug);
|
$data = $model->getCharacter($slug);
|
||||||
|
|
||||||
if ( ! array_key_exists('data', $data))
|
if (( ! array_key_exists('data', $data)) || empty($data['data']))
|
||||||
{
|
{
|
||||||
return $this->notFound();
|
return $this->notFound(
|
||||||
|
$this->formatTitle(
|
||||||
|
'Characters',
|
||||||
|
'Character not found'
|
||||||
|
),
|
||||||
|
'Character Not Found'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $this->outputJSON($data);
|
|
||||||
$this->outputHTML('character', [
|
$this->outputHTML('character', [
|
||||||
'title' => $this->config->get('whose_list') .
|
'title' => $this->formatTitle(
|
||||||
"'s Anime List · Characters · " . $data['data'][0]['attributes']['name'],
|
'Characters',
|
||||||
|
$data['data'][0]['attributes']['name']
|
||||||
|
),
|
||||||
'data' => $data['data'][0]['attributes']
|
'data' => $data['data'][0]['attributes']
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,10 @@ class Collection extends BaseController {
|
|||||||
$this->outputHTML('collection/' . strtolower($action), [
|
$this->outputHTML('collection/' . strtolower($action), [
|
||||||
'action' => $action,
|
'action' => $action,
|
||||||
'action_url' => $this->urlGenerator->fullUrl('collection/' . strtolower($action)),
|
'action_url' => $this->urlGenerator->fullUrl('collection/' . strtolower($action)),
|
||||||
'title' => $this->config->get('whose_list') . " Anime Collection · {$action}",
|
'title' => $this->formatTitle(
|
||||||
|
$this->config->get('whose_list') . "'s Anime Collection",
|
||||||
|
$action
|
||||||
|
),
|
||||||
'media_items' => $this->animeCollectionModel->getMediaTypeList(),
|
'media_items' => $this->animeCollectionModel->getMediaTypeList(),
|
||||||
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
|
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
|
||||||
]);
|
]);
|
||||||
|
@ -71,7 +71,10 @@ class Manga extends Controller {
|
|||||||
{
|
{
|
||||||
$statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status];
|
$statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status];
|
||||||
|
|
||||||
$title = $this->config->get('whose_list') . "'s Manga List · {$statusTitle}";
|
$title = $this->formatTitle(
|
||||||
|
$this->config->get('whose_list') . "'s Manga List",
|
||||||
|
$statusTitle
|
||||||
|
);
|
||||||
|
|
||||||
$view_map = [
|
$view_map = [
|
||||||
'' => 'cover',
|
'' => 'cover',
|
||||||
@ -109,8 +112,10 @@ class Manga extends Controller {
|
|||||||
|
|
||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
$this->outputHTML('manga/add', [
|
$this->outputHTML('manga/add', [
|
||||||
'title' => $this->config->get('whose_list') .
|
'title' => $this->formatTitle(
|
||||||
"'s Manga List · Add",
|
$this->config->get('whose_list') . "'s Manga List",
|
||||||
|
'Add'
|
||||||
|
),
|
||||||
'action_url' => $this->urlGenerator->url('manga/add'),
|
'action_url' => $this->urlGenerator->url('manga/add'),
|
||||||
'status_list' => $statuses
|
'status_list' => $statuses
|
||||||
]);
|
]);
|
||||||
@ -155,7 +160,10 @@ class Manga extends Controller {
|
|||||||
{
|
{
|
||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
$item = $this->model->getLibraryItem($id);
|
$item = $this->model->getLibraryItem($id);
|
||||||
$title = $this->config->get('whose_list') . "'s Manga List · Edit";
|
$title = $this->formatTitle(
|
||||||
|
$this->config->get('whose_list') . "'s Manga List",
|
||||||
|
'Edit'
|
||||||
|
);
|
||||||
|
|
||||||
$this->outputHTML('manga/edit', [
|
$this->outputHTML('manga/edit', [
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
@ -261,9 +269,35 @@ class Manga extends Controller {
|
|||||||
public function details($manga_id)
|
public function details($manga_id)
|
||||||
{
|
{
|
||||||
$data = $this->model->getManga($manga_id);
|
$data = $this->model->getManga($manga_id);
|
||||||
|
$characters = [];
|
||||||
|
|
||||||
|
if (empty($data))
|
||||||
|
{
|
||||||
|
return $this->notFound(
|
||||||
|
$this->config->get('whose_list') .
|
||||||
|
"'s Manga List · Manga · " .
|
||||||
|
'Manga not found',
|
||||||
|
'Manga Not Found'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// dump($data);
|
||||||
|
|
||||||
|
foreach($data['included'] as $included)
|
||||||
|
{
|
||||||
|
if ($included['type'] === 'characters')
|
||||||
|
{
|
||||||
|
$characters[$included['id']] = $included['attributes'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->outputHTML('manga/details', [
|
$this->outputHTML('manga/details', [
|
||||||
'title' => 'Manga · ' . $data['title'],
|
'title' => $this->formatTitle(
|
||||||
|
$this->config->get('whose_list') . "'s Manga List",
|
||||||
|
'Manga',
|
||||||
|
$data['title']
|
||||||
|
),
|
||||||
|
'characters' => $characters,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -234,10 +234,14 @@ trait ControllerTrait {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function notFound()
|
public function notFound(
|
||||||
|
string $title = 'Sorry, page not found',
|
||||||
|
string $message = 'Page Not Found'
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$this->outputHTML('404', [
|
$this->outputHTML('404', [
|
||||||
'title' => 'Sorry, page not found'
|
'title' => $title,
|
||||||
|
'message' => $message,
|
||||||
], NULL, 404);
|
], NULL, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,10 +301,20 @@ trait ControllerTrait {
|
|||||||
], NULL, 200);
|
], NULL, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper for consistent page titles
|
||||||
|
*
|
||||||
|
* @param string ...$parts Title segements
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function formatTitle(string ...$parts) : string
|
||||||
|
{
|
||||||
|
return implode(' · ', $parts);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a message box to the page
|
* Add a message box to the page
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
|
||||||
* @param HtmlView $view
|
* @param HtmlView $view
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $message
|
* @param string $message
|
||||||
|
@ -106,7 +106,6 @@ class Dispatcher extends RoutingBase {
|
|||||||
/**
|
/**
|
||||||
* Handle the current route
|
* Handle the current route
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
|
||||||
* @param object|null $route
|
* @param object|null $route
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +24,6 @@ class API extends AbstractModel {
|
|||||||
/**
|
/**
|
||||||
* Sort the list entries by their title
|
* Sort the list entries by their title
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
|
||||||
* @param array $array
|
* @param array $array
|
||||||
* @param string $sortKey
|
* @param string $sortKey
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -21,6 +21,7 @@ use Aura\Web\WebFactory;
|
|||||||
use Aviat\AnimeClient\Controller;
|
use Aviat\AnimeClient\Controller;
|
||||||
use Aviat\AnimeClient\Controller\{
|
use Aviat\AnimeClient\Controller\{
|
||||||
Anime as AnimeController,
|
Anime as AnimeController,
|
||||||
|
Character as CharacterController,
|
||||||
Collection as CollectionController,
|
Collection as CollectionController,
|
||||||
Manga as MangaController
|
Manga as MangaController
|
||||||
};
|
};
|
||||||
@ -64,6 +65,10 @@ class ControllerTest extends AnimeClientTestCase {
|
|||||||
'Aviat\AnimeClient\Controller',
|
'Aviat\AnimeClient\Controller',
|
||||||
new MangaController($this->container)
|
new MangaController($this->container)
|
||||||
);
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
'Aviat\AnimeClient\Controller',
|
||||||
|
new CharacterController($this->container)
|
||||||
|
);
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
'Aviat\AnimeClient\Controller',
|
'Aviat\AnimeClient\Controller',
|
||||||
new CollectionController($this->container)
|
new CollectionController($this->container)
|
||||||
|
39
tests/ControllerTraitTest.php
Normal file
39
tests/ControllerTraitTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* Hummingbird Anime List Client
|
||||||
|
*
|
||||||
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
||||||
|
*
|
||||||
|
* PHP version 7
|
||||||
|
*
|
||||||
|
* @package HummingbirdAnimeClient
|
||||||
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||||
|
* @copyright 2015 - 2017 Timothy J. Warren
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||||
|
* @version 4.0
|
||||||
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Aviat\AnimeClient\Tests;
|
||||||
|
|
||||||
|
use Aviat\AnimeClient\ControllerTrait;
|
||||||
|
|
||||||
|
class ControllerTraitTest extends AnimeClientTestCase {
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->controller = new class {
|
||||||
|
use ControllerTrait;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormatTitle()
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->controller->formatTitle('foo', 'bar', 'baz'),
|
||||||
|
'foo · bar · baz'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user