diff --git a/app/views/anime/details.php b/app/views/anime/details.php index 9d14e390..c9390200 100644 --- a/app/views/anime/details.php +++ b/app/views/anime/details.php @@ -74,7 +74,30 @@ - */ ?> + + + */ ?> +
+ 0): ?> +

Characters

+
+ + +
+ generate('character', ['slug' => $char['slug']]) ?> + a($link, $char['name']); ?> +
+ + img($char['image']['original'], [ + 'width' => '225' + ]) ?> + +
+ + +
+ +
\ No newline at end of file diff --git a/src/API/JsonAPI.php b/src/API/JsonAPI.php index dc0475e0..2776c4ec 100644 --- a/src/API/JsonAPI.php +++ b/src/API/JsonAPI.php @@ -167,7 +167,10 @@ class JsonAPI { foreach ($data['data'] as $item) { - $organized[$key][] = $item['id']; + if (is_array($item) && array_key_exists('id', $item)) + { + $organized[$key][] = $item['id']; + } } } diff --git a/src/API/Kitsu/Model.php b/src/API/Kitsu/Model.php index 24de9b0c..bf4eb724 100644 --- a/src/API/Kitsu/Model.php +++ b/src/API/Kitsu/Model.php @@ -127,6 +127,7 @@ class Model { */ public function getCharacter(string $slug): array { + // @todo catch non-existent characters and show 404 $data = $this->getRequest('/characters', [ 'query' => [ 'filter' => [ @@ -196,7 +197,9 @@ class Model { { // @TODO catch non-existent anime $baseData = $this->getRawMediaData('anime', $slug); - return $this->animeTransformer->transform($baseData); + $transformed = $this->animeTransformer->transform($baseData); + $transformed['included'] = $baseData['included']; + return $transformed; } /** @@ -659,7 +662,7 @@ class Model { 'slug' => $slug ], 'include' => ($type === 'anime') - ? 'genres,mappings,streamingLinks' + ? 'genres,mappings,streamingLinks,animeCharacters.character' : 'genres,mappings', ] ]; diff --git a/src/Controller/Anime.php b/src/Controller/Anime.php index 6e391a89..5c81a861 100644 --- a/src/Controller/Anime.php +++ b/src/Controller/Anime.php @@ -261,9 +261,19 @@ class Anime extends BaseController { public function details(string $animeId) { $data = $this->model->getAnime($animeId); + $characters = []; + + foreach($data['included'] as $included) + { + if ($included['type'] === 'characters') + { + $characters[$included['id']] = $included['attributes']; + } + } $this->outputHTML('anime/details', [ 'title' => 'Anime · ' . $data['titles'][0], + 'characters' => $characters, 'data' => $data, ]); }