Example #1
0
 /**
  * Show static scoreboard
  */
 function static_scoreboard($coders, $md)
 {
     $submissions_total = 0;
     $submissions_correct = 0;
     //No correct participant therefore do nothing
     if (count($coders) == 0) {
         return;
     }
     for ($i = 0; $i < count($coders); $i++) {
         $submissions_total += $coders[$i]['submissions'];
         $submissions_correct += $coders[$i]['correct'];
     }
     //Sort the coders array by time taken where there is a tie if any
     $coders = sort_coders_array($coders);
     $row_class = array('lightblue', 'shadedwhite');
     echo "<div id='scoreboard'>";
     echo "<table border='0' cellpadding='2' cellspacing='1'>";
     for ($i = 0; $i < count($coders); $i++) {
         echo "<tr class='" . $row_class[$i % 2] . "'>";
         //Toggle the class row on each loop
         echo "<td class='position'>" . ($i + 1) . "</td>";
         echo "<td class='nickname'><a target='_blank' href='index.php?a=profile&amp;do=viewProfile&amp;nick_name=" . $coders[$i]['nick_name'] . "'>" . $coders[$i]['nick_name'] . "</a></td>";
         echo "<td class='points'>" . $coders[$i]['points'] . "</td>";
         echo "</tr>";
         if ($i == 12) {
             break;
         }
     }
     echo "</table>";
     echo "<a href='index.php?a=scoreboard&amp;m_tn=" . base64_encode($md['match_table_name']) . "'>full scoreboard</a>";
     echo "<br /><br />";
     echo "<span class='dark1'>Statistics</span><br />";
     echo "<span><b>Submissions total:</b> {$submissions_total}</span><br />";
     echo "<span><b>Correct:</b> {$submissions_correct}/{$submissions_total} (" . number_format($submissions_correct / ($submissions_total == 0 ? 1 : $submissions_total) * 100, 2) . "%)</span>";
     echo "</div>";
 }
 /**
  * Show partial scoreboard for the arena live scoreboard
  */
 function partial_scoreboard()
 {
     //sleep(1);
     $db = $this->db;
     $_pre = $this->_pre;
     $md = $this->md;
     require_once '..' . DS . 'include' . DS . 'utilityFunctions.php';
     $query = "SELECT * FROM " . $_pre . $md['match_table_name'] . " ORDER BY points DESC LIMIT 10";
     $db->setQuery($query);
     //No participant so far therefore do nothing
     if ($db->foundRows == 0) {
         return;
     }
     $submissions_total = 0;
     $submissions_correct = 0;
     $coders = array();
     while ($row = $db->fetch_assoc()) {
         if ($row['correct'] == 1) {
             array_push($coders, $row);
         }
         //Add correct users to the coders array
         $submissions_total += $row['submissions'];
         $submissions_correct += $row['correct'];
     }
     //No correct participant therefore do nothing
     if (count($coders) == 0) {
         return;
     }
     //Sort the coders array by time taken where there is a tie if any
     $coders = sort_coders_array($coders);
     $row_class = array('lightblue', 'shadedwhite');
     echo "<div id='scoreboard'>";
     echo "<table border='0' cellpadding='2' cellspacing='1'>";
     for ($i = 0; $i < count($coders); $i++) {
         echo "<tr class='" . $row_class[$i % 2] . "'>";
         //Toggle the class row on each loop
         echo "<td class='position'>" . ($i + 1) . "</td>";
         echo "<td class='nickname'><a target='_blank' href='index.php?a=profile&amp;do=viewProfile&amp;nick_name=" . $coders[$i]['nick_name'] . "'>" . $coders[$i]['nick_name'] . "</a></td>";
         echo "<td class='points'>" . $coders[$i]['points'] . "</td>";
         echo "</tr>";
         if ($i == 12) {
             break;
         }
     }
     echo "</table>";
     echo "<a href='index.php?a=scoreboard&amp;m_tn=" . base64_encode($md['match_table_name']) . "'>full scoreboard</a>";
     echo "<br /><br />";
     echo "<span class='dark1'>Statistics</span><br />";
     echo "<span><b>Submissions total:</b> {$submissions_total}</span><br />";
     echo "<span><b>Correct:</b> {$submissions_correct}/{$submissions_total} (" . number_format(@($submissions_correct / $submissions_total * 100), 2) . "%)</span>";
     echo "</div>";
 }
Example #3
0
$query = "SELECT * FROM " . $_pre . "matches WHERE (start_time+duration)<" . time() . " ORDER BY id DESC LIMIT 1";
$db->setQuery($query);
if ($db->foundRows > 0) {
    $match_won_details = $db->fetch_assoc();
    $query = "SELECT " . $_pre . $match_won_details['match_table_name'] . ".*," . $_pre . "profile.* FROM " . $_pre . $match_won_details['match_table_name'] . "," . $_pre . "profile WHERE " . $_pre . $match_won_details['match_table_name'] . ".registration_no=" . $_pre . "profile.registration_no ORDER BY points DESC";
    //$query="SELECT * FROM ".$_pre.$match_won_details['match_table_name']." ORDER BY points DESC";
    $db->setQuery($query);
    $coders = array();
    //Initialize coders array: holds the each user details in preparation for sorting to get winner
    if ($db->foundRows > 0) {
        while ($row = $db->fetch_assoc()) {
            array_push($coders, $row);
        }
        if ($coders[0]['points'] != 0) {
            //Has the first coder scored something?
            $coders = sort_coders_array($coders);
            echo "<span class='light10'>Most recent winner</span>";
            echo "<table border='0' cellpadding='2' cellspacing='0'>";
            echo "<tr><td><img id='user_avatar' width='70' src='images/avatars/" . (strlen($coders[0]['avatar_path']) == 0 ? "default.gif" : $coders[0]['avatar_path']) . "' title='{$match_won_details['title']} - Match winner: {$coders[0]['nick_name']} ' />\n\t\t\t\t<p><strong>{$match_won_details['title']}</strong>.<br />Winner: <a class='coder_nickname' href='index.php?a=profile&amp;do=viewProfile&amp;nick_name={$coders[0]['nick_name']}'><span class='" . get_user_class($coders[0]['ranking_pts']) . "'>{$coders[0]['nick_name']}</span></a></p>\n\t\t\t\t</td>\n\t\t\t\t</tr>";
            echo "</table>";
        }
    }
}
?>
		</td>
		</tr>
		</table>
		
		</div>