Mercurial > hg > fapweb
diff msite.inc.php @ 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 | b6fe46c86ff3 |
children | 998a09b332f1 |
line wrap: on
line diff
--- 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) { }