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->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();
$this->gameName = $fetchedAccount->gameName;
$this->tagLine = $fetchedAccount->tagLine;
$conn = new MySQLConnection();
$conn->query("
$conn->prepare("
UPDATE `accounts`
SET `gameName` = '$this->gameName', `tagLine` = '$this->tagLine'
WHERE `puuid` = '$this->puuid'
");
}
SET `gameName` = ?, `tagLine` = ?, `profileIconId` = $this->profileIconId
WHERE `puuid` = ?
")->execute([$this->gameName, $this->tagLine, $this->puuid]);
}
}

Loading…
Cancel
Save