added profileiconid

main
Benjamin Kraft 3 months ago
parent 4ab6b3c24b
commit 519d671e1a
  1. 43
      public/elotracker/Tracker.php

@ -31,6 +31,7 @@ class Tracker {
$account->puuid = $row["puuid"]; $account->puuid = $row["puuid"];
$account->gameName = $row["gameName"]; $account->gameName = $row["gameName"];
$account->tagLine = $row["tagLine"]; $account->tagLine = $row["tagLine"];
$account->profileIconId = $row["profileIconId"];
$accounts[$account->puuid] = $account; $accounts[$account->puuid] = $account;
} }
@ -92,8 +93,7 @@ class Tracker {
public function update(): void { public function update(): void {
foreach ($this->accounts as $puuid => $account) { foreach ($this->accounts as $puuid => $account) {
$account->updateRiotID(); $account->update($this->entries[$puuid]);
$account->addNewEloEntry($this->entries[$puuid]);
} }
} }
@ -110,6 +110,7 @@ class Tracker {
$account->gameName = $result->gameName; $account->gameName = $result->gameName;
$account->tagLine = $result->tagLine; $account->tagLine = $result->tagLine;
$this->accounts[$account->puuid] = $account; $this->accounts[$account->puuid] = $account;
$this->entries[$account->puuid] = [];
$this->conn->prepare(" $this->conn->prepare("
INSERT INTO `accounts` INSERT INTO `accounts`
@ -118,6 +119,9 @@ class Tracker {
")->execute([$account->puuid, $account->gameName, $account->tagLine]); ")->execute([$account->puuid, $account->gameName, $account->tagLine]);
$message = "Success."; $message = "Success.";
$account->update($this->entries[$account->puuid]);
return true; return true;
} else { } else {
$message = "Riot ID already added."; $message = "Riot ID already added.";
@ -160,12 +164,23 @@ class Account {
public string $puuid; public string $puuid;
public string $gameName; public string $gameName;
public string $tagLine; 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 * @param Elo[] $eloEntries
*/ */
public function addNewEloEntry(array &$eloEntries): void { private function tryAddNewEloEntry(array &$eloEntries, string $summonerId, bool $isEUNE): void {
$summonerId = (new RiotRequest("lol/summoner/v4/summoners/by-puuid/$this->puuid"))->run($isEUNE)->id;
$fetchedLeagues = (new RiotRequest("lol/league/v4/entries/by-summoner/$summonerId", $isEUNE))->run(); $fetchedLeagues = (new RiotRequest("lol/league/v4/entries/by-summoner/$summonerId", $isEUNE))->run();
$currentElo = end($eloEntries); $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 = new RiotRequest("riot/account/v1/accounts/by-puuid/$this->puuid");
$request->useRouting(); $request->useRouting();
$result = $request->run(); $fetchedAccount = $request->run();
if ($request->responseCode == 200) {
$this->gameName = $result->gameName; $this->gameName = $fetchedAccount->gameName;
$this->tagLine = $result->tagLine; $this->tagLine = $fetchedAccount->tagLine;
$conn = new MySQLConnection(); $conn = new MySQLConnection();
$conn->query(" $conn->prepare("
UPDATE `accounts` UPDATE `accounts`
SET `gameName` = '$this->gameName', `tagLine` = '$this->tagLine' SET `gameName` = ?, `tagLine` = ?, `profileIconId` = $this->profileIconId
WHERE `puuid` = '$this->puuid' WHERE `puuid` = ?
"); ")->execute([$this->gameName, $this->tagLine, $this->puuid]);
}
} }
} }

Loading…
Cancel
Save