Update Manga mappings and enums
This commit is contained in:
parent
1f86d4460c
commit
9c7ed16538
31
src/API/Enum/MangaReadingStatus/Route.php
Normal file
31
src/API/Enum/MangaReadingStatus/Route.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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://github.com/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\API\Enum\MangaReadingStatus;
|
||||
|
||||
use Aviat\Ion\Enum as Enum;
|
||||
|
||||
/**
|
||||
* Possible values for current reading status of manga
|
||||
*/
|
||||
class Route extends Enum {
|
||||
const ALL = 'all';
|
||||
const READING = 'reading';
|
||||
const PLAN_TO_READ = 'plan_to_read';
|
||||
const DROPPED = 'dropped';
|
||||
const ON_HOLD = 'on_hold';
|
||||
const COMPLETED = 'completed';
|
||||
}
|
31
src/API/Enum/MangaReadingStatus/Title.php
Normal file
31
src/API/Enum/MangaReadingStatus/Title.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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://github.com/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\API\Enum\MangaReadingStatus;
|
||||
|
||||
use Aviat\Ion\Enum as Enum;
|
||||
|
||||
/**
|
||||
* Possible values for current reading status of manga
|
||||
*/
|
||||
class Title extends Enum {
|
||||
const ALL = 'All';
|
||||
const READING = 'Currently Reading';
|
||||
const PLAN_TO_READ = 'Plan to Read';
|
||||
const DROPPED = 'Dropped';
|
||||
const ON_HOLD = 'On Hold';
|
||||
const COMPLETED = 'Completed';
|
||||
}
|
77
src/API/Mapping/MangaReadingStatus.php
Normal file
77
src/API/Mapping/MangaReadingStatus.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?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://github.com/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient\API\Mapping;
|
||||
|
||||
use Aviat\AnimeClient\API\{
|
||||
Kitsu\Enum\MangaReadingStatus as Kitsu,
|
||||
MAL\Enum\MangaReadingStatus as MAL
|
||||
};
|
||||
use Aviat\AnimeClient\API\Enum\MangaReadingStatus\{Title, Route};
|
||||
use Aviat\Ion\Enum;
|
||||
|
||||
class MangaReadingStatus extends Enum {
|
||||
const MAL_TO_KITSU = [
|
||||
Kitsu::READING => MAL::READING,
|
||||
Kitsu::PLAN_TO_READ => MAL::PLAN_TO_READ,
|
||||
Kitsu::COMPLETED => MAL::COMPLETED,
|
||||
Kitsu::ON_HOLD => MAL::ON_HOLD,
|
||||
Kitsu::DROPPED => MAL::DROPPED
|
||||
];
|
||||
|
||||
const KITSU_TO_MAL = [
|
||||
MAL::READING => Kitsu::READING,
|
||||
MAL::PLAN_TO_READ => Kitsu::PLAN_TO_READ,
|
||||
MAL::COMPLETED => Kitsu::COMPLETED,
|
||||
MAL::ON_HOLD => Kitsu::ON_HOLD,
|
||||
MAL::DROPPED => Kitsu::DROPPED
|
||||
];
|
||||
|
||||
const KITSU_TO_TITLE = [
|
||||
Kitsu::READING => Title::READING,
|
||||
Kitsu::PLAN_TO_READ => Title::PLAN_TO_READ,
|
||||
Kitsu::COMPLETED => Title::COMPLETED,
|
||||
Kitsu::ON_HOLD => Title::ON_HOLD,
|
||||
Kitsu::DROPPED => Title::DROPPED
|
||||
];
|
||||
|
||||
const ROUTE_TO_KITSU = [
|
||||
Route::ALL => 'all',
|
||||
Route::PLAN_TO_READ => Kitsu::PLAN_TO_READ,
|
||||
Route::READING => Kitsu::READING,
|
||||
Route::COMPLETED => Kitsu::COMPLETED,
|
||||
Route::DROPPED => Kitsu::DROPPED,
|
||||
Route::ON_HOLD => Kitsu::ON_HOLD
|
||||
];
|
||||
|
||||
const ROUTE_TO_TITLE = [
|
||||
Route::ALL => Title::ALL,
|
||||
Route::PLAN_TO_READ => Title::PLAN_TO_READ,
|
||||
Route::READING => Title::READING,
|
||||
Route::COMPLETED => Title::COMPLETED,
|
||||
Route::DROPPED => Title::DROPPED,
|
||||
Route::ON_HOLD => Title::ON_HOLD
|
||||
];
|
||||
|
||||
const TITLE_TO_KITSU = [
|
||||
Title::ALL => 'all',
|
||||
Title::PLAN_TO_READ => Kitsu::PLAN_TO_READ,
|
||||
Title::READING => Kitsu::READING,
|
||||
Title::COMPLETED => Kitsu::COMPLETED,
|
||||
Title::DROPPED => Kitsu::DROPPED,
|
||||
Title::ON_HOLD => Kitsu::ON_HOLD
|
||||
];
|
||||
}
|
@ -18,8 +18,11 @@ namespace Aviat\AnimeClient\Controller;
|
||||
|
||||
use Aviat\AnimeClient\Controller;
|
||||
use Aviat\AnimeClient\API\Kitsu;
|
||||
use Aviat\AnimeClient\API\Kitsu\Enum\MangaReadingStatus;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
|
||||
use Aviat\AnimeClient\API\Kitsu\{
|
||||
Enum\MangaReadingStatus as KitsuReadingStatus,
|
||||
Transformer\MangaListTransformer
|
||||
};
|
||||
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
|
||||
use Aviat\AnimeClient\Model\Manga as MangaModel;
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\{Json, StringWrapper};
|
||||
@ -70,16 +73,9 @@ class Manga extends Controller {
|
||||
*/
|
||||
public function index($status = "all", $view = "")
|
||||
{
|
||||
$map = [
|
||||
'all' => 'All',
|
||||
'plan_to_read' => MangaModel::PLAN_TO_READ,
|
||||
'reading' => MangaModel::READING,
|
||||
'completed' => MangaModel::COMPLETED,
|
||||
'dropped' => MangaModel::DROPPED,
|
||||
'on_hold' => MangaModel::ON_HOLD
|
||||
];
|
||||
$statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status];
|
||||
|
||||
$title = $this->config->get('whose_list') . "'s Manga List · {$map[$status]}";
|
||||
$title = $this->config->get('whose_list') . "'s Manga List · {$statusTitle}";
|
||||
|
||||
$view_map = [
|
||||
'' => 'cover',
|
||||
@ -87,7 +83,7 @@ class Manga extends Controller {
|
||||
];
|
||||
|
||||
$data = ($status !== 'all')
|
||||
? [$map[$status] => $this->model->getList($map[$status]) ]
|
||||
? [ $statusTitle => $this->model->getList($statusTitle) ]
|
||||
: $this->model->getList('All');
|
||||
|
||||
$this->outputHTML('manga/' . $view_map[$view], [
|
||||
@ -167,7 +163,7 @@ class Manga extends Controller {
|
||||
|
||||
$this->outputHTML('manga/edit', [
|
||||
'title' => $title,
|
||||
'status_list' => Kitsu::getStatusToMangaSelectMap(),
|
||||
'status_list' => MangaReadingStatus::KITSU_TO_TITLE,
|
||||
'item' => $item,
|
||||
'action' => $this->container->get('url-generator')
|
||||
->url('/manga/update_form'),
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
namespace Aviat\AnimeClient\Model;
|
||||
|
||||
use Aviat\AnimeClient\API\Kitsu\Enum\MangaReadingStatus;
|
||||
use Aviat\AnimeClient\API\Kitsu\Transformer;
|
||||
use Aviat\AnimeClient\API\Enum\MangaReadingStatus\Title;
|
||||
use Aviat\AnimeClient\API\Mapping\MangaReadingStatus;
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
|
||||
/**
|
||||
@ -25,37 +25,6 @@ use Aviat\Ion\Di\ContainerInterface;
|
||||
*/
|
||||
class Manga extends API
|
||||
{
|
||||
|
||||
const READING = 'Reading';
|
||||
const PLAN_TO_READ = 'Plan to Read';
|
||||
const DROPPED = 'Dropped';
|
||||
const ON_HOLD = 'On Hold';
|
||||
const COMPLETED = 'Completed';
|
||||
|
||||
/**
|
||||
* Map API constants to display constants
|
||||
* @var array
|
||||
*/
|
||||
protected $constMap = [
|
||||
MangaReadingStatus::READING => self::READING,
|
||||
MangaReadingStatus::PLAN_TO_READ => self::PLAN_TO_READ,
|
||||
MangaReadingStatus::ON_HOLD => self::ON_HOLD,
|
||||
MangaReadingStatus::DROPPED => self::DROPPED,
|
||||
MangaReadingStatus::COMPLETED => self::COMPLETED
|
||||
];
|
||||
|
||||
/**
|
||||
* Maps url segments to their title equivalents
|
||||
* @var array
|
||||
*/
|
||||
protected $statusMap = [
|
||||
'current' => self::READING,
|
||||
'planned' => self::PLAN_TO_READ,
|
||||
'completed' => self::COMPLETED,
|
||||
'on_hold' => self::ON_HOLD,
|
||||
'dropped' => self::DROPPED
|
||||
];
|
||||
|
||||
/**
|
||||
* Model for making requests to Kitsu API
|
||||
* @var \Aviat\AnimeClient\API\Kitsu\Model
|
||||
@ -87,7 +56,7 @@ class Manga extends API
|
||||
*/
|
||||
public function getList($status)
|
||||
{
|
||||
$APIstatus = array_flip($this->constMap)[$status];
|
||||
$APIstatus = MangaReadingStatus::TITLE_TO_KITSU[$status];
|
||||
$data = $this->kitsuModel->getMangaList($APIstatus);
|
||||
return $this->mapByStatus($data)[$status];
|
||||
}
|
||||
@ -168,15 +137,16 @@ class Manga extends API
|
||||
private function mapByStatus($data)
|
||||
{
|
||||
$output = [
|
||||
self::READING => [],
|
||||
self::PLAN_TO_READ => [],
|
||||
self::ON_HOLD => [],
|
||||
self::DROPPED => [],
|
||||
self::COMPLETED => [],
|
||||
Title::READING => [],
|
||||
Title::PLAN_TO_READ => [],
|
||||
Title::ON_HOLD => [],
|
||||
Title::DROPPED => [],
|
||||
Title::COMPLETED => [],
|
||||
];
|
||||
|
||||
foreach ($data as &$entry) {
|
||||
$key = $this->statusMap[$entry['reading_status']];
|
||||
$statusMap = MangaReadingStatus::KITSU_TO_TITLE;
|
||||
$key = $statusMap[$entry['reading_status']];
|
||||
$output[$key][] = $entry;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user