コード例 #1
0
<?php

require_once "./ClashAPI/API.class.php";
$foxforce = new CoC_Clan("#22UCCU0J");
echo "<img src=\"" . $foxforce->getBadgeUrl("small") . "\" /><h1 style='display:inline'>" . $foxforce->getName() . "</h1> " . $foxforce->getTag() . " - Level: " . $foxforce->getLevel() . "<br/>";
echo "<table><tr><th>#</th><th>Name</th><th>Rank</th><th>Trophies</th><th>Donations</th><th>Donations Received</th><th>Donation Ratio</th></tr>";
foreach ($foxforce->getAllMembers() as $clanmember) {
    $member = new CoC_Member($clanmember);
    $donationsReceivedCalc = $member->getDonationsReceived();
    if ($donationsReceivedCalc == 0) {
        $donationsReceivedCalc++;
    }
    $ratio = $member->getDonations() / $donationsReceivedCalc;
    echo "<tr><td>" . $member->getClanRank() . "</td><td>" . $member->getName() . "</td><td>" . $member->getRole() . "</td><td>" . $member->getTrophies() . "</td><td>" . $member->getDonations() . "</td><td>" . $member->getDonationsReceived() . "</td><td>Donation-Ratio: " . number_format($ratio, 2) . "</td></tr>";
}
?>
</table>
<br/>
Donation Ratio = donations made / donations received (if received = 0, use 1 instead to prevent errors)<br/>
admin = elder
コード例 #2
0
ファイル: callapi.php プロジェクト: rasms/theblackwar
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/ClashAPI/API.class.php';
date_default_timezone_set('Europe/Berlin');
$redis = new Predis\Client(getenv('REDIS_URL'));
if ($redis->exists('timer')) {
    echo 'Just wait another hour...';
} else {
    $timestamp = date("d.m.Y - H:i");
    $clan = new CoC_Clan("#QVQRYYG");
    $tottroph = 0;
    $totlvl = 0;
    foreach ($clan->getAllMembers() as $clanmember) {
        $member = new CoC_Member($clanmember);
        $league = new CoC_League($member->getLeague());
        $donationsReceivedCalc = $member->getDonationsReceived();
        if ($donationsReceivedCalc == 0) {
            $donationsReceivedCalc++;
        }
        $ratio = $member->getDonations() / $donationsReceivedCalc;
        $tottroph = $tottroph + $member->getTrophies();
        $totlvl = $totlvl + $member->getLevel();
        $clanmem[$member->getClanRank()] = ["rank" => $member->getClanRank(), "prevrank" => $member->getPreviousClanRank(), "name" => $member->getName(), "role" => $member->getRole(), "trophies" => $member->getTrophies(), "donations" => $member->getDonations(), "received" => $member->getDonationsReceived(), "ratio" => number_format($ratio, 2), "level" => $member->getLevel(), "leaguename" => $league->getLeagueName(), "leagueid" => $league->getLeagueId(), "leagueicontn" => $league->getLeagueIcon("tiny"), "leagueiconsm" => $league->getLeagueIcon("small"), "leagueiconmd" => $league->getLeagueIcon("medium")];
    }
    $avgtroph = round($tottroph / $clan->getMemberCount(), 0);
    $avglvl = round($totlvl / $clan->getMemberCount(), 0);
    $clandetails = ["badgesm" => $clan->getBadgeUrl("small"), "badgemd" => $clan->getBadgeUrl("medium"), "badgelg" => $clan->getBadgeUrl("large"), "name" => $clan->getName(), "level" => $clan->getLevel(), "description" => $clan->getDescription(), "wins" => $clan->getWarWins(), "ties" => $clan->getWarTies(), "losses" => $clan->getWarLosses(), "streak" => $clan->getWarWinStreak(), "points" => $clan->getPoints(), "freq" => $clan->getWarFrequency(), "membercount" => $clan->getMemberCount(), "avgtroph" => $avgtroph, "avglvl" => $avglvl, "timestamp" => $timestamp];
    $redis->set('clandetails', serialize($clandetails));
    $redis->set('clanmem', serialize($clanmem));
    $redis->setEx('timer', 5400, '');
}