94 lines
3 KiB
PHP
94 lines
3 KiB
PHP
<?php
|
|
|
|
// Lade den minimalistischen Autoloader
|
|
require_once __DIR__ . '/../src/autoload.php';
|
|
|
|
use App\Core\Database;
|
|
use App\Models\Game;
|
|
use App\Models\Tipp;
|
|
use App\Models\Round;
|
|
use App\Models\Season;
|
|
use App\Models\Ranking;
|
|
|
|
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
|
|
// Routing basierend auf Query-Parametern, um Probleme mit URL-Rewriting zu umgehen
|
|
if (($_GET['page'] ?? null) === 'round' && isset($_GET['id'])) {
|
|
try {
|
|
$roundId = (int)$_GET['id'];
|
|
$selectedRound = Round::getById($roundId);
|
|
|
|
if (!$selectedRound) {
|
|
http_response_code(404);
|
|
echo "404 Not Found: Runde nicht gefunden.";
|
|
exit;
|
|
}
|
|
|
|
// 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';
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
echo "<p style='color:red;'>Fehler: " . htmlspecialchars($e->getMessage()) . "</p>";
|
|
}
|
|
} elseif (($_GET['page'] ?? null) === 'ranking') {
|
|
try {
|
|
$currentSeason = Season::getCurrent();
|
|
if (!$currentSeason) {
|
|
throw new \Exception("Keine aktuelle Saison gefunden.");
|
|
}
|
|
|
|
$rankingData = Ranking::getRanking($currentSeason['id']);
|
|
$ranking = $rankingData['ranking'];
|
|
$games = $rankingData['games'];
|
|
|
|
require __DIR__ . '/../src/Views/ranking.php';
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
echo "<p style='color:red;'>Fehler: " . htmlspecialchars($e->getMessage()) . "</p>";
|
|
}
|
|
} elseif ($uri === '/' || $uri === '/index.php') {
|
|
try {
|
|
$db = Database::getConnection();
|
|
$userCount = $db->query("SELECT COUNT(*) FROM users")->fetchColumn();
|
|
|
|
$currentSeason = Season::getCurrent();
|
|
|
|
if ($currentSeason) {
|
|
$rounds = Round::getBySeason($currentSeason['id']);
|
|
} else {
|
|
$rounds = [];
|
|
}
|
|
|
|
// 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) {
|
|
$games = Game::getGamesByRound($lastRoundId);
|
|
} else {
|
|
$games = [];
|
|
}
|
|
|
|
require __DIR__ . '/../src/Views/home.php';
|
|
|
|
} catch (Throwable $e) {
|
|
echo "<p style='color:red;'>Fehler: " . $e->getMessage() . "</p>";
|
|
}
|
|
} elseif ($uri === '/api/status') {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['status' => 'ok', 'version' => '2027.1']);
|
|
} else {
|
|
http_response_code(404);
|
|
echo "404 Not Found";
|
|
}
|