Commit 10af61a4 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(live): prize table reads the {place, coins} list the form writes

Iterating a list of objects as a place => amount map passed an array to
htmlspecialchars() and broke the public page; places were also marked with
emoji. Both shapes are read now, places are medal icons.
Co-Authored-By: 's avatarClaude Opus 5.5 <noreply@anthropic.com>
parent bd0d91ef
<?php
$prizePool = $tournament['prize_pool'] ?? '';
$distribution = $tournament['prize_distribution'] ?? '';
if (is_string($distribution)) {
$distribution = json_decode($distribution, true) ?: [];
/**
* Prize table on the live page.
*
* prize_distribution is a list of {place, coins} (the manager's form writes
* that shape); an older {"1": 500, ...} map is read too. The previous version
* iterated a list of objects as if it were a map, which passed an array to
* htmlspecialchars() and broke the page, and it marked places with emoji.
*/
$prizePool = (int)($tournament['prize_pool_coins'] ?? $tournament['prize_pool'] ?? 0);
$raw = $tournament['prize_distribution'] ?? [];
if (is_string($raw)) $raw = json_decode($raw, true) ?: [];
$places = [];
foreach ((array)$raw as $k => $v) {
$place = is_array($v) ? (int)($v['place'] ?? 0) : (int)$k;
$coins = is_array($v) ? (int)($v['coins'] ?? 0) : (int)$v;
if ($place > 0 && $coins > 0) $places[$place] = $coins;
}
ksort($places);
$maxPrize = $places ? max($places) : 0;
$medalTone = [1 => 'var(--live-gold)', 2 => '#C9D1DC', 3 => '#D69A6B'];
?>
<div class="prizes-display">
<?php if ($prizePool): ?>
<?php if ($prizePool > 0): ?>
<div class="prize-total">
<span class="prize-total-label">إجمالي الجوائز</span>
<span class="prize-total-value"><?= htmlspecialchars($prizePool) ?></span>
<span class="prize-total-value"><?= number_format($prizePool) ?></span>
</div>
<?php endif; ?>
<?php if (!empty($distribution)): ?>
<?php if (!empty($places)): ?>
<div class="prize-podium">
<?php
$positions = ['first' => '🥇', 'second' => '🥈', 'third' => '🥉'];
$i = 0;
foreach ($distribution as $place => $prize):
$i++;
$medal = $positions[['first','second','third'][$i-1] ?? ''] ?? "#{$i}";
$maxPrize = max(array_values($distribution));
$pct = $maxPrize > 0 ? ($prize / $maxPrize) * 100 : 0;
?>
<?php foreach ($places as $place => $coins): ?>
<?php $pct = $maxPrize > 0 ? ($coins / $maxPrize) * 100 : 0; ?>
<div class="prize-bar-item">
<div class="prize-bar-info">
<span class="prize-medal"><?= $medal ?></span>
<span class="prize-place"><?= htmlspecialchars($place) ?></span>
<span class="prize-amount"><?= htmlspecialchars($prize) ?></span>
<span class="prize-medal" style="color: <?= $medalTone[$place] ?? 'var(--live-border)' ?>;" aria-hidden="true">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="9" r="6"/><path d="M8.5 14.5 7 22l5-3 5 3-1.5-7.5"/></svg>
</span>
<span class="prize-place">المركز <?= (int)$place ?></span>
<span class="prize-amount"><?= number_format($coins) ?></span>
</div>
<div class="prize-bar-track">
<div class="prize-bar-fill" style="width: <?= $pct ?>%"></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment