Don't show media tabs with no media on character page, make stats on user page more resiliant

This commit is contained in:
Timothy Warren 2018-12-07 10:22:16 -05:00
parent b871a4fac2
commit a38c9712e6
2 changed files with 34 additions and 15 deletions

View File

@ -27,10 +27,10 @@ use Aviat\AnimeClient\API\Kitsu;
</div>
</section>
<?php if (array_key_exists('anime', $data['media']) || array_key_exists('manga', $data['media'])): ?>
<?php if ( ! (empty($data['media']['anime']) || empty($data['media']['manga']))): ?>
<h3>Media</h3>
<div class="tabs">
<?php if (array_key_exists('anime', $data['media'])): ?>
<?php if ( ! empty($data['media']['anime'])): ?>
<input checked="checked" type="radio" id="media-anime" name="media-tabs" />
<label for="media-anime">Anime</label>
@ -58,7 +58,7 @@ use Aviat\AnimeClient\API\Kitsu;
</section>
<?php endif ?>
<?php if (array_key_exists('manga', $data['media'])): ?>
<?php if ( ! empty($data['media']['manga'])): ?>
<input type="radio" id="media-manga" name="media-tabs" />
<label for="media-manga">Manga</label>

View File

@ -131,19 +131,38 @@ final class UserTransformer extends AbstractTransformer {
return $output;
}
private function organizeStats($stats, $data): array
private function organizeStats($stats, $data = []): array
{
// $timeOnAnime = $this->formatAnimeTime($orgData['attributes']['lifeSpentOnAnime']);
$animeStats = [];
$mangaStats = [];
$otherStats = [];
return [
if (array_key_exists('anime-amount-consumed', $stats))
{
$animeStats = [
'Time spent watching anime:' => $this->formatAnimeTime($stats['anime-amount-consumed']['time']),
'Anime series watched:' => number_format($stats['anime-amount-consumed']['media']),
'Anime episodes watched:' => number_format($stats['anime-amount-consumed']['units']),
];
}
if (array_key_exists('manga-amount-consumed', $stats))
{
$mangaStats = [
'Manga series read:' => number_format($stats['manga-amount-consumed']['media']),
'Manga chapters read:' => number_format($stats['manga-amount-consumed']['units']),
];
}
if ( ! empty($data))
{
$otherStats = [
'Posts:' => number_format($data['postsCount']),
'Comments:' => number_format($data['commentsCount']),
'Media Rated:' => number_format($data['ratingsCount']),
];
}
return array_merge($animeStats, $mangaStats, $otherStats);
}
}