Skip to content

Instantly share code, notes, and snippets.

@mcsaban
Created December 5, 2016 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsaban/14373d40a894dd29b38c628713d7908c to your computer and use it in GitHub Desktop.
Save mcsaban/14373d40a894dd29b38c628713d7908c to your computer and use it in GitHub Desktop.
Wot Clan stats on clan's homepage/website
<?php
$clanID = "500006494";
$clanApiPage = "https://api.worldoftanks.eu/wgn/clans/info/?application_id=demo&clan_id=$clanID";
$userApiPage = "https://api.worldoftanks.eu/wot/account/info/?application_id=demo&account_id=";
$getAndDecode = function($url) {
$jsonData = file_get_contents($url);
$dataArray = json_decode($jsonData, true);
return $dataArray;
};
$determineDays = function($date) {
$datediff = time() - $date;
return floor($datediff/(60*60*24));
};
$jsonData = $getAndDecode($clanApiPage);
$clanAccounts = array();
foreach($jsonData["data"][$clanID]["members"] as $memberArray) {
$accountID = $memberArray["account_id"];
$clanAccounts[$accountID]['id'] = $memberArray["account_id"];
$clanAccounts[$accountID]['role'] = $memberArray["role_i18n"];
$clanAccounts[$accountID]['name'] = $memberArray["account_name"];
$clanAccounts[$accountID]['days'] = $determineDays($memberArray["joined_at"]);
}
$accountIDs = implode(",", array_keys($clanAccounts));
$apiPage = $userApiPage . $accountIDs;
$userJsonData = $getAndDecode($apiPage);
foreach($userJsonData["data"] as $userID => $dataArray) {
$playerStatistic = $dataArray["statistics"]["all"];
$clanAccounts[$userID]['rating'] = $dataArray["global_rating"];
$clanAccounts[$userID]['battles'] = $playerStatistic["battles"];
$clanAccounts[$userID]['w_p_b'] = $playerStatistic["wins"]/$playerStatistic["battles"] * 100;//wins per battle
$clanAccounts[$userID]['xp_p_b'] = $playerStatistic["battle_avg_xp"]; //experience per battle
}
$w_p_b = array();
foreach ($clanAccounts as $userID => $row) {
$w_p_b[$userID] = $row['w_p_b'];
}
array_multisort($w_p_b, SORT_DESC, $clanAccounts);
die(json_encode($clanAccounts));
?>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "clan_info.php",
success: function(data){
var htmlString = '<table cellpadding="0px" class="menu1"><tr><th>Username</th><th>Rank</th><th>PR</th><th>BTL</th><th>W/B</th><th>E/B</th><th>Days</th></tr>';
var clanData = JSON.parse(data);
i = 0;
for(userID in clanData){
userData = clanData[userID];
var extraClass = '';
if(i < 3) {
extraClass = 'class="rank' + (i+1) + '"';
}
var username = '<img src="images/' + userData['role'] + '.png" height="25" width="25" />' + userData['name'];
htmlString += '<tr>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + username + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['role'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['rating'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['battles'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['w_p_b'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['xp_p_b'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['days'] + '</a></td>';
htmlString += '</tr>';
i++;
}
htmlString += '</table>';
console.log(htmlString);
$("#wot").html(htmlString);
}
});
});
</script>
.rank1:first-child{
background: url("images/gold.png")no-repeat;
background-size: 15px 13px;
background-position: right;
}
.rank2:first-child{
background: url("images/silver.png")no-repeat;
background-size: 15px 13px;
background-position: right;
}
.rank3:first-child{
background: url("images/bronze.png")no-repeat;
background-size: 15px 13px;
background-position: right;
}
@mcsaban
Copy link
Author

mcsaban commented Dec 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment