Show characters on anime details page
This commit is contained in:
parent
0d4b26e493
commit
bc6854a8e5
@ -74,7 +74,30 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif ?>
|
||||
<?php /*<pre><?= print_r($data, TRUE) ?></pre> */ ?>
|
||||
|
||||
|
||||
<?php /* <pre><?= print_r($characters, TRUE) ?></pre> */ ?>
|
||||
</div>
|
||||
</section>
|
||||
<section>
|
||||
<?php if (count($characters) > 0): ?>
|
||||
<h2>Characters</h2>
|
||||
<div class="flex flex-wrap">
|
||||
<?php foreach($characters as $char): ?>
|
||||
<?php if (array_key_exists('image', $char)): ?>
|
||||
<div class="character">
|
||||
<?php $link = $url->generate('character', ['slug' => $char['slug']]) ?>
|
||||
<?= $helper->a($link, $char['name']); ?>
|
||||
<br />
|
||||
<a href="<?= $link ?>">
|
||||
<?= $helper->img($char['image']['original'], [
|
||||
'width' => '225'
|
||||
]) ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</section>
|
||||
</main>
|
@ -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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
]
|
||||
];
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user