List characters on manga pages

This commit is contained in:
Timothy Warren 2017-03-24 10:59:07 -04:00
parent cf0db8b9fa
commit be0baac962
5 changed files with 65 additions and 6 deletions

View File

@ -35,4 +35,26 @@
<p><?= nl2br($data['synopsis']) ?></p>
</div>
</section>
<section>
<?php if (count($characters) > 0): ?>
<h2>Characters</h2>
<div class="flex flex-wrap">
<?php foreach($characters as $char): ?>
<?php if ( ! empty($char['image']['original'])): ?>
<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>

View File

@ -257,7 +257,15 @@ class Model {
public function getManga(string $mangaId): array
{
$baseData = $this->getRawMediaData('manga', $mangaId);
return $this->mangaTransformer->transform($baseData);
if (empty($baseData))
{
return [];
}
$transformed = $this->mangaTransformer->transform($baseData);
$transformed['included'] = $baseData['included'];
return $transformed;
}
/**
@ -636,6 +644,12 @@ class Model {
];
$data = $this->getRequest("{$type}/{$id}", $options);
if (empty($data['data']))
{
return [];
}
$baseData = $data['data']['attributes'];
$baseData['included'] = $data['included'];
return $baseData;
@ -657,7 +671,7 @@ class Model {
],
'include' => ($type === 'anime')
? 'genres,mappings,streamingLinks,animeCharacters.character'
: 'genres,mappings',
: 'genres,mappings,mangaCharacters.character,castings.character',
]
];

View File

@ -288,8 +288,11 @@ class Anime extends BaseController {
}
$this->outputHTML('anime/details', [
'title' => $this->config->get('whose_list') . "'s Anime List" .
' &middot; Anime &middot; ' . $data['titles'][0],
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Anime',
$data['titles'][0]
),
'characters' => $characters,
'data' => $data,
]);

View File

@ -30,7 +30,6 @@ class Character extends BaseController {
{
return $this->notFound(
$this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Characters',
'Character not found'
),
@ -40,7 +39,6 @@ class Character extends BaseController {
$this->outputHTML('character', [
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Characters',
$data['data'][0]['attributes']['name']
),

View File

@ -269,6 +269,27 @@ class Manga extends Controller {
public function details($manga_id)
{
$data = $this->model->getManga($manga_id);
$characters = [];
if (empty($data))
{
return $this->notFound(
$this->config->get('whose_list') .
"'s Manga List &middot; Manga &middot; " .
'Manga not found',
'Manga Not Found'
);
}
// dump($data);
foreach($data['included'] as $included)
{
if ($included['type'] === 'characters')
{
$characters[$included['id']] = $included['attributes'];
}
}
$this->outputHTML('manga/details', [
'title' => $this->formatTitle(
@ -276,6 +297,7 @@ class Manga extends Controller {
'Manga',
$data['title']
),
'characters' => $characters,
'data' => $data,
]);
}