1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Syntax\SteamApi\Steam\User; |
4
|
|
|
|
5
|
|
|
use Syntax\SteamApi\Client; |
6
|
|
|
use Syntax\SteamApi\Containers\Achievement; |
7
|
|
|
|
8
|
|
|
class Stats extends Client |
9
|
|
|
{ |
10
|
4 |
|
public function __construct($steamId) |
11
|
|
|
{ |
12
|
4 |
|
parent::__construct(); |
13
|
4 |
|
$this->interface = 'ISteamUserStats'; |
14
|
4 |
|
$this->steamId = $steamId; |
15
|
4 |
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @deprecated |
19
|
|
|
* |
20
|
|
|
* @param $appId |
21
|
|
|
* |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
|
public function GetPlayerAchievementsAPI($appId) |
25
|
|
|
{ |
26
|
|
|
// Set up the api details |
27
|
|
|
$this->method = 'GetPlayerAchievementsAPI'; |
28
|
|
|
$this->version = 'v0001'; |
29
|
|
|
|
30
|
|
|
// Set up the arguments |
31
|
|
|
$arguments = [ |
32
|
|
|
'steamid' => $this->steamId, |
33
|
|
|
'appid' => $appId, |
34
|
|
|
'l' => 'english', |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
// Get the client |
38
|
|
|
$stats = $this->GetSchemaForGame($appId); |
39
|
|
|
|
40
|
|
|
// Make sure the game has achievements |
41
|
|
|
if ($stats == null || $stats->game->availableGameStats->achievements == null) { |
42
|
|
|
return null; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$client = $this->setUpClient($arguments)->playerstats; |
46
|
|
|
$stats = $stats->game->availableGameStats->achievements; |
47
|
|
|
|
48
|
|
|
// Clean up the games |
49
|
|
|
$achievements = $this->convertToObjects($client->achievements, $stats); |
|
|
|
|
50
|
|
|
|
51
|
|
|
return $achievements; |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
public function GetPlayerAchievements($appId) |
55
|
|
|
{ |
56
|
|
|
// Set up the api details |
57
|
2 |
|
$this->interface = null; |
58
|
2 |
|
$this->method = 'achievements'; |
59
|
|
|
|
60
|
2 |
|
if (is_numeric($this->steamId)) { |
61
|
2 |
|
$this->url = 'http://steamcommunity.com/profiles/'; |
62
|
|
|
} else { |
63
|
|
|
$this->url = 'http://steamcommunity.com/id/'; |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
$this->url = $this->url . $this->steamId . '/stats/' . $appId; |
67
|
|
|
|
68
|
|
|
// Set up the arguments |
69
|
|
|
$arguments = [ |
70
|
2 |
|
'xml' => 1, |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
try { |
74
|
|
|
// Get the client |
75
|
2 |
|
$client = $this->setUpXml($arguments); |
76
|
|
|
|
77
|
|
|
// Clean up the games |
78
|
1 |
|
$achievements = $this->convertToObjects($client->achievements->achievement); |
79
|
|
|
|
80
|
1 |
|
return $achievements; |
81
|
1 |
|
} catch (\Exception $e) { |
82
|
|
|
// In rare cases, games can force the use of a simplified name instead of an app ID |
83
|
|
|
// In these cases, try again by grabbing the redirected url. |
84
|
1 |
|
if (is_int($appId)) { |
85
|
1 |
|
$this->getRedirectUrl(); |
86
|
|
|
|
87
|
|
|
try { |
88
|
|
|
// Get the client |
89
|
1 |
|
$client = $this->setUpXml($arguments); |
90
|
|
|
|
91
|
|
|
// Clean up the games |
92
|
|
|
$achievements = $this->convertToObjects($client->achievements->achievement); |
93
|
|
|
|
94
|
|
|
return $achievements; |
95
|
1 |
|
} catch (\Exception $exception) { |
96
|
1 |
|
return null; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// If the name and ID fail, return null. |
101
|
|
|
return null; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
public function GetGlobalAchievementPercentagesForApp($gameId) |
106
|
|
|
{ |
107
|
|
|
// Set up the api details |
108
|
1 |
|
$this->method = __FUNCTION__; |
109
|
1 |
|
$this->version = 'v0002'; |
110
|
|
|
|
111
|
|
|
// Set up the arguments |
112
|
|
|
$arguments = [ |
113
|
1 |
|
'gameid' => $gameId, |
114
|
1 |
|
'l' => 'english', |
115
|
|
|
]; |
116
|
|
|
|
117
|
|
|
// Get the client |
118
|
1 |
|
$client = $this->setUpClient($arguments)->achievementpercentages; |
119
|
|
|
|
120
|
1 |
|
return $client->achievements; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param $appId int Steam 64 id |
125
|
|
|
* @param $all bool Return all stats when true and only achievements when false |
126
|
|
|
* |
127
|
|
|
* @return mixed |
128
|
|
|
*/ |
129
|
|
|
public function GetUserStatsForGame($appId, $all = false) |
130
|
|
|
{ |
131
|
|
|
// Set up the api details |
132
|
|
|
$this->method = __FUNCTION__; |
133
|
|
|
$this->version = 'v0002'; |
134
|
|
|
|
135
|
|
|
// Set up the arguments |
136
|
|
|
$arguments = [ |
137
|
|
|
'steamid' => $this->steamId, |
138
|
|
|
'appid' => $appId, |
139
|
|
|
'l' => 'english', |
140
|
|
|
]; |
141
|
|
|
|
142
|
|
|
// Get the client |
143
|
|
|
$client = $this->setUpClient($arguments)->playerstats; |
144
|
|
|
|
145
|
|
|
// Games like DOTA and CS:GO have additional stats here. Return everything if they are wanted. |
146
|
|
|
if ($all === true) { |
147
|
|
|
return $client; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
return $client->achievements; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param $appId |
155
|
|
|
* |
156
|
|
|
* @link https://wiki.teamfortress.com/wiki/WebAPI/GetSchemaForGame |
157
|
|
|
* |
158
|
|
|
* @return mixed |
159
|
|
|
*/ |
160
|
1 |
|
public function GetSchemaForGame($appId) |
161
|
|
|
{ |
162
|
|
|
// Set up the api details |
163
|
1 |
|
$this->method = __FUNCTION__; |
164
|
1 |
|
$this->version = 'v0002'; |
165
|
|
|
|
166
|
|
|
// Set up the arguments |
167
|
|
|
$arguments = [ |
168
|
1 |
|
'appid' => $appId, |
169
|
1 |
|
'l' => 'english', |
170
|
|
|
]; |
171
|
|
|
|
172
|
|
|
// Get the client |
173
|
1 |
|
$client = $this->setUpClient($arguments); |
174
|
|
|
|
175
|
1 |
|
return $client; |
176
|
|
|
} |
177
|
|
|
|
178
|
1 |
|
protected function convertToObjects($achievements) |
179
|
|
|
{ |
180
|
1 |
|
$cleanedAchievements = []; |
181
|
|
|
|
182
|
1 |
|
foreach ($achievements as $achievement) { |
183
|
1 |
|
$cleanedAchievements[] = new Achievement($achievement); |
184
|
|
|
} |
185
|
|
|
|
186
|
1 |
|
return $cleanedAchievements; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.