feat: Erweitere Rundenansicht und integriere Hauptmenü

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
torsten 2026-10-03 17:09:57 +02:00
parent 15cce6e697
commit 19e40998c2
5 changed files with 107 additions and 64 deletions

View file

@ -15,15 +15,24 @@ $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if (($_GET['page'] ?? null) === 'round' && isset($_GET['id'])) {
try {
$roundId = (int)$_GET['id'];
$round = Round::getById($roundId);
$selectedRound = Round::getById($roundId);
if (!$round) {
if (!$selectedRound) {
http_response_code(404);
echo "404 Not Found: Runde nicht gefunden.";
exit;
}
$games = Game::getGamesByRound($roundId);
// Alle Runden der Saison holen
$allRoundsInSeason = Round::getBySeason($selectedRound['season_id']);
$roundsToShow = [];
foreach ($allRoundsInSeason as $round) {
if ($round['id'] <= $selectedRound['id']) {
$round['games'] = Game::getGamesByRound($round['id']);
$roundsToShow[] = $round;
}
}
// Lade das View-Template für die Rundenansicht
require __DIR__ . '/../src/Views/round.php';
@ -32,64 +41,30 @@ if (($_GET['page'] ?? null) === 'round' && isset($_GET['id'])) {
echo "<p style='color:red;'>Fehler: " . htmlspecialchars($e->getMessage()) . "</p>";
}
} elseif ($uri === '/' || $uri === '/index.php') {
echo "<h1>Willkommen bei Tippspiel 2027</h1>";
echo "<p>Dies ist die Nachfolgeversion des alten Tippspiels (Pure PHP Variante).</p>";
try {
$db = Database::getConnection();
$userCount = $db->query("SELECT COUNT(*) FROM users")->fetchColumn();
echo "<p>Datenbank verbunden! Aktuell <strong>$userCount</strong> User im System.</p>";
echo "<h2>Rundenübersicht</h2>";
$currentSeason = Season::getCurrent();
if ($currentSeason) {
echo "<p>Saison: <strong>" . htmlspecialchars($currentSeason['name']) . "</strong></p>";
$rounds = Round::getBySeason($currentSeason['id']);
} else {
$rounds = [];
}
if ($rounds) {
echo "<ul>";
foreach ($rounds as $round) {
// Link-Format angepasst, um ohne URL-Rewriting zu funktionieren
echo '<li><a href="/index.php?page=round&id=' . htmlspecialchars($round['id']) . '">' . htmlspecialchars($round['name']) . '</a></li>';
}
echo "</ul>";
} else {
echo "<p>Keine Runden für die aktuelle Saison gefunden.</p>";
}
echo "<h2>Portierte Backend-Logik (Test)</h2>";
// 1. Test der Score-Berechnung (getScoreLocal Logik aus Tipp.php)
echo "<h3>Punkteberechnung</h3>";
$scoreTest = Tipp::getScoreLocal(2, 1, 2, 1, true); // Ergebnis: 2:1, Tipp: 2:1 (mit Joker)
echo "<p>Test: Spiel endet 2:1, getippt wurde 2:1 mit Joker. Erwartet: 4 Punkte. <strong>Berechnet: $scoreTest Punkte</strong>.</p>";
// 2. Test der Spiel-Logiken
echo "<h3>Spiele der letzten gespielten Runde</h3>";
// Finde zunächst die ID der letzten gespielten Runde (wo es Ergebnisse gibt)
// Testdaten für die Startseite
$scoreTest = Tipp::getScoreLocal(2, 1, 2, 1, true);
$lastRoundId = $db->query("SELECT round_id FROM games WHERE score1 > -1 ORDER BY id DESC LIMIT 1")->fetchColumn();
if ($lastRoundId) {
// Hole alle Spiele exakt dieser Runde
$games = Game::getGamesByRound($lastRoundId);
if ($games) {
echo "<ul>";
foreach ($games as $g) {
$status = Game::getResultString($g['score1'], $g['score2'], $g['kickoff']);
$locked = Game::isLocked($g['kickoff']) ? "Gesperrt" : "Offen";
echo "<li>" . htmlspecialchars($g['team1'] . " vs " . $g['team2']) . " | Status: $status | $locked</li>";
}
echo "</ul>";
}
} else {
echo "<p>Keine gespielten Spiele gefunden.</p>";
$games = [];
}
require __DIR__ . '/../src/Views/home.php';
} catch (Throwable $e) {
echo "<p style='color:red;'>Fehler: " . $e->getMessage() . "</p>";
}

49
src/Views/home.php Normal file
View file

@ -0,0 +1,49 @@
<?php
use App\Models\Game;
$pageTitle = 'Tippspiel 2027 - Startseite';
require __DIR__ . '/partials/header.php';
?>
<h1>Willkommen bei Tippspiel 2027</h1>
<p>Dies ist die Nachfolgeversion des alten Tippspiels (Pure PHP Variante).</p>
<p>Datenbank verbunden! Aktuell <strong><?php echo $userCount; ?></strong> User im System.</p>
<h2>Rundenübersicht</h2>
<?php if ($currentSeason): ?>
<p>Saison: <strong><?php echo htmlspecialchars($currentSeason['name']); ?></strong></p>
<?php if ($rounds): ?>
<ul>
<?php foreach ($rounds as $round): ?>
<li><a href="/index.php?page=round&id=<?php echo htmlspecialchars($round['id']); ?>"><?php echo htmlspecialchars($round['name']); ?></a></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>Keine Runden für die aktuelle Saison gefunden.</p>
<?php endif; ?>
<?php else: ?>
<p>Keine Saison gefunden.</p>
<?php endif; ?>
<h2>Portierte Backend-Logik (Test)</h2>
<h3>Punkteberechnung</h3>
<p>Test: Spiel endet 2:1, getippt wurde 2:1 mit Joker. Erwartet: 4 Punkte. <strong>Berechnet: <?php echo $scoreTest; ?> Punkte</strong>.</p>
<h3>Spiele der letzten gespielten Runde</h3>
<?php if ($lastRoundId && $games): ?>
<ul>
<?php foreach ($games as $g): ?>
<?php
$status = Game::getResultString($g['score1'], $g['score2'], $g['kickoff']);
$locked = Game::isLocked($g['kickoff']) ? "Gesperrt" : "Offen";
?>
<li><?php echo htmlspecialchars($g['team1'] . " vs " . $g['team2']) . " | Status: $status | $locked"; ?></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>Keine gespielten Spiele gefunden.</p>
<?php endif; ?>
<?php require __DIR__ . '/partials/footer.php'; ?>

View file

@ -0,0 +1,2 @@
</body>
</html>

View file

@ -0,0 +1,24 @@
<?php $pageTitle = $pageTitle ?? 'Tippspiel 2027'; ?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title><?php echo htmlspecialchars($pageTitle); ?></title>
<style>
body { font-family: sans-serif; margin: 2em; }
nav { background: #f4f4f4; padding: 1em; margin-bottom: 2em; }
nav a { margin-right: 1em; text-decoration: none; color: #333; font-weight: bold; }
table { border-collapse: collapse; width: 100%; max-width: 800px; margin-top: 1em;}
th, td { border: 1px solid #ccc; padding: 8px; text-align: left; }
th { background-color: #f4f4f4; }
tr:nth-child(even) { background-color: #f9f9f9; }
</style>
</head>
<body>
<nav>
<a href="/">Start</a>
<a href="#">Administration</a>
<a href="#">Tipps</a>
<a href="#">Rangliste</a>
<a href="#">Info</a>
</nav>

View file

@ -1,27 +1,19 @@
<?php
// Stellt sicher, dass die benötigten Variablen vorhanden sind
if (!isset($round) || !isset($games)) {
if (!isset($selectedRound) || !isset($roundsToShow)) {
echo "Fehler: Daten für die Rundenansicht nicht gefunden.";
exit;
}
$pageTitle = 'Rundenübersicht - ' . htmlspecialchars($selectedRound['name']);
require __DIR__ . '/partials/header.php';
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Tippspiel 2027 - <?php echo htmlspecialchars($round['name']); ?></title>
<style>
body { font-family: sans-serif; margin: 2em; }
table { border-collapse: collapse; width: 100%; max-width: 800px; margin-top: 1em;}
th, td { border: 1px solid #ccc; padding: 8px; text-align: left; }
th { background-color: #f4f4f4; }
tr:nth-child(even) { background-color: #f9f9f9; }
</style>
</head>
<body>
<h1><?php echo htmlspecialchars($round['name']); ?></h1>
<?php if (!empty($games)): ?>
<h1>Tippübersicht bis: <?php echo htmlspecialchars($selectedRound['name']); ?></h1>
<?php foreach ($roundsToShow as $round): ?>
<h2><?php echo htmlspecialchars($round['name']); ?></h2>
<?php if (!empty($round['games'])): ?>
<table>
<thead>
<tr>
@ -33,7 +25,7 @@ if (!isset($round) || !isset($games)) {
</tr>
</thead>
<tbody>
<?php foreach ($games as $game): ?>
<?php foreach ($round['games'] as $game): ?>
<tr>
<td><?php echo htmlspecialchars((new DateTime($game['kickoff']))->format('d.m.Y H:i')); ?></td>
<td><?php echo htmlspecialchars($game['team1']); ?></td>
@ -47,7 +39,8 @@ if (!isset($round) || !isset($games)) {
<?php else: ?>
<p>Für diese Runde wurden keine Spiele gefunden.</p>
<?php endif; ?>
<?php endforeach; ?>
<p><a href="/">Zurück zur Startseite</a></p>
</body>
</html>
<p><a href="/">Zurück zur Startseite</a></p>
<?php require __DIR__ . '/partials/footer.php'; ?>