Merge branch 'develop' into 'master'

Develop

See merge request !17
This commit is contained in:
Timothy Warren 2017-03-28 10:43:51 -04:00
commit 0c4c0a436c
21 changed files with 289 additions and 127 deletions

View File

@ -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, ' && ');
} }

View File

@ -1,4 +1,4 @@
<main> <main>
<h1>404</h1> <h1>404</h1>
<h2>Page Not Found</h2> <h2><?= $message ?></h2>
</main> </main>

View File

@ -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>

View File

@ -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
View File

@ -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();

View File

@ -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
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -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';
} }

View File

@ -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;

View File

@ -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,

View File

@ -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,

View File

@ -54,38 +54,38 @@ class SyncKitsuWithMal extends BaseCommand {
$this->setCache($this->container->get('cache')); $this->setCache($this->container->get('cache'));
$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;
$pages = ceil($count / $size); $pages = ceil($count / $size);
$requests = []; $requests = [];
// Set up requests // Set up requests
for ($i = 0; $i < $pages; $i++) for ($i = 0; $i < $pages; $i++)
{ {
$offset = $i * $size; $offset = $i * $size;
$requests[] = $this->kitsuModel->getPagedAnimeList($size, $offset); $requests[] = $this->kitsuModel->getPagedAnimeList($size, $offset);
} }
$promiseArray = (new Client())->requestMulti($requests); $promiseArray = (new Client())->requestMulti($requests);
$responses = wait(all($promiseArray)); $responses = wait(all($promiseArray));
@ -100,15 +100,15 @@ class SyncKitsuWithMal extends BaseCommand {
return $output; return $output;
} }
public function getMALList() public function getMALAnimeList()
{ {
return $this->malModel->getFullList(); return $this->malModel->getFullList();
} }
public function filterMappings(array $includes): array public function filterMappings(array $includes): array
{ {
$output = []; $output = [];
foreach($includes as $id => $mapping) foreach($includes as $id => $mapping)
{ {
if ($mapping['externalSite'] === 'myanimelist/anime') if ($mapping['externalSite'] === 'myanimelist/anime')
@ -116,15 +116,15 @@ class SyncKitsuWithMal extends BaseCommand {
$output[$id] = $mapping; $output[$id] = $mapping;
} }
} }
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)
{ {
$output[$item['series_animedb_id']] = [ $output[$item['series_animedb_id']] = [
@ -144,24 +144,24 @@ 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']);
$includes['mappings'] = $this->filterMappings($includes['mappings']); $includes['mappings'] = $this->filterMappings($includes['mappings']);
$output = []; $output = [];
foreach($data['data'] as $listItem) foreach($data['data'] as $listItem)
{ {
$animeId = $listItem['relationships']['anime']['data']['id']; $animeId = $listItem['relationships']['anime']['data']['id'];
$potentialMappings = $includes['anime'][$animeId]['relationships']['mappings']; $potentialMappings = $includes['anime'][$animeId]['relationships']['mappings'];
$malId = NULL; $malId = NULL;
foreach ($potentialMappings as $mappingId) foreach ($potentialMappings as $mappingId)
{ {
if (array_key_exists($mappingId, $includes['mappings'])) if (array_key_exists($mappingId, $includes['mappings']))
@ -169,20 +169,20 @@ class SyncKitsuWithMal extends BaseCommand {
$malId = $includes['mappings'][$mappingId]['externalId']; $malId = $includes['mappings'][$mappingId]['externalId'];
} }
} }
// Skip to the next item if there isn't a MAL ID // Skip to the next item if there isn't a MAL ID
if (is_null($malId)) if (is_null($malId))
{ {
continue; continue;
} }
$output[$listItem['id']] = [ $output[$listItem['id']] = [
'id' => $listItem['id'], 'id' => $listItem['id'],
'malId' => $malId, 'malId' => $malId,
'data' => $listItem['attributes'], 'data' => $listItem['attributes'],
]; ];
} }
return $output; return $output;
} }
@ -191,32 +191,32 @@ 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 = [];
foreach($kitsuList as $kitsuItem) foreach($kitsuList as $kitsuItem)
{ {
if (array_key_exists($kitsuItem['malId'], $malList)) if (array_key_exists($kitsuItem['malId'], $malList))
{ {
// Eventually, compare the list entries, and determine which // Eventually, compare the list entries, and determine which
// needs to be updated // needs to be updated
continue; continue;
} }
// Looks like this item only exists on Kitsu // Looks like this item only exists on Kitsu
$itemsToAddToMAL[] = [ $itemsToAddToMAL[] = [
'mal_id' => $kitsuItem['malId'], 'mal_id' => $kitsuItem['malId'],
'data' => $kitsuItem['data'] 'data' => $kitsuItem['data']
]; ];
} }
// Compare each list entry // Compare each list entry
@ -227,17 +227,17 @@ class SyncKitsuWithMal extends BaseCommand {
// Otherwise, use rewatch count, then episode progress as critera for selecting the more up // Otherwise, use rewatch count, then episode progress as critera for selecting the more up
// to date entry // to date entry
// Based on the 'newer' entry, update the other api list item // Based on the 'newer' entry, update the other api list item
return [ return [
'addToMAL' => $itemsToAddToMAL, 'addToMAL' => $itemsToAddToMAL,
]; ];
} }
public function createMALListItems($itemsToAdd) public function createMALAnimeListItems($itemsToAdd)
{ {
$transformer = new ALT(); $transformer = new ALT();
$requests = []; $requests = [];
foreach($itemsToAdd as $item) foreach($itemsToAdd as $item)
{ {
$data = $transformer->untransform($item); $data = $transformer->untransform($item);
@ -261,5 +261,4 @@ class SyncKitsuWithMal extends BaseCommand {
} }
} }
} }
} }

View File

@ -47,7 +47,7 @@ class Controller {
$this->config = $container->get('config'); $this->config = $container->get('config');
$this->request = $container->get('request'); $this->request = $container->get('request');
$this->response = $container->get('response'); $this->response = $container->get('response');
$this->baseData = array_merge((array)$this->baseData, [ $this->baseData = array_merge((array)$this->baseData, [
'url' => $auraUrlGenerator, 'url' => $auraUrlGenerator,
'urlGenerator' => $urlGenerator, 'urlGenerator' => $urlGenerator,
@ -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
*/ */

View File

@ -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 &middot; " . 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 &middot; 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 &middot; 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')
@ -262,7 +268,17 @@ 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 &middot; Anime &middot; " .
'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 &middot ' . $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,
]); ]);

View File

@ -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 &middot; Characters &middot; " . $data['data'][0]['attributes']['name'], 'Characters',
$data['data'][0]['attributes']['name']
),
'data' => $data['data'][0]['attributes'] 'data' => $data['data'][0]['attributes']
]); ]);
} }

View File

@ -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 &middot; {$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) : []
]); ]);

View File

@ -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 &middot; {$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 &middot; 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 &middot; 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 &middot; Manga &middot; " .
'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 &middot; ' . $data['title'], 'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List",
'Manga',
$data['title']
),
'characters' => $characters,
'data' => $data, 'data' => $data,
]); ]);
} }

View File

@ -26,7 +26,7 @@ use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
use InvalidArgumentException; use InvalidArgumentException;
trait ControllerTrait { trait ControllerTrait {
use ContainerAware; use ContainerAware;
/** /**
@ -80,7 +80,7 @@ trait ControllerTrait {
'other_type' => 'manga', 'other_type' => 'manga',
'menu_name' => '' 'menu_name' => ''
]; ];
/** /**
* Redirect to the default controller/url from an empty path * Redirect to the default controller/url from an empty path
* *
@ -228,16 +228,20 @@ trait ControllerTrait {
$view->appendOutput($this->loadPartial($view, $template, $data)); $view->appendOutput($this->loadPartial($view, $template, $data));
$view->appendOutput($this->loadPartial($view, 'footer', $data)); $view->appendOutput($this->loadPartial($view, 'footer', $data));
} }
/** /**
* 404 action * 404 action
* *
* @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);
} }
@ -270,17 +274,17 @@ trait ControllerTrait {
public function setFlashMessage($message, $type = "info") public function setFlashMessage($message, $type = "info")
{ {
static $messages; static $messages;
if ( ! $messages) if ( ! $messages)
{ {
$messages = []; $messages = [];
} }
$messages[] = [ $messages[] = [
'message_type' => $type, 'message_type' => $type,
'message' => $message 'message' => $message
]; ];
$this->session->setFlash('message', $messages); $this->session->setFlash('message', $messages);
} }
@ -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(' &middot; ', $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

View File

@ -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
*/ */
@ -262,7 +261,7 @@ class Dispatcher extends RoutingBase {
// Run the appropriate controller method // Run the appropriate controller method
$logger->debug('Dispatcher - controller arguments'); $logger->debug('Dispatcher - controller arguments');
$logger->debug(print_r($params, TRUE)); $logger->debug(print_r($params, TRUE));
call_user_func_array([$controller, $method], $params); call_user_func_array([$controller, $method], $params);
} }

View File

@ -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

View File

@ -21,12 +21,13 @@ 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
}; };
class ControllerTest extends AnimeClientTestCase { class ControllerTest extends AnimeClientTestCase {
protected $BaseController; protected $BaseController;
public function setUp() public function setUp()
@ -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)

View 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 &middot; bar &middot; baz'
);
}
}