public function ajax_ranking()
 {
     $vdata = getTopPlayers($this->db, 5);
     $this->load->view('/player/ranking', array('players' => $vdata));
 }
Example #2
0
              <table class="table table-hover table-striped table-bordered">
                <!-- TODO: Unit conversions + Plural wording & words. -->
                <thead>
                <tr>
                  <th>Rank</th>
                  <th>Player</th>
                  <th><?php 
    echo getHumanFriendlyStatName($stat);
    ?>
                </tr>
                </thead>

                <tbody>
                <?php 
    $page = 1;
    $result = getTopPlayers($mysqli, $mysql_table_prefix, $stat, $page, $player_on_top);
    $i = 1 * $page;
    if (!$result) {
        echo $mysqli->error;
    }
    $lastVal = 0;
    while (($arr = $result->fetch_array()) != null) {
        echo "<tr>";
        echo "<th>&num;" . $i++ . "</th>";
        $playerName = getPlayerName($mysqli, $mysql_table_prefix, $arr['player_id']);
        echo "<td><img src='" . $avatar_service_uri . $playerName . "/16' " . "class='img-circle avatar-list-icon'> <a href='" . LINKBASE . "players/" . $arr['player_id'] . "' title='" . $playerName . "&apos;s Stats'> " . $playerName . "</a></td>";
        echo "<td>" . translateValue($stat, $arr['value']);
        if ($stat !== 'playtime' && $lastVal !== 0) {
            echo " <i><small>(" . (intval(translateValue($stat, $arr['value'])) - $lastVal) . ")</small></i>";
        }
        echo "</td>";
function getTopPlayers()
{
    $players = array();
    for ($i = 0; $i < 3000; $i = $i + 500) {
        $rankingUrl = "http://a.scrollsguide.com/ranking?start=" . $i . "&limit=500";
        $json = json_decode(file_get_contents($rankingUrl), true);
        // due to rate limit
        sleep(1);
        foreach ($json["data"] as $player) {
            $players[] = new Player($player["name"], $player["rating"]);
        }
    }
    return $players;
}
echo "start: " . date("Y/m/d g:i") . "<br>";
// start
$topPlayers = getTopPlayers();
$ranks = getRanks();
$outputObj = array();
foreach ($topPlayers as $player) {
    $playerInfoUrl = "http://a.scrollsguide.com/player?name=" . $player->getName() . "&fields=name,rankedwon,rank";
    $json = json_decode(file_get_contents($playerInfoUrl), true);
    // due to rate limit
    sleep(1);
    $playerInfo = $json["data"];
    $player->setRankedGamesWon($playerInfo["rankedwon"]);
    $player->setRank($ranks[$playerInfo["rank"]]);
    $outputObj["data"][] = array("name" => $player->getName(), "rating" => $player->getRating(), "rank" => $player->getRank(), "rankedGamesWon" => $player->getRankedGamesWon());
}
file_put_contents("test.json", json_encode($outputObj));
echo "end: " . date("Y/m/d g:i");