1
|
|
|
<?php namespace Syntax\SteamApi\Steam\User; |
2
|
|
|
|
3
|
|
|
use Syntax\SteamApi\Client; |
4
|
|
|
use Syntax\SteamApi\Containers\Achievement; |
5
|
|
|
|
6
|
|
|
class Stats extends Client |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
public function __construct($steamId) |
10
|
|
|
{ |
11
|
|
|
parent::__construct(); |
12
|
|
|
$this->interface = 'ISteamUserStats'; |
13
|
|
|
$this->steamId = $steamId; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function GetPlayerAchievements($appId) |
17
|
|
|
{ |
18
|
|
|
// Set up the api details |
19
|
|
|
$this->method = __FUNCTION__; |
20
|
|
|
$this->version = 'v0001'; |
21
|
|
|
|
22
|
|
|
// Set up the arguments |
23
|
|
|
$arguments = [ |
24
|
|
|
'steamid' => $this->steamId, |
25
|
|
|
'appid' => $appId, |
26
|
|
|
'l' => 'english', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
// Get the client |
30
|
|
|
$client = $this->setUpClient($arguments)->playerstats; |
31
|
|
|
|
32
|
|
|
// Clean up the games |
33
|
|
|
$achievements = $this->convertToObjects($client->achievements); |
34
|
|
|
|
35
|
|
|
return $achievements; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function GetGlobalAchievementPercentagesForApp($gameId) |
39
|
|
|
{ |
40
|
|
|
// Set up the api details |
41
|
|
|
$this->method = __FUNCTION__; |
42
|
|
|
$this->version = 'v0002'; |
43
|
|
|
|
44
|
|
|
// Set up the arguments |
45
|
|
|
$arguments = [ |
46
|
|
|
'gameid' => $gameId, |
47
|
|
|
'l' => 'english', |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
// Get the client |
51
|
|
|
$client = $this->setUpClient($arguments)->achievementpercentages; |
52
|
|
|
|
53
|
|
|
return $client->achievements; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param $appId int Steam 64 id |
58
|
|
|
* @param $all bool Return all stats when true and only achievements when false |
59
|
|
|
* |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
|
63
|
|
|
public function GetUserStatsForGame($appId, $all = false) |
64
|
|
|
{ |
65
|
|
|
// Set up the api details |
66
|
|
|
$this->method = __FUNCTION__; |
67
|
|
|
$this->version = 'v0002'; |
68
|
|
|
|
69
|
|
|
// Set up the arguments |
70
|
|
|
$arguments = [ |
71
|
|
|
'steamid' => $this->steamId, |
72
|
|
|
'appid' => $appId, |
73
|
|
|
'l' => 'english', |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
// Get the client |
77
|
|
|
$client = $this->setUpClient($arguments)->playerstats; |
78
|
|
|
|
79
|
|
|
// Games like DOTA and CS:GO have additional stats here. Return everything if they are wanted. |
80
|
|
|
if ($all === true) { |
81
|
|
|
return $client; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $client->achievements; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
protected function convertToObjects($achievements) |
88
|
|
|
{ |
89
|
|
|
$cleanedAchievements = []; |
90
|
|
|
|
91
|
|
|
foreach ($achievements as $achievement) { |
92
|
|
|
$cleanedAchievements[] = new Achievement($achievement); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $cleanedAchievements; |
96
|
|
|
} |
97
|
|
|
} |