From 25aac7357c77ed73d2d06d3952d318668fba777b Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Thu, 16 Jun 2016 08:16:24 -0400 Subject: [PATCH] Hide entry key if there are no prizes and only one entry shown per competitor. --- lib/race.php | 96 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/lib/race.php b/lib/race.php index 357152a..bdfd743 100644 --- a/lib/race.php +++ b/lib/race.php @@ -248,9 +248,12 @@ foreach ($race->getPrizeKeys() as $p) { $keys[$p] = ucfirst($race->PrizeDescription($p)); } - $rows = array(); - $rows['orange'] = count($keys) ? "Competitor's best non-prizewinning entry" : "Competitor's best entry"; - if (! $one_entry) $rows['blue'] = "Competitor's other entries"; + $show_highlight_key = (! $one_entry || count($keys)); + if ($show_highlight_key) { + $rows = array(); + $rows['orange'] = count($keys) ? "Competitor's best non-prizewinning entry" : "Competitor's best entry"; + if (! $one_entry) $rows['blue'] = "Competitor's other entries"; + } $endorsements = Entry::EndorsementKeys(); asort($endorsements); @@ -259,20 +262,22 @@ echo "\n"; echo "\n"; - echo "\n"; + if ($show_highlight_key) echo "\n"; echo "\n"; echo "\n"; echo "\n"; - echo "\n"; echo "
Highlight keyHighlight keyEndorsement key
\n"; - echo "\n"; - foreach ($keys as $key => $description) { - echo "\n"; - } - foreach ($rows as $key => $description) { - echo "\n"; + if ($show_highlight_key) { + echo "\n"; } - echo "
$description
$description
\n"; + echo "\n"; + foreach ($keys as $key => $description) { + echo "\n"; + } + foreach ($rows as $key => $description) { + echo "\n"; + } + echo "
$description
$description
\n"; + echo "
\n"; - echo "
\n"; echo "\n"; foreach ($endorsements as $e) { @@ -290,32 +295,36 @@ echo "[table]\n"; echo "[tr]"; - echo "[td]"; - echo "[b]Highlight key[/b]"; - echo "[/td]"; + if ($show_highlight_key) { + echo "[td]"; + echo "[b]Highlight key[/b]"; + echo "[/td]"; + } echo "[td]"; echo "[b]Endorsement key[/b]"; echo "[/td]"; echo "[/tr]\n"; echo "[tr]\n"; - echo "[td]\n"; - echo "[table]\n"; - foreach ($keys as $key => $description) { - echo "[tr]"; - echo "[td=\"bgcolor: " . colour($key)[0] . "\"][color=" . entry_fgcolor(0, 0, 1, 1) . "]"; - echo $description; - echo "[/color][/td]"; - echo "[/tr]\n"; - } - foreach ($rows as $key => $description) { - echo "[tr]"; - echo "[td=\"bgcolor: " . entry_bgcolor(1, 0) . "\"][color=" . colour($key)[1] . "]"; - echo $description; - echo "[/color][/td]"; - echo "[/tr]\n"; + if ($show_highlight_key) { + echo "[td]\n"; + echo "[table]\n"; + foreach ($keys as $key => $description) { + echo "[tr]"; + echo "[td=\"bgcolor: " . colour($key)[0] . "\"][color=" . entry_fgcolor(0, 0, 1, 1) . "]"; + echo $description; + echo "[/color][/td]"; + echo "[/tr]\n"; + } + foreach ($rows as $key => $description) { + echo "[tr]"; + echo "[td=\"bgcolor: " . entry_bgcolor(1, 0) . "\"][color=" . colour($key)[1] . "]"; + echo $description; + echo "[/color][/td]"; + echo "[/tr]\n"; + } + echo "[/table]\n"; + echo "[/td]\n"; } - echo "[/table]\n"; - echo "[/td]\n"; echo "[td]\n"; echo "[table]\n"; foreach ($endorsements as $e) { @@ -995,7 +1004,8 @@ } if ($prize_name || ! $prize_entry) { /* One entry per racer per ship. */ - if (filtered("ships", $format, $formats) && $competitor_hull_entries[$name][$hull_id]++) continue; + if (filtered("ships", $format, $formats) && $competitor_hull_entries[$name][$hull_id]) continue; + $competitor_hull_entries[$name][$hull_id]++; if (array_key_exists($name, $competitor_entries)) { /* One entry per competitor. */ @@ -1011,7 +1021,8 @@ else { /* Racer has a prize but this isn't it. */ /* One entry per racer per ship. */ - if (filtered("ships", $format, $formats) && $competitor_hull_entries[$name][$hull_id]++) continue; + if (filtered("ships", $format, $formats) && $competitor_hull_entries[$name][$hull_id]) continue; + $competitor_hull_entries[$name][$hull_id]++; /* One entry per racer. */ /* XXX what if in both excluded_competitors */ if ((array_key_exists($name, $excluded_competitors) || array_key_exists($name, $competitor_entries)) && filtered("competitors", $format, $formats)) continue; @@ -1030,7 +1041,8 @@ /* Excluded. */ if (filtered("ranked", $format, $formats)) continue; /* One entry per racer per ship. */ - if ($competitor_hull_entries[$name][$hull_id]++ && filtered("ships", $format, $formats)) continue; + if (filtered("ships", $format, $formats) && $competitor_hull_entries[$name][$hull_id]) continue; + $competitor_hull_entries[$name][$hull_id]++; /* One entry per racer. */ if ((array_key_exists($name, $excluded_competitors) || array_key_exists($name, $competitor_entries)) && filtered("competitors", $format, $formats)) continue; $r = (array_key_exists($name, $excluded_competitors)) ? 2 : 1; @@ -1043,7 +1055,17 @@ show_entry($sort, $format, $entry, $allotted_time, null, $race->getPrizes(), $p, $r, $s, $n++, $type, $prize_name, count($blue_fields), count($white_fields)); if ($filter) $filtered_entries[] = $entry; } - entry_footer($race, $type, filtered("competitors", $format, $formats)); + $one_entry = true; + if (! filtered("competitors", $format, $formats)) { + foreach (array_values($competitor_hull_entries) as $hull_entries) { + if (count($hull_entries) == 1) { + if (array_values($hull_entries)[0] == 1) continue; + } + $one_entry = false; + break; + } + } + entry_footer($race, $type, $one_entry); echo "\n"; } echo "\n"; -- 2.7.4