From f9f868be9dbdd3779cccbc8cbd4c6a7a5932ad6c Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 6 May 2020 09:08:27 -0400 Subject: [PATCH] Show more alternate titles on anime detail pages --- app/views/anime/details.php | 2 +- src/AnimeClient/API/Kitsu.php | 28 +++++++++++++++++++ src/AnimeClient/API/Kitsu/Model.php | 4 +-- .../Kitsu/Transformer/AnimeTransformer.php | 2 ++ src/AnimeClient/Types/Anime.php | 5 ++++ src/AnimeClient/Types/AnimePage.php | 4 +-- 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/app/views/anime/details.php b/app/views/anime/details.php index c3089004..9e72b539 100644 --- a/app/views/anime/details.php +++ b/app/views/anime/details.php @@ -45,7 +45,7 @@

- +


diff --git a/src/AnimeClient/API/Kitsu.php b/src/AnimeClient/API/Kitsu.php index d7c6c69e..94bc3edb 100644 --- a/src/AnimeClient/API/Kitsu.php +++ b/src/AnimeClient/API/Kitsu.php @@ -195,6 +195,23 @@ final class Kitsu { return []; } + /** + * Get the list of titles + * + * @param array $data + * @return array + */ + public static function getTitles(array $data): array + { + $raw = array_unique([ + $data['canonicalTitle'], + ...array_values($data['titles']), + ...array_values($data['abbreviatedTitles']), + ]); + + return array_diff($raw,[$data['canonicalTitle']]); + } + /** * Filter out duplicate and very similar names from * @@ -217,6 +234,17 @@ final class Kitsu { } } + if (array_key_exists('abbreviatedTitles', $data)) + { + foreach ($data['abbreviatedTitles'] as $alternateTitle) + { + if (self::titleIsUnique($alternateTitle, $valid)) + { + $valid[] = $alternateTitle; + } + } + } + return $valid; } diff --git a/src/AnimeClient/API/Kitsu/Model.php b/src/AnimeClient/API/Kitsu/Model.php index 8571e30d..15c5687d 100644 --- a/src/AnimeClient/API/Kitsu/Model.php +++ b/src/AnimeClient/API/Kitsu/Model.php @@ -252,8 +252,8 @@ final class Model { 'fields' => [ 'characters' => 'canonicalName,slug,image', 'characterVoices' => 'mediaCharacter', - 'anime' => 'canonicalTitle,titles,slug,posterImage', - 'manga' => 'canonicalTitle,titles,slug,posterImage', + 'anime' => 'canonicalTitle,abbreviatedTitles,titles,slug,posterImage', + 'manga' => 'canonicalTitle,abbreviatedTitles,titles,slug,posterImage', 'mediaCharacters' => 'role,media,character', 'mediaStaff' => 'role,media,person', ], diff --git a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php index e0b049b0..838f6549 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php @@ -42,6 +42,7 @@ final class AnimeTransformer extends AbstractTransformer { $title = $item['canonicalTitle']; $titles = Kitsu::filterTitles($item); + $titles_more = Kitsu::getTitles($item); $characters = []; $staff = []; @@ -123,6 +124,7 @@ final class AnimeTransformer extends AbstractTransformer { 'synopsis' => $item['synopsis'], 'title' => $title, 'titles' => $titles, + 'titles_more' => $titles_more, 'trailer_id' => $item['youtubeVideoId'], 'url' => "https://kitsu.io/anime/{$item['slug']}", ]); diff --git a/src/AnimeClient/Types/Anime.php b/src/AnimeClient/Types/Anime.php index b9435937..af6b649a 100644 --- a/src/AnimeClient/Types/Anime.php +++ b/src/AnimeClient/Types/Anime.php @@ -97,6 +97,11 @@ class Anime extends AbstractType { */ public array $titles = []; + /** + * @var array + */ + public array $titles_more = []; + /** * @var string */ diff --git a/src/AnimeClient/Types/AnimePage.php b/src/AnimeClient/Types/AnimePage.php index b1a3b5d9..ef530373 100644 --- a/src/AnimeClient/Types/AnimePage.php +++ b/src/AnimeClient/Types/AnimePage.php @@ -23,10 +23,10 @@ final class AnimePage extends Anime { /** * @var array */ - public $characters; + public array $characters = []; /** * @var array */ - public $staff; + public array $staff = []; } \ No newline at end of file