Merge pull request #112 from OpzekerIT/dev

get matchinfo
This commit is contained in:
Lanta 2023-11-14 22:38:17 +01:00 committed by GitHub
commit 921e9994ab
5 changed files with 157 additions and 24 deletions

View file

@ -10,6 +10,7 @@
"SquadKiller101", "SquadKiller101",
"Pettie1972", "Pettie1972",
"HeteKip", "HeteKip",
"Shepherders",
"WackyJacky101" "WackyJacky101"
] ]
} }

View file

@ -204,8 +204,8 @@ nav {
/* Ensure links stand out */ /* Ensure links stand out */
a { a {
color: #6699ff; /* Blue color for links */ color: #e69109; /* Blue color for links */
text-decoration: underline; /* Underline links for better visibility */ text-decoration: none; /* Underline links for better visibility */
} }
/* Specific button styles for .btn class to match the hacker theme */ /* Specific button styles for .btn class to match the hacker theme */

View file

@ -100,14 +100,14 @@ error_reporting(E_ALL);
echo "<tr> echo "<tr>
<td><a href='latestmatches.php?selected_player=$player_name'>$player_name</a></td> <td><a href='latestmatches.php?selected_player=$player_name'>$player_name</a></td>
<td>$winratio</td> <td><a href='latestmatches.php?selected_player=$player_name'>$winratio</a></td>
<td>$KD_H</td> <td><a href='latestmatches.php?selected_player=$player_name'>$KD_H</a></td>
<td>$KD_ALL</td> <td><a href='latestmatches.php?selected_player=$player_name'>$KD_ALL</a></td>
<td>$kills</td> <td><a href='latestmatches.php?selected_player=$player_name'>$kills</a></td>
<td>$humankills</td> <td><a href='latestmatches.php?selected_player=$player_name'>$humankills</a></td>
<td>$matches</td> <td><a href='latestmatches.php?selected_player=$player_name'>$matches</a></td>
<td>$wins</td> <td><a href='latestmatches.php?selected_player=$player_name'>$wins</a></td>
<td>$deaths</td> <td><a href='latestmatches.php?selected_player=$player_name'>$deaths</a></td>
<td style='line-height: 17px;'><img src='$imagePath' alt='Change Indicator' style='vertical-align: middle;' width='17' height='17'/> $change </td> <td style='line-height: 17px;'><img src='$imagePath' alt='Change Indicator' style='vertical-align: middle;' width='17' height='17'/> $change </td>

View file

@ -7,16 +7,17 @@ error_reporting(E_ALL);
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<?php include './includes/head.php'; ?> <?php include './includes/head.php'; ?>
<body> <body>
<?php include './includes/navigation.php'; ?> <?php include './includes/navigation.php'; ?>
<header> <header>
<img src="./images/banner2.png" alt="banner" class="banner"> <img src="./images/banner2.png" alt="banner" class="banner">
</header> </header>
<main> <main>
<section> <section>
<h2>Match Stats</h2> <h2>Match Stats</h2>
<?php <?php
include './config/config.php'; include './config/config.php';
$players_matches = json_decode(file_get_contents('./data/player_matches.json'), true); $players_matches = json_decode(file_get_contents('./data/player_matches.json'), true);
@ -29,7 +30,7 @@ error_reporting(E_ALL);
echo "<button type='submit' name='selected_player' value='$player_name' class='btn'>$player_name</button>"; echo "<button type='submit' name='selected_player' value='$player_name' class='btn'>$player_name</button>";
} }
} }
echo "</form><br>"; echo "</form><br>";
$selected_player = $_GET['selected_player'] ?? $players_matches[0]['playername']; $selected_player = $_GET['selected_player'] ?? $players_matches[0]['playername'];
@ -64,17 +65,28 @@ error_reporting(E_ALL);
$damage = number_format($match['stats']['damageDealt'], 0, '.', ''); $damage = number_format($match['stats']['damageDealt'], 0, '.', '');
$timeSurvived = $match['stats']['timeSurvived']; $timeSurvived = $match['stats']['timeSurvived'];
$winPlace = $match['stats']['winPlace']; $winPlace = $match['stats']['winPlace'];
echo "<tr><td>$formattedDate</td><td>$gameMode</td><td>$matchType</td><td>$mapName</td><td>$kills</td><td>$damage</td><td>$timeSurvived</td><td>$winPlace</td></tr>"; echo "<tr>
<td><a href='matchinfo.php?matchid=" . $match['id'] . "'>" . $formattedDate . "</a></td>
<td><a href='matchinfo.php?matchid=" . $match['id'] . "'>" . $gameMode . "</a></td>
<td><a href='matchinfo.php?matchid=" . $match['id'] . "'>" . $matchType . "</a></td>
<td><a href='matchinfo.php?matchid=" . $match['id'] . "'>" . $mapName . "</a></td>
<td><a href='matchinfo.php?matchid=" . $match['id'] . "'>" . $kills . "</a></td>
<td><a href='matchinfo.php?matchid=" . $match['id'] . "'>" . $damage . "</a></td>
<td><a href='matchinfo.php?matchid=" . $match['id'] . "'>" . $timeSurvived . "</a></td>
<td><a href='matchinfo.php?matchid=" . $match['id'] . "'>" . $winPlace . "</a></td>
</tr>";
} }
echo "</table><br>"; echo "</table><br>";
} }
} }
?> ?>
</section> </section>
</main> </main>
<?php include './includes/footer.php'; ?> <?php include './includes/footer.php'; ?>
</body> </body>
</html>
</html>

120
matchinfo.php Normal file
View file

@ -0,0 +1,120 @@
<?php
// Read the JSON file
$jsonData = file_get_contents('data/player_matches.json');
$playersData = json_decode($jsonData, true);
// Combine matches from all players
$allMatches = [];
foreach ($playersData as $player) {
foreach ($player['player_matches'] as $match) {
$match['playername'] = $player['playername']; // Add playername to each match for reference
$allMatches[] = $match;
}
}
// Sort matches by createdAt date
usort($allMatches, function ($a, $b) {
return strtotime($b['createdAt']) - strtotime($a['createdAt']);
});
// Get the last 5 matches
$lastMatches = array_slice($allMatches, 0, 8);
?>
<!DOCTYPE html>
<html lang="en">
<?php include './includes/head.php'; ?>
<body>
<?php include './includes/navigation.php'; ?>
<header>
<img src="./images/banner2.png" alt="banner" class="banner">
</header>
<main>
<section>
<h2>Latest Matches</h2>
<?php
// Check if a match ID is provided in the GET request
if (isset($_GET['matchid'])) {
$matchId = $_GET['matchid'];
$filename = "data/matches/" . $matchId . ".json";
// Check if the JSON file for the given match ID exists
if (file_exists($filename)) {
// Read and decode the JSON file
$jsonData = json_decode(file_get_contents($filename), true);
$matchinfo = $jsonData['data']['attributes'];
$matchdata = $jsonData['data'];
echo "<table class='sortable'><tr><th>matchType</th><th>duration</th><th>gameMode</th><th>mapName</th><th>createdAt</th><th>id</th></tr>";
echo "<tr>";
echo "<td>" . htmlspecialchars($matchinfo['matchType']) . "</td>";
echo "<td>" . htmlspecialchars($matchinfo['duration']) . "</td>";
echo "<td>" . htmlspecialchars($matchinfo['gameMode']) . "</td>";
echo "<td>" . htmlspecialchars($matchinfo['mapName']) . "</td>";
echo "<td>" . htmlspecialchars($matchinfo['createdAt']) . "</td>";
echo "<td>" . htmlspecialchars($matchdata['id']) . "</td>";
echo "</tr>";
echo "</table>";
echo "<table class='sortable'>";
echo "<tr>
<th>Player Name</th>
<th>Kills</th>
<th>Damage Dealt</th>
<th>Time Survived</th>
<th>Rank</th>
<th>Revives</th>
<th>Longest Kill</th>
<th>DBNOs</th>
<th>Headshot Kills</th>
<th>Assists</th>
</tr>";
foreach ($jsonData['included'] as $includedItem) {
if ($includedItem['type'] == "participant") {
$playerStats = $includedItem['attributes']['stats'];
echo "<tr>";
echo "<td>" . htmlspecialchars($playerStats['name']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['kills']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['damageDealt']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['timeSurvived']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['winPlace']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['revives']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['longestKill']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['DBNOs']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['headshotKills']) . "</td>";
echo "<td>" . htmlspecialchars($playerStats['assists']) . "</td>";
echo "</tr>";
}
}
echo "</table>";
} else {
echo "JSON file not found for the given match ID.";
}
} else {
echo "No match ID provided.";
}
?>
</table>
</section>
</main>
<?php include './includes/footer.php'; ?>
</body>
</html>