changeset 23:e6ffab8414cc

Improve display of results.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 06 Dec 2012 23:08:46 +0200
parents f2877f1b0b75
children 5bc8bd5c7ecc
files results.inc.php
diffstat 1 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/results.inc.php	Thu Dec 06 21:28:17 2012 +0200
+++ b/results.inc.php	Thu Dec 06 23:08:46 2012 +0200
@@ -3,6 +3,16 @@
 $showResults = stGetSetting("showResults");
 $showAuthors = stGetSetting("showResAuthors");
 
+function stChop($str, $len)
+{
+  if (strlen($str) > $len)
+    $s = substr($str, 0, $len - 3)."...";
+  else
+    $s = $str;
+  return sprintf("%-".$len."s", $s);
+}
+
+
 echo "<h1>Results</h1>\n";
 if (!$showResults)
 {
@@ -29,15 +39,24 @@
           echo "<b> ".$compo["name"]." </b>\n";
           echo str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
 
-          $index = 1;
+          $index = 0;
+          $prev = FALSE;
           foreach ($fres as $entry)
           {
-            printf("%3s.  %s  by  %s (%d pts)\n",
-              $index,
-              chentities(sprintf("%-35s", $entry["name"])),
-              chentities(sprintf("%-25s", $showAuthors ? $entry["author"] : "-")),
+            if ($entry["votesum"] != $prev)
+            {
+              $index++;
+              printf("%3d.", $index);
+            }
+            else
+              echo "    ";
+            $prev = $entry["votesum"];
+
+            printf("  %s  by  %s (%d pts)\n",
+              chentities(stChop($entry["name"], 30)),
+              chentities(stChop($showAuthors ? $entry["author"] : "-", 30)),
               $entry["votesum"]);
-            $index++;
+
           }
           echo "\n\n";
         }
@@ -52,9 +71,12 @@
           "  <th>Author</th>\n".
           " </tr>\n";
 
-          $index = 1;
+          $index = 0;
           foreach ($fres as $entry)
           {
+            if ($entry["votesum"] != $prev)
+              $index++;
+            $prev = $entry["votesum"];
             echo
               "<tr>".
               "<td>#".$index."</td>".
@@ -62,7 +84,6 @@
               "<td>".chentities($entry["name"])."</td>".
               "<td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>".
               "</tr>\n";
-            $index++;
           }
 
           echo "</table>\n";