-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.php
More file actions
72 lines (58 loc) · 2.25 KB
/
Copy pathApp.php
File metadata and controls
72 lines (58 loc) · 2.25 KB
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
<?php
class App
{
private $appId;
/**
* App constructor.
* @param $appId
*/
public function __construct($appId)
{
$this->appId = $appId;
}
/**
* @return int $appId
*/
public function getAppId()
{
return $this->appId;
}
/**
* Function that calculates the total percentage of completed achievements.
* @param $steamId
* @param $dB
* @return float $gameCompletionPercent
*/
public function setAchievements($steamId, $dB)
{
$appId = $this->getAppId();
$achievementURL = 'http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=' . $appId . '&key=1DE926993382D94F844F42DD076A24BB&steamid=' . $steamId;
$achievementData = curl_connect($achievementURL);
$achievementOut = json_decode($achievementData);
$achievementCount = 0;
$hasAchieved = 0;
foreach ($achievementOut->playerstats as $categories) {
foreach ($categories as $achievements) {
$apiname = $achievements->apiname;
$achieved = $achievements->achieved;
$achievementCount++;
if ($achieved == 1) {
$boolAchieved = true;
$hasAchieved++;
} else {
$boolAchieved = false;
}
$achResult = mysqli_query($dB, "INSERT INTO achievement(apiname)
VALUES ('$apiname')");
$achId = mysqli_query($dB, "SELECT achievement_id FROM achievement
WHERE apiname LIKE '%$apiname%' LIMIT 1")->fetch_object()->achievement_id;
$achGame = mysqli_query($dB, "INSERT INTO game_achievement(app_id, achievement_id)
VALUES ('$appId','$achId')");
$achAppLink = mysqli_query($dB, "INSERT INTO user_achievement(user_id, achievement_id, achieved)
VALUES ('$steamId','$achId','$boolAchieved')");
}
}
$gameCompletionPercent = $hasAchieved / $achievementCount * 100;
return $gameCompletionPercent;
}
}