Commit c2073097 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: rounds show player names + fix all JSONB json_decode crashes

1. Rounds tab now shows White | Result | Black columns with proper
   result badges (1-0, 0-1, ½-½) instead of raw enum strings.
2. BotSimulationService stores whiteName/blackName in results JSONB.
3. Fixed live-tournaments admin-controller and LiveDataService
   json_decode crashes on already-decoded JSONB arrays.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 19b137f9
......@@ -34,8 +34,10 @@ class LiveTournamentsAdminController
'order' => 'display_order.asc',
]);
$visibility = json_decode($tournament['live_visibility'] ?? '{}', true) ?: [];
$branding = json_decode($tournament['live_branding'] ?? '{}', true) ?: [];
$rawVis = $tournament['live_visibility'] ?? '{}';
$visibility = is_array($rawVis) ? $rawVis : (json_decode($rawVis, true) ?: []);
$rawBrand = $tournament['live_branding'] ?? '{}';
$branding = is_array($rawBrand) ? $rawBrand : (json_decode($rawBrand, true) ?: []);
$pageTitle = 'إعدادات الصفحة المباشرة - ' . $tournament['name'];
$moduleCSS = 'live-tournaments';
......
......@@ -21,7 +21,8 @@ class LiveDataService
public function getFullData(array $tournament): array
{
$id = $tournament['id'];
$visibility = json_decode($tournament['live_visibility'] ?? '{}', true) ?: [];
$rawVis = $tournament['live_visibility'] ?? '{}';
$visibility = is_array($rawVis) ? $rawVis : (json_decode($rawVis, true) ?: []);
$data = [
'tournament' => $this->sanitizeTournament($tournament),
......
......@@ -212,8 +212,10 @@ class BotSimulationService
$playersBody = SwissApiService::isSuccess($playersResp) ? SwissApiService::getBody($playersResp) : [];
$playersList = $playersBody['data'] ?? $playersBody ?? [];
$ratingsMap = [];
$namesMap = [];
foreach ($playersList as $p) {
$ratingsMap[$p['id']] = $p['fideRatingStandard'] ?? 1200;
$namesMap[$p['id']] = $p['name'] ?? '?';
}
// Get pairings
......@@ -233,20 +235,22 @@ class BotSimulationService
foreach ($pairings as $pairing) {
$pairingId = $pairing['id'];
$whiteId = $pairing['whitePlayerId'] ?? $pairing['white_player_id'] ?? '';
$blackId = $pairing['blackPlayerId'] ?? $pairing['black_player_id'] ?? '';
$whiteName = $namesMap[$whiteId] ?? '?';
$blackName = $namesMap[$blackId] ?? '?';
if (!empty($pairing['isBye']) || !empty($pairing['is_bye']) || empty($pairing['blackPlayerId'] ?? $pairing['black_player_id'])) {
$results[] = ['pairingId' => $pairingId, 'result' => 'bye_full'];
if (!empty($pairing['isBye']) || !empty($pairing['is_bye']) || empty($blackId)) {
$results[] = ['pairingId' => $pairingId, 'result' => 'bye_full', 'whiteName' => $whiteName, 'blackName' => 'BYE'];
$summary['byes']++;
continue;
}
$whiteId = $pairing['whitePlayerId'] ?? $pairing['white_player_id'] ?? '';
$blackId = $pairing['blackPlayerId'] ?? $pairing['black_player_id'] ?? '';
$ratingWhite = $ratingsMap[$whiteId] ?? 1200;
$ratingBlack = $ratingsMap[$blackId] ?? 1200;
$result = self::simulateResult($ratingWhite, $ratingBlack, $drawRate);
$results[] = ['pairingId' => $pairingId, 'result' => $result];
$results[] = ['pairingId' => $pairingId, 'result' => $result, 'whiteName' => $whiteName, 'blackName' => $blackName];
if ($result === 'white_wins') $summary['white_wins']++;
elseif ($result === 'black_wins') $summary['black_wins']++;
......
......@@ -321,14 +321,33 @@ $tabs['arbiter'] = 'أدوات الحكم';
<thead>
<tr>
<th>#</th>
<th>أبيض</th>
<th>النتيجة</th>
<th>أسود</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $idx => $r): ?>
<?php
$resultLabel = match($r['result'] ?? '') {
'white_wins' => '1 - 0',
'black_wins' => '0 - 1',
'draw' => '½ - ½',
'bye_full' => 'BYE',
default => $r['result'] ?? '-',
};
$resultClass = match($r['result'] ?? '') {
'white_wins' => 'badge-success',
'black_wins' => 'badge-danger',
'draw' => 'badge-warning',
default => 'badge-default',
};
?>
<tr>
<td><?= $idx + 1 ?></td>
<td><span class="badge badge-default"><?= $r['result'] ?? '-' ?></span></td>
<td class="font-medium"><?= View::e($r['whiteName'] ?? $r['white_name'] ?? '-') ?></td>
<td><span class="badge <?= $resultClass ?>"><?= $resultLabel ?></span></td>
<td class="font-medium"><?= View::e($r['blackName'] ?? $r['black_name'] ?? '-') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
......
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