-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.php
140 lines (106 loc) · 3.74 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<meta enctype="utf-8">
<title>BF3Stats API Class - Examples</title>
</head>
<body>
<h1>BF3Stats API Class - Examples</h1>
<p>Please check the source of this file for more information</p>
<p> </p>
<?php
require_once('bf3stats.class.php');
$api = new BF3StatsAPI();
// set a time correction in seconds in case your server time and the API server time are different (required for signed requests)
// $api->setTimeCorrection( 0 );
// enable, disable or specify the caching type. (not fully implemented yet)
// $api->setCache( 'files' );
// set the date format based on strftime <http://www.php.net/manual/en/function.strftime.php>
// $api->setDateFormat( '%d-%m-%Y' );
// set the time format. Currently only 'battlelog'
// $api->setTimeFormat( 'battlelog' );
// set the relative path to the images (rank images, ribbons, medals, etc). Images can be downloaded here <http://bf3stats.com/bf3stats.com_images.zip>
// $api->setImagePath( 'bf3' );
// set the relative path where the cache files should be placed. Make sure it has READ and WRITE rights (chmod 665 should be enough, chmod 777 will always work)
// $api->setCachePath( '_cache' );
?>
<h2>$api->player</h2>
<?php
/** / // remove space after second * to activate
// get a single player
$data = $api->player('Grezvany13', 'pc', array('clear', 'assignments'));
print '<pre>';
var_dump($data->stats);
print '<pre>';
/**/
?>
<?php
/*
He loops over all the possible unlocks (or service stars or medals),
takes the number which needs te be acquired (eg. 100 kills),
takes that number which you have and calculates the difference.
This new number is divided by the number which is required
and you've got the order (when sorting from low to high) which unlock will be first.
And now the best part: at the statistics page the order is defined by the amount of time!
This is calculated by taking the the result from before
and by calculating the same type per minute (eg. total kills per minute) for that item (eg. weapon).
* /
$tmp = array();
// example only shows 1 weapon, but you should loop over all!
$aek = $data->stats->weapons->arAEK;
foreach( $aek->unlocks as $unlock ):
// unlock not yet taken
if( $unlock->curr !== $unlock->needed ):
// take number you needed (here: kills needed till recieving this unlock)
$need = ($unlock->needed - $unlock->curr);
// get the type (here: kills)
$type = strtolower($unlock->nname);
// check if this value exists, since the "DICE unlocks" don't have it ;)
if( !isset($aek->{$type}) ):
continue;
endif;
// take the number from this type (here: amount of kills)
$num = $aek->{$type};
// get the time you used this weapon
$time = $aek->time;
// calculate the number per time (here: kills per minute)
$npt = ( $time / $num );
// calculate the amount of time needed for this unlock (here: kills per minute multiplied by the amount of kills needed)
$time_needed = $npt * $need;
// make the time readable
$real_time_needed = $data->_niceTime($time_needed);
// put it in an array, where the time needed is the key
$tmp[$time_needed] = array(
'name' => $unlock->name,
'time' => $real_time_needed
);
endif;
endforeach;
// sort all unlocks by the key (= time)
ksort($tmp);
// loop over the array and show the next unlocks
var_dump($tmp);
/**/
?>
<h2>$api->playerlist</h2>
<?php
/**/ // remove space after second * to activate
// get a list of players
$data = $api->playerlist(array('Grezvany13', 'ZA-Tony'), 'pc', array('clear','global'));
print '<pre>';
var_dump($data);
print '<pre>';
/**/
?>
<h2>$api->onlinestats</h2>
<?php
/** / // remove space after second * to activate
// get a list of players
$data = $api->onlinestats();
print '<pre>';
var_dump($data);
print '<pre>';
/**/
?>
</body>
</html>