This commit is contained in:
torsten 2026-10-18 23:16:07 +02:00
parent 50cd802d33
commit 317f0bce1a
224 changed files with 1105 additions and 27 deletions

View file

@ -146,6 +146,8 @@ class Ranking {
$joker = $tipp ? (bool)$tipp['joker'] : false;
$cells[$game['id']] = [
'text' => ($tipp1 < 0 ? 'x' : $tipp1) . ':' . ($tipp2 < 0 ? 'x' : $tipp2),
'score1' => $tipp1 < 0 ? 'x' : (string)$tipp1,
'score2' => $tipp2 < 0 ? 'x' : (string)$tipp2,
'joker' => $joker,
'points' => Tipp::getScoreLocal((int)$game['score1'], (int)$game['score2'], $tipp1, $tipp2, $joker),
'color' => Tipp::getCol((int)$game['score1'], (int)$game['score2'], $tipp1, $tipp2, $joker),

View file

@ -0,0 +1,227 @@
<?php
namespace App\Models;
use App\Core\Database;
/**
* Kanonische Mannschaften (Vereine und Nationalmannschaften) mit Aliasen und Logo.
*
* Mannschaftsnamen in `games` sind Freitext. Über die normalisierten Aliase in
* `team_aliases` lassen sie sich robust einer kanonischen Mannschaft zuordnen.
* Für Vereine wird ein Vereinslogo, für Nationalmannschaften eine Flagge angezeigt.
*/
class Team {
/** In-Memory-Cache für resolve() innerhalb eines Requests */
private static $resolveCache = [];
/**
* Normalisiert einen Mannschaftsnamen für den Alias-Vergleich:
* Kleinbuchstaben, Umlaute/Akzente transliteriert, nur noch [a-z0-9 ].
*
* @param string $name
* @return string
*/
public static function normalize($name) {
$name = mb_strtolower(trim((string)$name), 'UTF-8');
$map = [
'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'ß' => 'ss',
'á' => 'a', 'à' => 'a', 'â' => 'a', 'ã' => 'a',
'é' => 'e', 'è' => 'e', 'ê' => 'e', 'ë' => 'e',
'í' => 'i', 'ì' => 'i', 'î' => 'i', 'ï' => 'i',
'ó' => 'o', 'ò' => 'o', 'ô' => 'o', 'õ' => 'o',
'ú' => 'u', 'ù' => 'u', 'û' => 'u', 'ü' => 'ue',
'ñ' => 'n', 'ç' => 'c', 'ø' => 'o', 'å' => 'a',
'ł' => 'l', 'ı' => 'i', 'ş' => 's', 'ğ' => 'g',
'č' => 'c', 'ć' => 'c', 'š' => 's', 'ž' => 'z',
'đ' => 'd', 'ý' => 'y', 'æ' => 'ae', 'œ' => 'oe',
];
$name = strtr($name, $map);
$name = preg_replace('/[^a-z0-9]+/', ' ', $name);
$name = preg_replace('/\s+/', ' ', $name);
return trim($name);
}
/**
* Sucht eine Mannschaft über den normalisierten Alias.
*
* @param string $name Freitext-Name
* @return array|false
*/
public static function findByAlias($name) {
$db = Database::getConnection();
$stmt = $db->prepare(
"SELECT t.* FROM team_aliases a JOIN teams t ON t.id = a.team_id WHERE a.alias = ?"
);
$stmt->execute([self::normalize($name)]);
return $stmt->fetch();
}
/**
* Ordnet einen Freitext-Namen eindeutig zu (nur exakter Alias-Treffer).
* Für unsichere Fälle liefert suggest() Vorschläge.
*
* @param string $name
* @return array|false
*/
public static function resolve($name) {
$normalized = self::normalize($name);
if ($normalized === '') {
return false;
}
if (array_key_exists($normalized, self::$resolveCache)) {
return self::$resolveCache[$normalized];
}
$db = Database::getConnection();
$stmt = $db->prepare(
"SELECT t.* FROM team_aliases a JOIN teams t ON t.id = a.team_id WHERE a.alias = ?"
);
$stmt->execute([$normalized]);
$team = $stmt->fetch();
self::$resolveCache[$normalized] = $team;
return $team;
}
/**
* Liefert Vorschläge (Fuzzy) für einen nicht eindeutig zuordenbaren Namen.
*
* @param string $name
* @param int $limit
* @return array Liste von ['id','name','distance']
*/
public static function suggest($name, $limit = 5) {
$normalized = self::normalize($name);
if ($normalized === '') {
return [];
}
$db = Database::getConnection();
$teams = $db->query("SELECT id, name FROM teams")->fetchAll();
$candidates = [];
foreach ($teams as $team) {
$distance = levenshtein($normalized, self::normalize($team['name']));
$candidates[] = [
'id' => (int)$team['id'],
'name' => $team['name'],
'distance' => $distance,
];
}
usort($candidates, fn($a, $b) => $a['distance'] <=> $b['distance']);
return array_slice($candidates, 0, $limit);
}
/**
* @param int $id
* @return array|false
*/
public static function findById($id) {
$db = Database::getConnection();
$stmt = $db->prepare("SELECT * FROM teams WHERE id = ?");
$stmt->execute([(int)$id]);
return $stmt->fetch();
}
/**
* Öffentlicher Pfad zum Logo bzw. zur Flagge, oder null.
*
* @param array $team Zeile aus `teams`
* @return string|null z. B. '/img/teams/fc-bayern-muenchen.png'
*/
public static function logoUrl(array $team) {
return empty($team['logo']) ? null : '/img/' . $team['logo'];
}
/**
* Prüft, ob die Logodatei tatsächlich vorhanden ist.
*
* @param array $team
* @return bool
*/
public static function logoExists(array $team) {
if (empty($team['logo'])) {
return false;
}
$path = dirname(__DIR__, 2) . '/public/img/' . $team['logo'];
return is_file($path);
}
/**
* Liefert eine Map team_id => ['name' => ..., 'logo' => '/img/...'|null]
* für die Anzeige (Logo nur, wenn die Datei existiert).
*
* @param int[] $ids
* @return array
*/
public static function logoMap(array $ids) {
$ids = array_values(array_unique(array_map('intval', $ids)));
if (empty($ids)) {
return [];
}
$db = Database::getConnection();
$placeholders = implode(',', array_fill(0, count($ids), '?'));
$stmt = $db->prepare("SELECT * FROM teams WHERE id IN ($placeholders)");
$stmt->execute($ids);
$map = [];
foreach ($stmt->fetchAll() as $team) {
$map[(int)$team['id']] = [
'name' => $team['name'],
'logo' => self::logoExists($team) ? self::logoUrl($team) : null,
];
}
return $map;
}
/**
* Ordnet alle Spiele einer Saison zu: füllt team1_id/team2_id für beide
* Team-Spalten. Liefert die nicht zuordenbaren Namen (für ein Review).
*
* @param int $seasonId
* @return array ['mapped' => int, 'unmatched' => string[]]
*/
public static function mapSeason($seasonId) {
$db = Database::getConnection();
$stmt = $db->prepare(
"SELECT g.id, g.team1, g.team2 FROM games g
JOIN rounds r ON r.id = g.round_id
WHERE r.season_id = ?"
);
$stmt->execute([(int)$seasonId]);
$games = $stmt->fetchAll();
$update = $db->prepare("UPDATE games SET team1_id = ?, team2_id = ? WHERE id = ?");
$mapped = 0;
$unmatched = [];
foreach ($games as $game) {
$team1 = self::resolve($game['team1']);
$team2 = self::resolve($game['team2']);
$update->execute([
$team1 ? $team1['id'] : null,
$team2 ? $team2['id'] : null,
$game['id'],
]);
$mapped += ($team1 ? 1 : 0) + ($team2 ? 1 : 0);
if (!$team1) {
$unmatched[$game['team1']] = $game['team1'];
}
if (!$team2) {
$unmatched[$game['team2']] = $game['team2'];
}
}
return [
'mapped' => $mapped,
'unmatched' => array_values($unmatched),
];
}
}

View file

@ -1,10 +1,21 @@
<?php
use App\Models\Round;
use App\Models\Team;
$pageTitle = 'Spiele & Ergebnisse eintragen';
require __DIR__ . '/../partials/header.php';
$failedRoundId = $failedForm ? (int)($failedForm['round_id'] ?? 0) : null;
$teamLogo = function ($name) {
static $cache = [];
if (array_key_exists($name, $cache)) {
return $cache[$name];
}
$team = Team::resolve($name);
$cache[$name] = ($team && Team::logoExists($team)) ? Team::logoUrl($team) : null;
return $cache[$name];
};
?>
<h1>Spiele &amp; Ergebnisse eintragen</h1>
@ -81,12 +92,16 @@ $failedRoundId = $failedForm ? (int)($failedForm['round_id'] ?? 0) : null;
$gameId = (int)$game['id'];
$in = $form['games'][$gameId] ?? null;
$field = "games[$gameId]";
$team1Name = $in['team1'] ?? $game['team1'];
$team2Name = $in['team2'] ?? $game['team2'];
$l1 = $teamLogo($team1Name);
$l2 = $teamLogo($team2Name);
?>
<tr>
<td><input type="text" name="<?php echo $field; ?>[team1]" maxlength="100" required
value="<?php echo htmlspecialchars($in['team1'] ?? $game['team1']); ?>"></td>
<td><input type="text" name="<?php echo $field; ?>[team2]" maxlength="100" required
value="<?php echo htmlspecialchars($in['team2'] ?? $game['team2']); ?>"></td>
<td><span class="team-cell"><?php if ($l1): ?><img src="<?php echo htmlspecialchars($l1); ?>" alt="" class="team-logo"><?php endif; ?><input type="text" name="<?php echo $field; ?>[team1]" maxlength="100" required
value="<?php echo htmlspecialchars($team1Name); ?>"></span></td>
<td><span class="team-cell"><?php if ($l2): ?><img src="<?php echo htmlspecialchars($l2); ?>" alt="" class="team-logo"><?php endif; ?><input type="text" name="<?php echo $field; ?>[team2]" maxlength="100" required
value="<?php echo htmlspecialchars($team2Name); ?>"></span></td>
<td><input type="datetime-local" name="<?php echo $field; ?>[kickoff]" required
value="<?php echo htmlspecialchars($in['kickoff'] ?? date('Y-m-d\TH:i', strtotime($game['kickoff']))); ?>"></td>
<td class="score">

View file

@ -3,6 +3,7 @@ $pageTitle = 'Saisons verwalten';
require __DIR__ . '/../partials/header.php';
?>
<div class="season-centered">
<h1>Saisons verwalten</h1>
<?php if (!empty($message)): ?>
@ -125,8 +126,13 @@ require __DIR__ . '/../partials/header.php';
<?php endforeach; ?>
</tbody>
</table>
</div>
<style>
.season-centered { text-align: center; }
.season-centered form { display: inline-block; text-align: left; }
.season-centered form h2 { text-align: center; }
.season-centered table { margin: 1em auto 0; text-align: left; }
/* From users.php, for consistency */
.form-group {
margin-bottom: 1rem;

View file

@ -14,23 +14,51 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR
?>
<style>
.game-header {
width: 100px; /* Feste Breite für die Spiele-Spalten */
th.rotated-header,
th.game-header {
padding: 4px 2px;
text-align: center;
vertical-align: bottom;
white-space: normal;
}
th.game-header {
width: 34px;
min-width: 34px;
}
table.ranking-table {
width: auto; /* Keine feste Breite, damit die Tabelle frei wachsen kann */
min-width: 100%;
max-width: none; /* Default-max-width (800px) aufheben */
}
th.rotated-header .rotated-label,
th.game-header .rotated-label {
display: inline-block;
writing-mode: vertical-rl;
transform: rotate(180deg);
white-space: nowrap;
max-height: 180px;
overflow: hidden;
}
th.game-header .team-logo {
display: block;
margin: 0 auto 6px; /* Logo ganz oben, darunter der gedrehte Name */
}
.result-label {
font-weight: 700;
text-align: left;
}
.tipp-points {
width: 55px; /* Breite für den Tipp (z.B. 2:1) */
width: 34px; /* Schmale Spalte: Tor 1 bzw. Tor 2 */
box-sizing: border-box;
text-align: center;
padding-left: 2px;
padding-right: 2px;
}
.tipp-joker {
width: 70px; /* Breite für vergrößerten Joker */
width: 44px; /* Breite für den Joker */
box-sizing: border-box;
padding-left: 5px;
padding-left: 2px;
padding-right: 2px;
text-align: center;
}
.joker-icon {
@ -140,6 +168,7 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR
.bd-table .bd-num { text-align: right; }
.bd-joker { font-size: 0.85em; color: var(--muted); }
.bd-line { display: flex; justify-content: space-between; padding: 0.15em 0; }
.bd-line strong { white-space: nowrap; }
.bd-line.bd-total { border-top: 2px solid var(--pitch-dark); margin-top: 0.4em; padding-top: 0.4em; font-weight: 700; }
@media (max-width: 700px) {
@ -171,16 +200,26 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR
<table class="ranking-table">
<thead>
<tr>
<th class="text-center">Platz</th>
<th>Name</th>
<th class="text-center"><span class="daily-winner-icon">🏆</span></th>
<th class="text-center">Punkte<br>(Gesamt)</th>
<th class="text-center">Punkte<br>(Runde)</th>
<?php foreach ($games as $game): ?>
<th class="game-header" colspan="2">
<?php echo htmlspecialchars($game['team1']); ?><br>
<?php echo htmlspecialchars($game['team2']); ?><br>
<small>(<?php echo htmlspecialchars(App\Models\Game::getResultString($game['score1'], $game['score2'], $game['kickoff'])); ?>)</small>
<th class="rotated-header"><span class="rotated-label">Platz</span></th>
<th class="rotated-header"><span class="rotated-label">Name</span></th>
<th class="rotated-header"><span class="rotated-label">Tagessieg</span></th>
<th class="rotated-header"><span class="rotated-label">Punkte Gesamt</span></th>
<th class="rotated-header"><span class="rotated-label">Punkte Runde</span></th>
<?php foreach ($games as $game):
$t1 = $teamLogos[$game['team1_id']] ?? null;
$t2 = $teamLogos[$game['team2_id']] ?? null;
$matchTitle = htmlspecialchars($game['team1'] . ' : ' . $game['team2']);
?>
<th class="game-header" title="<?php echo $matchTitle; ?>">
<?php if ($t1 && $t1['logo']): ?><img src="<?php echo htmlspecialchars($t1['logo']); ?>" alt="" class="team-logo"><?php endif; ?>
<span class="rotated-label"><?php echo htmlspecialchars($game['team1']); ?></span>
</th>
<th class="game-header" title="<?php echo $matchTitle; ?>">
<?php if ($t2 && $t2['logo']): ?><img src="<?php echo htmlspecialchars($t2['logo']); ?>" alt="" class="team-logo"><?php endif; ?>
<span class="rotated-label"><?php echo htmlspecialchars($game['team2']); ?></span>
</th>
<th class="game-header" title="Joker">
<span class="rotated-label">Joker</span>
</th>
<?php endforeach; ?>
</tr>
@ -229,7 +268,10 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR
$title = "Punkte: " . $tipp['points'];
?>
<td class="tipp-cell tipp-points <?php echo htmlspecialchars($td_class); ?>" title="<?php echo $title; ?>">
<?php echo htmlspecialchars($tipp['text']); ?>
<?php echo htmlspecialchars($tipp['score1']); ?>
</td>
<td class="tipp-cell tipp-points <?php echo htmlspecialchars($td_class); ?>" title="<?php echo $title; ?>">
<?php echo htmlspecialchars($tipp['score2']); ?>
</td>
<td class="tipp-cell tipp-joker" title="<?php echo $title; ?>">
<?php if ($tipp['joker']): ?>
@ -240,6 +282,20 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<td></td>
<td class="result-label">Spielergebnis</td>
<td></td>
<td></td>
<td></td>
<?php foreach ($games as $game): ?>
<td class="text-center"><?php echo ((int)$game['score1'] > -1) ? (int)$game['score1'] : ''; ?></td>
<td class="text-center"><?php echo ((int)$game['score2'] > -1) ? (int)$game['score2'] : ''; ?></td>
<td></td>
<?php endforeach; ?>
</tr>
</tfoot>
</table>
<?php else: ?>
<p>Für diese Saison gibt es noch keine Rangliste (möglicherweise haben noch keine Spieler bezahlt).</p>

View file

@ -1,6 +1,7 @@
<?php
use App\Models\Game;
use App\Models\Tipp;
use App\Models\Team;
// Stellt sicher, dass die benötigten Variablen vorhanden sind
if (!isset($selectedRound) || !isset($roundsToShow) || !isset($users) || !isset($tipps_map)) {
@ -10,6 +11,16 @@ if (!isset($selectedRound) || !isset($roundsToShow) || !isset($users) || !isset(
$pageTitle = 'Tippübersicht - ' . htmlspecialchars($selectedRound['name']);
require __DIR__ . '/partials/header.php';
$teamLogo = function ($name) {
static $cache = [];
if (array_key_exists($name, $cache)) {
return $cache[$name];
}
$team = Team::resolve($name);
$cache[$name] = ($team && Team::logoExists($team)) ? Team::logoUrl($team) : null;
return $cache[$name];
};
?>
<h1>Tippübersicht bis: <?php echo htmlspecialchars($selectedRound['name']); ?></h1>
@ -27,7 +38,9 @@ require __DIR__ . '/partials/header.php';
<th>Spieler</th>
<?php foreach ($round['games'] as $game): ?>
<th class="game-header">
<?php $l1 = $teamLogo($game['team1']); if ($l1): ?><img src="<?php echo htmlspecialchars($l1); ?>" alt="" class="team-logo"><?php endif; ?>
<?php echo htmlspecialchars($game['team1']); ?><br>
<?php $l2 = $teamLogo($game['team2']); if ($l2): ?><img src="<?php echo htmlspecialchars($l2); ?>" alt="" class="team-logo"><?php endif; ?>
<?php echo htmlspecialchars($game['team2']); ?><br>
<small>(<?php echo Game::getResultString($game['score1'], $game['score2'], $game['kickoff']); ?>)</small>
</th>

View file

@ -1,11 +1,27 @@
<?php
use App\Models\Team;
$pageTitle = 'Spieltipp';
require __DIR__ . '/../partials/header.php';
$teamLogo = function ($name) {
static $cache = [];
if (array_key_exists($name, $cache)) {
return $cache[$name];
}
$team = Team::resolve($name);
$cache[$name] = ($team && Team::logoExists($team)) ? Team::logoUrl($team) : null;
return $cache[$name];
};
?>
<h1>Spieltipp:</h1>
<p><strong><?php echo htmlspecialchars($game['team1'] . ' : ' . $game['team2']); ?></strong></p>
<p><strong>
<span class="team-cell"><?php $l1 = $teamLogo($game['team1']); if ($l1): ?><img src="<?php echo htmlspecialchars($l1); ?>" alt="" class="team-logo"><?php endif; ?><?php echo htmlspecialchars($game['team1']); ?></span>
:
<span class="team-cell"><?php $l2 = $teamLogo($game['team2']); if ($l2): ?><img src="<?php echo htmlspecialchars($l2); ?>" alt="" class="team-logo"><?php endif; ?><?php echo htmlspecialchars($game['team2']); ?></span>
</strong></p>
<?php if ($error): ?>
<p style="color: red;"><?php echo htmlspecialchars($error); ?></p>

View file

@ -1,8 +1,19 @@
<?php
use App\Models\Tipp;
use App\Models\Team;
$pageTitle = 'Tipps';
require __DIR__ . '/../partials/header.php';
$teamLogo = function ($name) {
static $cache = [];
if (array_key_exists($name, $cache)) {
return $cache[$name];
}
$team = Team::resolve($name);
$cache[$name] = ($team && Team::logoExists($team)) ? Team::logoUrl($team) : null;
return $cache[$name];
};
?>
<p>Aktive Saison: <?php echo htmlspecialchars($activeSeason['name']); ?></p>
@ -37,7 +48,11 @@ require __DIR__ . '/../partials/header.php';
$tippText = $tipp1 > -1 ? $tipp1 . ' : ' . $tipp2 : null;
?>
<tr>
<td><?php echo htmlspecialchars($game['team1'] . ' : ' . $game['team2']); ?></td>
<td>
<span class="team-cell"><?php $l1 = $teamLogo($game['team1']); if ($l1): ?><img src="<?php echo htmlspecialchars($l1); ?>" alt="" class="team-logo"><?php endif; ?><?php echo htmlspecialchars($game['team1']); ?></span>
:
<span class="team-cell"><?php $l2 = $teamLogo($game['team2']); if ($l2): ?><img src="<?php echo htmlspecialchars($l2); ?>" alt="" class="team-logo"><?php endif; ?><?php echo htmlspecialchars($game['team2']); ?></span>
</td>
<td><?php echo date('d.m.Y H:i', strtotime($game['kickoff'])); ?></td>
<td><?php echo (int)$game['score1'] > -1 ? (int)$game['score1'] . ' : ' . (int)$game['score2'] : ''; ?></td>
<td>

View file

@ -1,6 +1,18 @@
<?php
use App\Models\Team;
$pageTitle = 'Runde tippen';
require __DIR__ . '/../partials/header.php';
$teamLogo = function ($name) {
static $cache = [];
if (array_key_exists($name, $cache)) {
return $cache[$name];
}
$team = Team::resolve($name);
$cache[$name] = ($team && Team::logoExists($team)) ? Team::logoUrl($team) : null;
return $cache[$name];
};
?>
<h2><?php echo htmlspecialchars($round['name']); ?></h2>
@ -19,9 +31,9 @@ require __DIR__ . '/../partials/header.php';
$gameId = (int)$game['id'];
?>
<tr>
<td><?php echo htmlspecialchars($game['team1']); ?></td>
<td><span class="team-cell"><?php $l1 = $teamLogo($game['team1']); if ($l1): ?><img src="<?php echo htmlspecialchars($l1); ?>" alt="" class="team-logo"><?php endif; ?><?php echo htmlspecialchars($game['team1']); ?></span></td>
<td>:</td>
<td><?php echo htmlspecialchars($game['team2']); ?></td>
<td><span class="team-cell"><?php $l2 = $teamLogo($game['team2']); if ($l2): ?><img src="<?php echo htmlspecialchars($l2); ?>" alt="" class="team-logo"><?php endif; ?><?php echo htmlspecialchars($game['team2']); ?></span></td>
<td class="score">
<input type="number" min="0" max="99" name="scores[<?php echo $gameId; ?>][score1]" required
value="<?php echo htmlspecialchars((string)($formScores[$gameId]['score1'] ?? '')); ?>">