From e5e4323486c249d9ebc722b1273a993715b71019 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 6 Apr 2017 21:27:03 -0400 Subject: [PATCH] Make sure Cast heading only shows up if there are actual cast entries --- app/views/character.php | 2 +- src/Controller/Character.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/views/character.php b/app/views/character.php index a938a50c..d499f213 100644 --- a/app/views/character.php +++ b/app/views/character.php @@ -72,7 +72,7 @@
- + 0): ?>

Castings

$entries): ?>

diff --git a/src/Controller/Character.php b/src/Controller/Character.php index 8f05563f..25977ade 100644 --- a/src/Controller/Character.php +++ b/src/Controller/Character.php @@ -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 {