Mercurial > hg > fapweb
changeset 511:6fe66ea0e954
Move most of the results code to site module, remove the support for HTML
type output.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Dec 2013 02:16:26 +0200 |
parents | 25bc2087869e |
children | 998a09b332f1 |
files | createdb.php msite.inc.php results.inc.php |
diffstat | 3 files changed, 126 insertions(+), 149 deletions(-) [+] |
line wrap: on
line diff
--- a/createdb.php Sun Dec 08 00:03:58 2013 +0200 +++ b/createdb.php Sun Dec 08 02:16:26 2013 +0200 @@ -28,7 +28,6 @@ "allowVoting" => array(VT_BOOL, false, "Enable voting (individual compos must be enabled as well)"), "showResults" => array(VT_BOOL, false, "Enable results page"), - "showResultsASCII" => array(VT_BOOL, true, "Show results as ASCII instead of HTML table"), "showResAuthors" => array(VT_BOOL, true, "Show entry authors on results page"), "requireEMail" => array(VT_BOOL, false, "Require e-mail address in registrations"),
--- a/msite.inc.php Sun Dec 08 00:03:58 2013 +0200 +++ b/msite.inc.php Sun Dec 08 02:16:26 2013 +0200 @@ -388,6 +388,128 @@ } +function stStrKludge($str) +{ + $tmp = $str; + foreach (array("ä" => "ae", "ö" => "oe", "Ä" => "Ae", "Ö" => "Oe") as $sfrom => $sto) + $tmp = str_replace($sfrom, $sto, $tmp); + + return $tmp; +} + + +function stGetNumberSuffix($val) +{ + switch ($val) + { + case 1: return "st"; + case 2: return "nd"; + case 3: return "rd"; + case 4: case 5: case 6: + case 7: case 8: case 9: return "th"; + default: return "th"; + } +} + + +function stGetCompoResultsASCIIStr($showAuthors) +{ + if (($res = stExecSQL("SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC")) === false) + return ""; + + $voteKeyMode = stGetSetting("voteKeyMode"); + $out = ""; + + // For each compo that has been set visible + foreach ($res as $compo) + { + // 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) + { + // Get voting results by mode + switch ($voteKeyMode) + { + case VOTE_FREELY: + $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"]; + break; + + case VOTE_ACTIVATE: + $sql = + "SELECT entries.*, ". + "(SELECT SUM(votes.value) FROM votes ". + "LEFT JOIN votekeys ON votes.key_id=votekeys.id ". + "WHERE votes.entry_id=entries.id AND votekeys.active<>0) ". + "AS votesum ". + "FROM entries ". + "WHERE entries.compo_id=".$compo["id"]; + break; + + case VOTE_ASSIGN: + $sql = + "SELECT entries.*,SUM(votes.value) AS votesum FROM entries ". + "LEFT JOIN votes ON votes.entry_id=entries.id ". + "LEFT JOIN attendees ON votes.key_id=attendees.key_id ". + "WHERE entries.compo_id=".$compo["id"]." ". + "AND attendees.key_id<>0"; + + $sql = + "SELECT entries.*, ". + "(SELECT SUM(votes.value) FROM votes ". + "LEFT JOIN votekeys ON votes.key_id=votekeys.id ". + "LEFT JOIN attendees ON votekeys.id=attendees.key_id ". + "WHERE votes.entry_id=entries.id AND attendees.key_id<>0) ". + "AS votesum ". + "FROM entries ". + "WHERE entries.compo_id=".$compo["id"]; + break; + } + + $sql .= " ". + "GROUP BY entries.id ". + "ORDER BY votesum DESC"; + + // List results + $prev = FALSE; + $index = 0; + + $out .= + "<pre>\n". + "<b> ".chentities($compo["name"])." </b>\n". + str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n"; + + foreach (stExecSQL($sql) as $entry) + { + if ($entry["votesum"] !== $prev) + { + $index++; + $out .= sprintf("%3d%s.", $index, stGetNumberSuffix($index)); + } + else + $out .= " -''-"; + + $out .= sprintf(" %s by %s (%d pts)\n", + chentities(stStrChop(stStrKludge($entry["name"]), 30)), + chentities(stStrChop($showAuthors ? stStrKludge($entry["author"]) : "-", 30)), + $entry["votesum"]); + + $prev = $entry["votesum"]; + } + $out .= "\n\n</pre>\n"; + } + } + + return $out; +} + + + function stNormalizeListSlideOrder($list_id) { }
--- a/results.inc.php Sun Dec 08 00:03:58 2013 +0200 +++ b/results.inc.php Sun Dec 08 02:16:26 2013 +0200 @@ -4,33 +4,8 @@ // Competition results page // (C) Copyright 2012-2013 Tecnic Software productions (TNSP) // -$useASCII = stGetSetting("showResultsASCII"); $showResults = stGetSetting("showResults"); $showAuthors = stGetSetting("showResAuthors"); -$voteKeyMode = stGetSetting("voteKeyMode"); - - -function stKludge($str) -{ - $tmp = $str; - foreach (array("ä" => "ae", "ö" => "oe", "Ä" => "Ae", "Ö" => "Oe") as $sfrom => $sto) - $tmp = str_replace($sfrom, $sto, $tmp); - - return $tmp; -} - -function stGetNumberSuffix($val) -{ - switch ($val) - { - case 1: return "st"; - case 2: return "nd"; - case 3: return "rd"; - case 4: case 5: case 6: - case 7: case 8: case 9: return "th"; - default: return "th"; - } -} echo "<h1>Results</h1>\n"; @@ -47,130 +22,11 @@ } -if (!$showResults) +if ($showResults) + echo stGetCompoResultsASCIIStr($showAuthors); +else { echo "<p>Sorry, no results available! Nothing to see here, move along.</p>"; } -else -if (($res = stExecSQL("SELECT * FROM compos WHERE visible<>0 ORDER BY name DESC")) !== FALSE) -{ - // For each compo that has been set visible - foreach ($res as $compo) - { - // 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) - { - // Get voting results by mode - switch ($voteKeyMode) - { - case VOTE_FREELY: - $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"]; - break; - - case VOTE_ACTIVATE: - $sql = - "SELECT entries.*, ". - "(SELECT SUM(votes.value) FROM votes ". - "LEFT JOIN votekeys ON votes.key_id=votekeys.id ". - "WHERE votes.entry_id=entries.id AND votekeys.active<>0) ". - "AS votesum ". - "FROM entries ". - "WHERE entries.compo_id=".$compo["id"]; - break; - - case VOTE_ASSIGN: - $sql = - "SELECT entries.*,SUM(votes.value) AS votesum FROM entries ". - "LEFT JOIN votes ON votes.entry_id=entries.id ". - "LEFT JOIN attendees ON votes.key_id=attendees.key_id ". - "WHERE entries.compo_id=".$compo["id"]." ". - "AND attendees.key_id<>0"; - - $sql = - "SELECT entries.*, ". - "(SELECT SUM(votes.value) FROM votes ". - "LEFT JOIN votekeys ON votes.key_id=votekeys.id ". - "LEFT JOIN attendees ON votekeys.id=attendees.key_id ". - "WHERE votes.entry_id=entries.id AND attendees.key_id<>0) ". - "AS votesum ". - "FROM entries ". - "WHERE entries.compo_id=".$compo["id"]; - break; - } - - $sql .= " ". - "GROUP BY entries.id ". - "ORDER BY votesum DESC"; - - // List results - $prev = FALSE; - $index = 0; - - if ($useASCII) - { - echo - "<pre>\n". - "<b> ".chentities($compo["name"])." </b>\n". - str_repeat("=", strlen($compo["name"]) + 2)."-- - .\n\n"; - - foreach (stExecSQL($sql) as $entry) - { - if ($entry["votesum"] !== $prev) - { - $index++; - printf("%3d%s.", $index, stGetNumberSuffix($index)); - } - else - echo " -''-"; - - printf(" %s by %s (%d pts)\n", - chentities(stStrChop(stKludge($entry["name"]), 30)), - chentities(stStrChop($showAuthors ? stKludge($entry["author"]) : "-", 30)), - $entry["votesum"]); - - $prev = $entry["votesum"]; - } - echo "\n\n</pre>\n"; - } - else - { - echo - "<h2>".chentities($compo["name"])."</h2>\n". - "<table class=\"attendees\" style=\"width: 80%;\">\n". - " <tr>\n". - " <th style=\"width: 5%;\">#</th>\n". - " <th>Name</th>\n". - " <th>Author</th>\n". - " <th style=\"width: 3%;\">Points</th>\n". - " </tr>\n"; - - foreach (stExecSQL($sql) as $entry) - { - if ($entry["votesum"] != $prev) - $index++; - - echo - " <tr>". - " <td>".$index."</td>". - " <td>".chentities($entry["name"])."</td>". - " <td>".($showAuthors ? chentities($entry["author"]) : "-")."</td>". - " <td>".$entry["votesum"]."</td>". - " </tr>\n"; - - $prev = $entry["votesum"]; - } - - echo "</table>\n"; - } - } - } -} - + ?> \ No newline at end of file