Do you wish to register an account?
Browse Source

Make sure Cast heading only shows up if there are actual cast entries

tags/v4.0.0-rc-1
Timothy Warren 3 years ago
parent
commit
e5e4323486
2 changed files with 27 additions and 1 deletions
  1. +1
    -1
      app/views/character.php
  2. +26
    -0
      src/Controller/Character.php

+ 1
- 1
app/views/character.php View File

@@ -72,7 +72,7 @@
<?php endif ?>

<section>
<?php if (array_key_exists('castings', $data['included'])): ?>
<?php if ($castCount > 0): ?>
<h3>Castings</h3>
<?php foreach($castings as $role => $entries): ?>
<h4><?= $role ?></h4>

+ 26
- 0
src/Controller/Character.php View File

@@ -52,17 +52,25 @@ class Character extends BaseController {
$data[0]['attributes']['name']
),
'data' => $data,
'castCount' => 0,
'castings' => []
];

if (array_key_exists('included', $data) && array_key_exists('castings', $data['included']))
{
$viewData['castings'] = $this->organizeCast($data['included']['castings']);
$viewData['castCount'] = $this->getCastCount($viewData['castings']);
}

$this->outputHTML('character', $viewData);
}

/**
* Organize VA => anime relationships
*
* @param array $cast
* @return array
*/
private function dedupeCast(array $cast): array
{
$output = [];
@@ -102,6 +110,24 @@ class Character extends BaseController {

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
{

Loading…
Cancel
Save