From 52e1d1822a9bf294605cfe53838df7691af95436 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 1 Mar 2017 21:52:30 -0500 Subject: [PATCH] Update Manga mappings and enums --- src/API/Enum/MangaReadingStatus/Route.php | 31 +++++++++ src/API/Enum/MangaReadingStatus/Title.php | 31 +++++++++ src/API/Mapping/MangaReadingStatus.php | 77 +++++++++++++++++++++++ src/Controller/Manga.php | 22 +++---- src/Model/Manga.php | 52 ++++----------- 5 files changed, 159 insertions(+), 54 deletions(-) create mode 100644 src/API/Enum/MangaReadingStatus/Route.php create mode 100644 src/API/Enum/MangaReadingStatus/Title.php create mode 100644 src/API/Mapping/MangaReadingStatus.php diff --git a/src/API/Enum/MangaReadingStatus/Route.php b/src/API/Enum/MangaReadingStatus/Route.php new file mode 100644 index 00000000..248a3fbf --- /dev/null +++ b/src/API/Enum/MangaReadingStatus/Route.php @@ -0,0 +1,31 @@ + + * @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'; +} diff --git a/src/API/Enum/MangaReadingStatus/Title.php b/src/API/Enum/MangaReadingStatus/Title.php new file mode 100644 index 00000000..a8365f19 --- /dev/null +++ b/src/API/Enum/MangaReadingStatus/Title.php @@ -0,0 +1,31 @@ + + * @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'; +} diff --git a/src/API/Mapping/MangaReadingStatus.php b/src/API/Mapping/MangaReadingStatus.php new file mode 100644 index 00000000..9269f49a --- /dev/null +++ b/src/API/Mapping/MangaReadingStatus.php @@ -0,0 +1,77 @@ + + * @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 + ]; +} \ No newline at end of file diff --git a/src/Controller/Manga.php b/src/Controller/Manga.php index 24357342..6cc37465 100644 --- a/src/Controller/Manga.php +++ b/src/Controller/Manga.php @@ -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'), diff --git a/src/Model/Manga.php b/src/Model/Manga.php index e1149d73..ce07dd57 100644 --- a/src/Model/Manga.php +++ b/src/Model/Manga.php @@ -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,43 +25,12 @@ 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 */ protected $kitsuModel; - + /** * Model for making requests to MAL API * @var \Aviat\AnimeClient\API\MAL\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; }