Show characters on anime details page
This commit is contained in:
parent
39e083d17c
commit
0187140e8e
@ -74,7 +74,30 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<?php /*<pre><?= print_r($data, TRUE) ?></pre> */ ?>
|
|
||||||
|
|
||||||
|
<?php /* <pre><?= print_r($characters, TRUE) ?></pre> */ ?>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</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>
|
</main>
|
@ -166,10 +166,13 @@ class JsonAPI {
|
|||||||
$organized[$key] = $organized[$key] ?? [];
|
$organized[$key] = $organized[$key] ?? [];
|
||||||
|
|
||||||
foreach ($data['data'] as $item)
|
foreach ($data['data'] as $item)
|
||||||
|
{
|
||||||
|
if (is_array($item) && array_key_exists('id', $item))
|
||||||
{
|
{
|
||||||
$organized[$key][] = $item['id'];
|
$organized[$key][] = $item['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $organized;
|
return $organized;
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,7 @@ class Model {
|
|||||||
*/
|
*/
|
||||||
public function getCharacter(string $slug): array
|
public function getCharacter(string $slug): array
|
||||||
{
|
{
|
||||||
|
// @todo catch non-existent characters and show 404
|
||||||
$data = $this->getRequest('/characters', [
|
$data = $this->getRequest('/characters', [
|
||||||
'query' => [
|
'query' => [
|
||||||
'filter' => [
|
'filter' => [
|
||||||
@ -196,7 +197,9 @@ class Model {
|
|||||||
{
|
{
|
||||||
// @TODO catch non-existent anime
|
// @TODO catch non-existent anime
|
||||||
$baseData = $this->getRawMediaData('anime', $slug);
|
$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
|
'slug' => $slug
|
||||||
],
|
],
|
||||||
'include' => ($type === 'anime')
|
'include' => ($type === 'anime')
|
||||||
? 'genres,mappings,streamingLinks'
|
? 'genres,mappings,streamingLinks,animeCharacters.character'
|
||||||
: 'genres,mappings',
|
: 'genres,mappings',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
@ -261,9 +261,19 @@ class Anime extends BaseController {
|
|||||||
public function details(string $animeId)
|
public function details(string $animeId)
|
||||||
{
|
{
|
||||||
$data = $this->model->getAnime($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', [
|
$this->outputHTML('anime/details', [
|
||||||
'title' => 'Anime · ' . $data['titles'][0],
|
'title' => 'Anime · ' . $data['titles'][0],
|
||||||
|
'characters' => $characters,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user