changeset 167:1e16a71323de

Some work on results display.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 27 Oct 2013 05:32:05 +0200
parents c73217c35864
children 40a4a2d3d039
files results.inc.php
diffstat 1 files changed, 41 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/results.inc.php	Sun Oct 27 04:22:29 2013 +0200
+++ b/results.inc.php	Sun Oct 27 05:32:05 2013 +0200
@@ -43,93 +43,88 @@
 else
 if (($res = stExecSQL("SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC")) !== FALSE)
 {
-  if ($useASCII) echo "<pre>\n";
+  // For each compo that has been set visible
   foreach ($res as $compo)
   {
-    $sqlConds = $sqlJoins = "";
-    switch (stGetSetting("voteKeyMode"))
+    // Check if there are any entries for it
+    $sql =
+      "SELECT COUNT(*) FROM entries ".
+      "WHERE compo_id=".$compo["id"];
+
+    if (($nentries = stFetchSQLColumn($sql)) !== FALSE && $nentries > 0)
     {
-      case VOTE_FREELY:
-        break;
-      
-      case VOTE_ACTIVATE:
-        $sqlConds = "AND votekeys.active<>0 ";
-        break;
-      
-      case VOTE_ASSIGN:
-        $sqlJoins = "LEFT JOIN attendees ON votekeys.voter_id=attendees.id ";
-        break;
-    }
+      // Get voting results
+      $sql =
+        "SELECT entries.*,SUM(votes.value) AS votesum FROM entries ".
+        "LEFT JOIN votes ON votes.entry_id=entries.id ".
+        "WHERE entries.compo_id=".$compo["id"]." ".
+        "GROUP BY entries.id ".
+        "ORDER BY votesum DESC";
 
-    $sql =
-      "SELECT entries.*,SUM(votes.value) AS votesum ".
-      "FROM entries ".
-      "LEFT JOIN votes ON entries.id=votes.entry_id ".
-      "LEFT JOIN votekeys ON votekeys.id=votes.voter_id ".
-      $sqlJoins.
-      "WHERE entries.compo_id=".$compo["id"]." ".
-      $sqlConds.
-      "GROUP BY votes.entry_id ".
-      "ORDER BY votesum DESC";
+      $entries = stExecSQL($sql);
 
-    if (($fres = stExecSQL($sql)) !== FALSE)
-    {
       if ($useASCII)
       {
-        echo "<b> ".$compo["name"]." </b>\n";
-        echo str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
+        echo
+          "<pre>\n".
+          "<b> ".chentities($compo["name"])." </b>\n".
+          str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n";
 
-        $index = 0;
-        $prev = FALSE;
-        foreach ($fres as $entry)
+        foreach ($entries as $entry)
         {
-          if ($entry["votesum"] != $prev || $index == 0)
+          $index = 0;
+          $prev = FALSE;
+          
+          if ($entry["votesum"] != $prev)
           {
             $index++;
-            printf("%3d.", $index);
+            printf("%3d%s.", $index, stGetNumberSuffix($index));
           }
           else
             echo "    ";
-          $prev = $entry["votesum"];
 
           printf("  %s  by  %s (%d pts)\n",
             chentities(stStrChop($entry["name"], 30)),
             chentities(stStrChop($showAuthors ? $entry["author"] : "-", 30)),
             $entry["votesum"]);
 
+          $prev = $entry["votesum"];
         }
-        echo "\n\n";
+        echo "\n\n</pre>\n";
       }
       else
       {
-        echo "<h2>".$compo["name"]."</h2>\n".
-        "<table class=\"attendees\" style=\"width: 80%;\">\n".
-        " <tr>\n".
-        "  <th style=\"width: 1%;\">#</th>\n".
-        "  <th style=\"width: 3%;\">Points</th>\n".
-        "  <th>Name</th>\n".
-        "  <th>Author</th>\n".
-        " </tr>\n";
+        echo
+          "<h2>".chentities($compo["name"])."</h2>\n".
+          "<table class=\"attendees\" style=\"width: 80%;\">\n".
+          " <tr>\n".
+          "  <th style=\"width: 1%;\">#</th>\n".
+          "  <th style=\"width: 3%;\">Points</th>\n".
+          "  <th>Name</th>\n".
+          "  <th>Author</th>\n".
+          " </tr>\n";
 
         $index = 0;
         foreach ($fres as $entry)
         {
           if ($entry["votesum"] != $prev)
             $index++;
-          $prev = $entry["votesum"];
+
           echo
             "<tr>".
-            "<td>#".$index."</td>".
+            "<td>".$index."</td>".
             "<td>".$entry["votesum"]."</td>".
             "<td>".chentities($entry["name"])."</td>".
             "<td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>".
             "</tr>\n";
+
+          $prev = $entry["votesum"];
         }
 
         echo "</table>\n";
       }
     }
   }
-  if ($useASCII) echo "</pre>\n";
 }
+
 ?>
\ No newline at end of file