Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
4 changed files with 43 additions and 4 deletions
Showing only changes of commit 0187140e8e - Show all commits

View File

@ -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>

View File

@ -167,7 +167,10 @@ class JsonAPI {
foreach ($data['data'] as $item) foreach ($data['data'] as $item)
{ {
$organized[$key][] = $item['id']; if (is_array($item) && array_key_exists('id', $item))
{
$organized[$key][] = $item['id'];
}
} }
} }

View File

@ -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',
] ]
]; ];

View File

@ -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 &middot ' . $data['titles'][0], 'title' => 'Anime &middot ' . $data['titles'][0],
'characters' => $characters,
'data' => $data, 'data' => $data,
]); ]);
} }