-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummonerForm.php
169 lines (168 loc) · 12.6 KB
/
summonerForm.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
require_once '../config.php';
require_once '../kennitala_function.php';
require_once '../vendor/autoload.php';
use LeagueWrap\Api;
$server = $_POST['server'];
$summonerName = $_POST['summoner'];
$kennitala = $_POST['kennitala'];
if(preg_match('/ ^[0-9\p{L} ]+$ /', $summonerName))
{
echo "<div class='alert alert-danger'>Þessi summoner fannst ekki: <b>$summonerName</b>, vinsamlegast athugaðu hvort þú valdir réttan server</div>", exit;
}
if (kennitala($kennitala) == 'Ogild Kennitala') {
echo "<div class='alert alert-danger'>Þessi kennitala er ógild", exit;
}
$api = new Api($key); // Load up the API
$api->setRegion($server); //Setja region sem það sem notandinn valdi (na, euw eða {$server})
try {
$championsStaticData = $api->staticData()->getChampions();
} catch (LeagueWrap\Response\Http404 $e) {
echo "<div class='alert alert-danger'>Fyrirgefðu! Það er eitthvað bilað hjá Riot Games, vinsamlegast prufaðu aftur seinna</div>", exit;
} catch (LeagueWrap\Response\UnderlyingServiceRateLimitReached $e) {
echo "<div class='alert alert-danger'>Fyrirgefðu! það eru of margir að nota síðuna í augnablikinu, vinsamlegast prufaðu aftur seinna</div>", exit;
}
try {
$summoner = $api->summoner()->info($summonerName);
} catch (LeagueWrap\Response\Http404 $e) {
echo "<div class='alert alert-danger'>Þessi summoner fannst ekki: <b>$summonerName</b>, vinsamlegast athugaðu hvort þú valdir réttan server</div>", exit;
} catch (LeagueWrap\Response\UnderlyingServiceRateLimitReached $e) {
echo "<div class='alert alert-danger'>Fyrirgefðu! það eru of margir að nota síðuna í augnablikinu, vinsamlegast prufaðu aftur seinna</div>", exit;
}
try {
$masteryPages = $api->summoner()->masteryPages($summoner->id);
$runePages = $api->summoner()->runePages($summoner->id);
} catch (LeagueWrap\Response\Http404 $e) {
echo "<div class='alert alert-danger'>Það fannst ekki mastery/rune pages fyrir þennan summoner: <b>$summoner->name</b></div>", exit;
} catch (LeagueWrap\Response\UnderlyingServiceRateLimitReached $e) {
echo "<div class='alert alert-danger'>Fyrirgefðu! það eru of margir að nota síðuna í augnablikinu, vinsamlegast prufaðu aftur seinna</div>", exit;
}
#Tjekka hvort notandinn er með mastery Page sem er == "iceleague" til þess að staðfesta að notandinn á summoner aðganginn
$iceleaguePageFound = False;
foreach ($masteryPages as $masteryPage) {
$masteryPageName = strtolower($masteryPage->name); #Lágstafa nafnið á mastery page-inu svo það breyti ekki máli ef notandinn notar Lágstafi/Hástafi
if ($masteryPageName == "iceleague") {
$iceleaguePageFound = True;
}
}
foreach ($runePages as $runePage) {
$runePageName = strtolower($runePage->name); #Lágstafa nafnið á mastery page-inu svo það breyti ekki máli ef notandinn notar Lágstafi/Hástafi
if ($runePageName == "iceleague") {
$iceleaguePageFound = True;
}
}
if ($iceleaguePageFound == False) {
echo "<div class='alert alert-danger'>Þú verður að endurskíra Mastery page/ Rune page í 'iceleague' (án gæsalappa)</div>", exit;
}
elseif ($iceleaguePageFound == True) {
#setja notandann í gagnagrunninum
$sth = $pdo->prepare("REPLACE INTO {$server}_summoners (id, summonerName, profileIconId, summonerLevel) VALUES(:id, :name, :profileIconId, :summonerLevel)");
$sth->bindValue(":id", $summoner->id);
$sth->bindValue(":name", $summoner->name);
$sth->bindValue(":profileIconId", $summoner->profileIconId);
$sth->bindValue(":summonerLevel", $summoner->summonerLevel);
$sth->execute();
#Finna League stats hjá notanda, loopa í gegnum þá og setja í gagnagrunninn - Ef enginn league stats fannst þá fáum við 404 error
try {
$leagues = $api->league()->league($summoner, true);
foreach ($leagues as $league) {
$queue = strtolower($league->queue); #Lágstafa queue til þess að setja í table með lágstöfum
$sth = $pdo->prepare("REPLACE INTO {$server}_{$queue} (name, tier, queue, playerOrTeamid, playerOrTeamName, division, leaguePoints, wins, losses) VALUES(:name, :tier, :queue, :playerOrTeamId, :playerOrTeamName, :division, :leaguePoints, :wins, :losses)");
$sth->bindValue(":name", $league->name);
$sth->bindValue(":tier", $league->tier);
$sth->bindValue(":queue", $league->queue);
$sth->bindValue(":playerOrTeamId", $league->entries[0]->playerOrTeamId);
$sth->bindValue(":playerOrTeamName", $league->entries[0]->playerOrTeamName);
$sth->bindValue(":division", $league->entries[0]->division);
$sth->bindValue(":leaguePoints", $league->entries[0]->leaguePoints);
$sth->bindValue(":wins", $league->entries[0]->wins);
$sth->bindValue(":losses", $league->entries[0]->losses);
$sth->execute();
}
} catch (LeagueWrap\Response\Http404 $e) {
echo "<div class='alert alert-danger'>Það fannst ekki League stats fyrir þennan summoner: <b>$summoner->name</b></div>", exit;
} catch (LeagueWrap\Response\UnderlyingServiceRateLimitReached $e) {
echo "<div class='alert alert-danger'>Fyrirgefðu! það eru of margir að nota síðuna í augnablikinu, vinsamlegast prufaðu aftur seinna</div>", exit;
}
#Finna champion mastery stats hjá notanda, setja það í gagnagrunninn - Ef ekkert fannst þá fáum við 404 error
try {
$masteryList = $api->championMastery()->topChampions($summoner, 3);
$champion1 = $championsStaticData->getChampion($masteryList[0]->championId);
$champion2 = $championsStaticData->getChampion($masteryList[1]->championId);
$champion3 = $championsStaticData->getChampion($masteryList[2]->championId);
$sth = $pdo->prepare("REPLACE INTO {$server}_champion_mastery (id, summonerName, championId1, championName1, championPoints1, championId2, championName2, championPoints2, championId3, championName3, championPoints3)
VALUES(:id, :summonerName, :championId1, :championName1, :championPoints1, :championId2, :championName2, :championPoints2, :championId3, :championName3, :championPoints3)");
$sth->bindValue(":id", $summoner->id);
$sth->bindValue(":summonerName", $summoner->name);
$sth->bindValue(":championId1", $masteryList[0]->championId);
$sth->bindValue(":championName1", $champion1->key);
$sth->bindValue(":championPoints1", $masteryList[0]->championPoints);
$sth->bindValue(":championId2", $masteryList[1]->championId);
$sth->bindValue(":championName2", $champion2->key);
$sth->bindValue(":championPoints2", $masteryList[1]->championPoints);
$sth->bindValue(":championId3", $masteryList[2]->championId);
$sth->bindValue(":championName3", $champion3->key);
$sth->bindValue(":championPoints3", $masteryList[2]->championPoints);
$sth->execute();
} catch (LeagueWrap\Response\Http404 $e) {
echo "<div class='alert alert-danger'>Það fannst ekki Champion Mastery stats fyrir þennan summoner: <b>$summoner->name</b></div>", exit;
} catch (LeagueWrap\Response\UnderlyingServiceRateLimitReached $e) {
echo "<div class='alert alert-danger'>Fyrirgefðu! það eru of margir að nota síðuna í augnablikinu, vinsamlegast prufaðu aftur seinna</div>", exit;
}
#Finna ranked stats hjá notanda, setja það í gagnagrunninn - Ef enginn ranked stats fannst þá fáum við 404 error
try {
$stats = $api->stats()->ranked($summoner)->raw();
#Raða stats eftir totalSessionsPlayed (descending) - Setja top 3 champana í gagnagrunninn, setja champion id 0 ranked stats í gagnagrunninn (champion id 0 er samanlagða stats af öllum champions)
usort($stats['champions'], function($a, $b) {
return $b['stats']['totalSessionsPlayed'] - $a['stats']['totalSessionsPlayed'];
});
$champion1 = $championsStaticData->getChampion($stats['champions'][1]['id']);
$champion2 = $championsStaticData->getChampion($stats['champions'][2]['id']);
$champion3 = $championsStaticData->getChampion($stats['champions'][3]['id']);
$sth = $pdo->prepare("REPLACE INTO {$server}_most_played_champions (id, summonerName, championId1, championName1, championId2, championName2, championId3, championName3)
VALUES(:id, :summonerName, :championId1, :championName1, :championId2, :championName2, :championId3, :championName3)");
$sth->bindValue(":id", $summoner->id);
$sth->bindValue(":summonerName", $summoner->name);
$sth->bindValue(":championId1", $stats['champions'][1]['id']);
$sth->bindValue(":championName1", $champion1->key);
$sth->bindValue(":championId2", $stats['champions'][2]['id']);
$sth->bindValue(":championName2", $champion2->key);
$sth->bindValue(":championId3", $stats['champions'][3]['id']);
$sth->bindValue(":championName3", $champion3->key);
$sth->execute();
$sth = $pdo->prepare("REPLACE INTO {$server}_ranked_stats (id, summonerName, championId, totalSessionsPlayed, totalSessionsLost, totalSessionsWon, totalChampionKills, totalDamageDealt, totalDamageTaken, mostChampionKillsPerSession, totalMinionKills, totalDoubleKills, totalTripleKills, totalQuadraKills, totalPentaKills, totalUnrealKills, totalDeathsPerSession, totalGoldEarned, mostSpellsCast, totalTurretsKilled, totalPhysicalDamageDealt, totalMagicDamageDealt, totalFirstBlood, totalAssists, maxChampionsKilled, maxNumDeaths)
VALUES(:id, :summonerName, :championId, :totalSessionsPlayed, :totalSessionsLost, :totalSessionsWon, :totalChampionKills, :totalDamageDealt, :totalDamageTaken, :mostChampionKillsPerSession, :totalMinionKills, :totalDoubleKills, :totalTripleKills, :totalQuadraKills, :totalPentaKills, :totalUnrealKills, :totalDeathsPerSession, :totalGoldEarned, :mostSpellsCast, :totalTurretsKilled, :totalPhysicalDamageDealt, :totalMagicDamageDealt, :totalFirstBlood, :totalAssists, :maxChampionsKilled, :maxNumDeaths)");
$sth->bindValue(":id", $summoner->id);
$sth->bindValue(":summonerName", $summoner->name);
$sth->bindValue(":championId", $stats['champions'][0]['id']);
$sth->bindValue(":totalSessionsPlayed",$stats['champions'][0]['stats']['totalSessionsPlayed']);
$sth->bindValue(":totalSessionsLost", $stats['champions'][0]['stats']['totalSessionsLost']);
$sth->bindValue(":totalSessionsWon", $stats['champions'][0]['stats']['totalSessionsWon']);
$sth->bindValue(":totalChampionKills", $stats['champions'][0]['stats']['totalChampionKills']);
$sth->bindValue(":totalDamageDealt", $stats['champions'][0]['stats']['totalDamageDealt']);
$sth->bindValue(":totalDamageTaken", $stats['champions'][0]['stats']['totalDamageTaken']);
$sth->bindValue(":mostChampionKillsPerSession", $stats['champions'][0]['stats']['mostChampionKillsPerSession']);
$sth->bindValue(":totalMinionKills", $stats['champions'][0]['stats']['totalMinionKills']);
$sth->bindValue(":totalDoubleKills", $stats['champions'][0]['stats']['totalDoubleKills']);
$sth->bindValue(":totalTripleKills", $stats['champions'][0]['stats']['totalTripleKills']);
$sth->bindValue(":totalQuadraKills", $stats['champions'][0]['stats']['totalQuadraKills']);
$sth->bindValue(":totalPentaKills", $stats['champions'][0]['stats']['totalPentaKills']);
$sth->bindValue(":totalUnrealKills", $stats['champions'][0]['stats']['totalUnrealKills']);
$sth->bindValue(":totalDeathsPerSession", $stats['champions'][0]['stats']['totalDeathsPerSession']);
$sth->bindValue(":totalGoldEarned", $stats['champions'][0]['stats']['totalGoldEarned']);
$sth->bindValue(":mostSpellsCast", $stats['champions'][0]['stats']['mostSpellsCast']);
$sth->bindValue(":totalTurretsKilled", $stats['champions'][0]['stats']['totalTurretsKilled']);
$sth->bindValue(":totalPhysicalDamageDealt", $stats['champions'][0]['stats']['totalPhysicalDamageDealt']);
$sth->bindValue(":totalMagicDamageDealt", $stats['champions'][0]['stats']['totalMagicDamageDealt']);
$sth->bindValue(":totalFirstBlood", $stats['champions'][0]['stats']['totalFirstBlood']);
$sth->bindValue(":totalAssists", $stats['champions'][0]['stats']['totalAssists']);
$sth->bindValue(":maxChampionsKilled", $stats['champions'][0]['stats']['maxChampionsKilled']);
$sth->bindValue(":maxNumDeaths", $stats['champions'][0]['stats']['maxNumDeaths']);
$sth->execute();
} catch (LeagueWrap\Response\Http404 $e) {
echo "<div class='alert alert-danger'>Það fannst ekki ranked stats fyrir þennan summoner: <b>$summoner->name</b></div>", exit;
} catch (LeagueWrap\Response\UnderlyingServiceRateLimitReached $e) {
echo "<div class='alert alert-danger'>Fyrirgefðu! það eru of margir að nota síðuna í augnablikinu, vinsamlegast prufaðu aftur seinna</div>", exit;
}
echo "<div class='alert alert-success'>Takk fyrir að skrá þig <b>$summoner->name</b>!</div>";
}