From 519d671e1a2b8e1f04775a9b34a23b18039f4f5a Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Sat, 8 Jun 2024 22:37:44 +0200 Subject: [PATCH] added profileiconid --- public/elotracker/Tracker.php | 45 ++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/public/elotracker/Tracker.php b/public/elotracker/Tracker.php index abf0637..8b9db75 100644 --- a/public/elotracker/Tracker.php +++ b/public/elotracker/Tracker.php @@ -31,6 +31,7 @@ class Tracker { $account->puuid = $row["puuid"]; $account->gameName = $row["gameName"]; $account->tagLine = $row["tagLine"]; + $account->profileIconId = $row["profileIconId"]; $accounts[$account->puuid] = $account; } @@ -92,8 +93,7 @@ class Tracker { public function update(): void { foreach ($this->accounts as $puuid => $account) { - $account->updateRiotID(); - $account->addNewEloEntry($this->entries[$puuid]); + $account->update($this->entries[$puuid]); } } @@ -110,6 +110,7 @@ class Tracker { $account->gameName = $result->gameName; $account->tagLine = $result->tagLine; $this->accounts[$account->puuid] = $account; + $this->entries[$account->puuid] = []; $this->conn->prepare(" INSERT INTO `accounts` @@ -118,6 +119,9 @@ class Tracker { ")->execute([$account->puuid, $account->gameName, $account->tagLine]); $message = "Success."; + + $account->update($this->entries[$account->puuid]); + return true; } else { $message = "Riot ID already added."; @@ -160,12 +164,23 @@ class Account { public string $puuid; public string $gameName; public string $tagLine; + public int $profileIconId = 0; + + /** + * @param Elo[] $eloEntries + */ + public function update(array &$eloEntries): void { + $summoner = (new RiotRequest("lol/summoner/v4/summoners/by-puuid/$this->puuid"))->run($isEUNE); + $this->profileIconId = $summoner->profileIconId; + + $this->updateRiotIDAndProfileIcon(); + $this->tryAddNewEloEntry($eloEntries, $summoner->id, $isEUNE); + } /** * @param Elo[] $eloEntries */ - public function addNewEloEntry(array &$eloEntries): void { - $summonerId = (new RiotRequest("lol/summoner/v4/summoners/by-puuid/$this->puuid"))->run($isEUNE)->id; + private function tryAddNewEloEntry(array &$eloEntries, string $summonerId, bool $isEUNE): void { $fetchedLeagues = (new RiotRequest("lol/league/v4/entries/by-summoner/$summonerId", $isEUNE))->run(); $currentElo = end($eloEntries); @@ -204,22 +219,20 @@ class Account { } } } - public function updateRiotID(): void { + private function updateRiotIDAndProfileIcon(): void { $request = new RiotRequest("riot/account/v1/accounts/by-puuid/$this->puuid"); $request->useRouting(); - $result = $request->run(); - if ($request->responseCode == 200) { - $this->gameName = $result->gameName; - $this->tagLine = $result->tagLine; + $fetchedAccount = $request->run(); - $conn = new MySQLConnection(); - $conn->query(" - UPDATE `accounts` - SET `gameName` = '$this->gameName', `tagLine` = '$this->tagLine' - WHERE `puuid` = '$this->puuid' - "); + $this->gameName = $fetchedAccount->gameName; + $this->tagLine = $fetchedAccount->tagLine; - } + $conn = new MySQLConnection(); + $conn->prepare(" + UPDATE `accounts` + SET `gameName` = ?, `tagLine` = ?, `profileIconId` = $this->profileIconId + WHERE `puuid` = ? + ")->execute([$this->gameName, $this->tagLine, $this->puuid]); } }