Make sure Cast heading only shows up if there are actual cast entries
This commit is contained in:
parent
b210954874
commit
81a1a927b1
@ -72,7 +72,7 @@
|
|||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<?php if (array_key_exists('castings', $data['included'])): ?>
|
<?php if ($castCount > 0): ?>
|
||||||
<h3>Castings</h3>
|
<h3>Castings</h3>
|
||||||
<?php foreach($castings as $role => $entries): ?>
|
<?php foreach($castings as $role => $entries): ?>
|
||||||
<h4><?= $role ?></h4>
|
<h4><?= $role ?></h4>
|
||||||
|
@ -52,17 +52,25 @@ class Character extends BaseController {
|
|||||||
$data[0]['attributes']['name']
|
$data[0]['attributes']['name']
|
||||||
),
|
),
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
|
'castCount' => 0,
|
||||||
'castings' => []
|
'castings' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
if (array_key_exists('included', $data) && array_key_exists('castings', $data['included']))
|
if (array_key_exists('included', $data) && array_key_exists('castings', $data['included']))
|
||||||
{
|
{
|
||||||
$viewData['castings'] = $this->organizeCast($data['included']['castings']);
|
$viewData['castings'] = $this->organizeCast($data['included']['castings']);
|
||||||
|
$viewData['castCount'] = $this->getCastCount($viewData['castings']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->outputHTML('character', $viewData);
|
$this->outputHTML('character', $viewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Organize VA => anime relationships
|
||||||
|
*
|
||||||
|
* @param array $cast
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function dedupeCast(array $cast): array
|
private function dedupeCast(array $cast): array
|
||||||
{
|
{
|
||||||
$output = [];
|
$output = [];
|
||||||
@ -103,6 +111,24 @@ class Character extends BaseController {
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCastCount(array $cast): int
|
||||||
|
{
|
||||||
|
$count = 0;
|
||||||
|
|
||||||
|
foreach($cast as $role)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
array_key_exists('attributes', $role) &&
|
||||||
|
array_key_exists('role', $role['attributes']) &&
|
||||||
|
( ! is_null($role['attributes']['role']))
|
||||||
|
) {
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
private function organizeCast(array $cast): array
|
private function organizeCast(array $cast): array
|
||||||
{
|
{
|
||||||
$cast = $this->dedupeCast($cast);
|
$cast = $this->dedupeCast($cast);
|
||||||
|
Loading…
Reference in New Issue
Block a user