From 7275d814682cc4e4d584fb1ae530ce7b86cecce8 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 29 Jul 2020 11:00:54 -0400 Subject: [PATCH] Re-add characters to anime details page, see #27 --- app/views/anime/details.php | 6 +++--- .../GraphQL/Queries/AnimeDetails.graphql | 18 ----------------- .../Kitsu/Transformer/AnimeTransformer.php | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/views/anime/details.php b/app/views/anime/details.php index 9e72b539..98bcf8d1 100644 --- a/app/views/anime/details.php +++ b/app/views/anime/details.php @@ -11,10 +11,10 @@ Airing Status - + Show Type - + */ ?> Episode Count @@ -130,7 +130,7 @@
generate('character', ['slug' => $char['slug']]) ?>
- a($link, $char['name']); ?> + a($link, $char['name']) ?>
picture("images/characters/{$id}.webp") ?> diff --git a/src/AnimeClient/API/Kitsu/GraphQL/Queries/AnimeDetails.graphql b/src/AnimeClient/API/Kitsu/GraphQL/Queries/AnimeDetails.graphql index 09f66264..f41066c9 100644 --- a/src/AnimeClient/API/Kitsu/GraphQL/Queries/AnimeDetails.graphql +++ b/src/AnimeClient/API/Kitsu/GraphQL/Queries/AnimeDetails.graphql @@ -41,24 +41,6 @@ query ($slug: String!) { slug } role - voices { - nodes { - id - licensor { - id - name - } - locale - person { - id - names { - alternatives - canonical - localized - } - } - } - } } pageInfo { endCursor diff --git a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php index df3d6ace..4afe576e 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/AnimeTransformer.php @@ -46,6 +46,26 @@ final class AnimeTransformer extends AbstractTransformer { $title = $base['titles']['canonical']; $titles = Kitsu::filterLocalizedTitles($base['titles']); + if (count($base['characters']['nodes']) > 0) + { + $characters['main'] = []; + $characters['supporting'] = []; + + foreach ($base['characters']['nodes'] as $rawCharacter) + { + $type = $rawCharacter['role'] === 'MAIN' ? 'main' : 'supporting'; + $details = $rawCharacter['character']; + $characters[$type][$details['id']] = [ + 'image' => $details['image'], + 'name' => $details['names']['canonical'], + 'slug' => $details['slug'], + ]; + } + + uasort($characters['main'], fn($a, $b) => $a['name'] <=> $b['name']); + uasort($characters['supporting'], fn($a, $b) => $a['name'] <=> $b['name']); + } + $data = [ 'age_rating' => $base['ageRating'], 'age_rating_guide' => $base['ageRatingGuide'],