Resultadophp #13
+155
-290
@@ -1,291 +1,156 @@
|
|||||||
<!DOCTYPE html>
|
<?php
|
||||||
<html lang="es">
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/triviagmatico/includes/conexionBD.php';
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
$idPartida = intval($_GET['idPartida'] ?? 0);
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
if ($idPartida <= 0) {
|
||||||
|
die("Partida no válida.");
|
||||||
<title>Trivial - Resultado final</title>
|
}
|
||||||
|
|
||||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
$conexion = conexionBD();
|
||||||
|
if (is_array($conexion)) {
|
||||||
<link
|
die("Error de conexión a la base de datos.");
|
||||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
|
}
|
||||||
rel="stylesheet">
|
|
||||||
|
// Obtener listado de jugadores y sus equipos en esta partida
|
||||||
<!-- Bootstrap Icons -->
|
$stmt = $conexion->prepare("
|
||||||
<link
|
SELECT u.idUsuario, u.nombreUsuario, e.idEquipo, e.nombreEquipo
|
||||||
rel="stylesheet"
|
FROM equipoxpartida exp
|
||||||
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
INNER JOIN equipoxusuario exu ON exp.idEquipo = exu.idEquipo
|
||||||
|
INNER JOIN usuario u ON exu.idUsuario = u.idUsuario
|
||||||
<link
|
INNER JOIN equipo e ON exu.idEquipo = e.idEquipo
|
||||||
href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap"
|
WHERE exp.idPartida = :idPartida
|
||||||
rel="stylesheet">
|
");
|
||||||
|
$stmt->execute([':idPartida' => $idPartida]);
|
||||||
<link rel="stylesheet" href="css/index.css">
|
$listaJugadoresRaw = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
</head>
|
|
||||||
|
$primerosEnAcertar = $_SESSION['primeros_en_acertar'][$idPartida] ?? [];
|
||||||
<body>
|
|
||||||
|
$jugadoresFinales = [];
|
||||||
<?php
|
$equiposFinales = [];
|
||||||
include_once("cabecera.php");
|
|
||||||
?>
|
// Respuestas de velocidad (+2 o +1)
|
||||||
|
foreach ($listaJugadoresRaw as $jugador) {
|
||||||
<main class="container py-5">
|
$idU = (int)$jugador['idUsuario'];
|
||||||
|
$idE = (int)$jugador['idEquipo'];
|
||||||
<!-- Título -->
|
|
||||||
<div class="text-center mb-5">
|
$stmtRespuestas = $conexion->prepare("
|
||||||
|
SELECT ra.idPartidaxPregunta, r.correcta
|
||||||
<div class="trophy-icon">
|
FROM respuestaalmacenada ra
|
||||||
<i class="bi bi-trophy-fill"></i>
|
INNER JOIN respuesta r ON ra.idRespuesta = r.idRespuesta
|
||||||
</div>
|
INNER JOIN partidaxpregunta pxp ON ra.idPartidaxPregunta = pxp.idPartidaxPregunta
|
||||||
|
WHERE pxp.idPartida = :idPartida AND ra.idUsuario = :idUsuario
|
||||||
<h1 class="fw-bold">
|
");
|
||||||
¡Trivial terminado!
|
$stmtRespuestas->execute([':idPartida' => $idPartida, ':idUsuario' => $idU]);
|
||||||
</h1>
|
$respuestasUsuario = $stmtRespuestas->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
<p class="text-muted fs-5 mb-0">
|
$aciertos = 0;
|
||||||
Estos son los resultados finales
|
$puntosTotalesJugador = 0;
|
||||||
</p>
|
|
||||||
|
foreach ($respuestasUsuario as $resp) {
|
||||||
</div>
|
if ((int)$resp['correcta'] === 1) {
|
||||||
|
$aciertos++;
|
||||||
|
$idPxp = $resp['idPartidaxPregunta'];
|
||||||
<!-- Equipo ganador -->
|
|
||||||
<section class="row justify-content-center mb-5">
|
// Si el ID de usuario coincide con el primero guardado de esa pregunta se lleva 2 puntos
|
||||||
|
if (isset($primerosEnAcertar[$idPxp]) && $primerosEnAcertar[$idPxp] === $idU) {
|
||||||
<div class="col-12 col-lg-8">
|
$puntosTotalesJugador += 2;
|
||||||
|
} else {
|
||||||
<div class="ranking-card">
|
$puntosTotalesJugador += 1;
|
||||||
|
}
|
||||||
<div class="ranking-header text-center">
|
}
|
||||||
<i class="bi bi-trophy-fill me-2"></i>
|
}
|
||||||
Equipo ganador
|
|
||||||
</div>
|
$jugadoresFinales[] = [
|
||||||
|
'nombre' => $jugador['nombreUsuario'],
|
||||||
<div class="card-body text-center p-4">
|
'equipo' => $jugador['nombreEquipo'],
|
||||||
|
'aciertos' => $aciertos,
|
||||||
<h2 class="fw-bold mb-2">
|
'puntos' => $puntosTotalesJugador
|
||||||
Los Cerebritos
|
];
|
||||||
</h2>
|
|
||||||
|
if (!isset($equiposFinales[$idE])) {
|
||||||
<div class="display-3 fw-bold mb-3">
|
$equiposFinales[$idE] = [
|
||||||
850
|
'nombre' => $jugador['nombreEquipo'],
|
||||||
<span class="fs-4 text-muted">
|
'puntos' => 0
|
||||||
puntos
|
];
|
||||||
</span>
|
}
|
||||||
</div>
|
$equiposFinales[$idE]['puntos'] += $puntosTotalesJugador;
|
||||||
|
}
|
||||||
<p class="text-muted mb-0">
|
|
||||||
<i class="bi bi-stars me-1"></i>
|
// Ordenar según la puntuación final de mayor a menor
|
||||||
¡Enhorabuena por la victoria!
|
usort($jugadoresFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
||||||
</p>
|
usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
||||||
|
?>
|
||||||
</div>
|
|
||||||
|
<!DOCTYPE html>
|
||||||
</div>
|
<html lang="es">
|
||||||
|
<head>
|
||||||
</div>
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
</section>
|
<title>Resultados - Trivial</title>
|
||||||
|
<link rel="stylesheet" href="css/resultados.css">
|
||||||
|
<script src="https://jquery.com"></script>
|
||||||
<!-- Resultados de los dos equipos -->
|
</head>
|
||||||
<section class="row justify-content-center g-4">
|
<body data-id-partida="<?php echo $idPartida; ?>">
|
||||||
|
|
||||||
<!-- EQUIPO GANADOR -->
|
<div id="pantalla-espera" class="contenedor">
|
||||||
<div class="col-12 col-lg-6">
|
<h2>⌛ Esperando a que todos los jugadores terminen...</h2>
|
||||||
|
<p>Calculando estadísticas de velocidad y actualizando perfiles históricos en el servidor.</p>
|
||||||
<div class="ranking-card h-100">
|
<div class="loader"></div>
|
||||||
|
</div>
|
||||||
<div class="ranking-header d-flex justify-content-between align-items-center">
|
|
||||||
|
<div id="pantalla-resultados" class="contenedor" style="display:none;">
|
||||||
<span>
|
<h1>🏆 Resultados de la Partida 🏆</h1>
|
||||||
Los Cerebritos
|
|
||||||
</span>
|
<h2>Clasificación por Equipos</h2>
|
||||||
|
<table class="tabla-ranking">
|
||||||
<span>
|
<thead>
|
||||||
<i class="bi bi-trophy-fill"></i>
|
<tr>
|
||||||
</span>
|
<th>Posición</th>
|
||||||
|
<th>Equipo</th>
|
||||||
</div>
|
<th>Puntos Totales</th>
|
||||||
|
</tr>
|
||||||
<div class="card-body p-4">
|
</thead>
|
||||||
|
<tbody>
|
||||||
<div class="text-center mb-4">
|
<?php foreach ($equiposFinales as $index => $eq): ?>
|
||||||
|
<tr class="<?php echo $index === 0 ? 'top-team' : ''; ?>">
|
||||||
<div class="fs-1 fw-bold">
|
<td>#<?php echo $index + 1; ?></td>
|
||||||
850
|
<td><?php echo htmlspecialchars($eq['nombre']); ?></td>
|
||||||
</div>
|
<td><strong><?php echo $eq['puntos']; ?> pts</strong></td>
|
||||||
|
</tr>
|
||||||
<div class="text-muted">
|
<?php endforeach; ?>
|
||||||
puntos
|
</tbody>
|
||||||
</div>
|
</table>
|
||||||
|
|
||||||
</div>
|
<h2>Rendimiento Individual</h2>
|
||||||
|
<table class="tabla-ranking">
|
||||||
<h5 class="fw-bold mb-3">
|
<thead>
|
||||||
<i class="bi bi-people-fill me-2"></i>
|
<tr>
|
||||||
Jugadores
|
<th>Posición</th>
|
||||||
</h5>
|
<th>Jugador</th>
|
||||||
|
<th>Equipo</th>
|
||||||
<ul class="list-group">
|
<th>Aciertos</th>
|
||||||
|
<th>Puntos Logrados</th>
|
||||||
<li class="list-group-item">
|
</tr>
|
||||||
1. Carlos
|
</thead>
|
||||||
</li>
|
<tbody>
|
||||||
|
<?php foreach ($jugadoresFinales as $index => $jug): ?>
|
||||||
<li class="list-group-item">
|
<tr class="<?php echo $index === 0 ? 'top-player' : ''; ?>">
|
||||||
2. Marta
|
<td>#<?php echo $index + 1; ?></td>
|
||||||
</li>
|
<td><?php echo htmlspecialchars($jug['nombre']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($jug['equipo']); ?></td>
|
||||||
<li class="list-group-item">
|
<td><?php echo $jug['aciertos']; ?> / 10</td>
|
||||||
3. Pablo
|
<td><strong><?php echo $jug['puntos']; ?> pts</strong></td>
|
||||||
</li>
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
<li class="list-group-item">
|
</tbody>
|
||||||
4. Laura
|
</table>
|
||||||
</li>
|
|
||||||
|
<div class="contenedor-boton">
|
||||||
<li class="list-group-item">
|
<a href="/triviagmatico/buscadorSala.php" class="btn-inicio">Volver al Inicio 🏠</a>
|
||||||
5. David
|
</div>
|
||||||
</li>
|
</div>
|
||||||
|
|
||||||
<li class="list-group-item">
|
<script src="js/resultados.js"></script>
|
||||||
6. Ana
|
</body>
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
7. Sergio
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
8. Lucía
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
9. Miguel
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
10. Elena
|
|
||||||
</li>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- EQUIPO PERDEDOR -->
|
|
||||||
<div class="col-12 col-lg-6">
|
|
||||||
|
|
||||||
<div class="ranking-card h-100">
|
|
||||||
|
|
||||||
<!-- Cabecera plateada -->
|
|
||||||
<div
|
|
||||||
class="ranking-header d-flex justify-content-between align-items-center"
|
|
||||||
style="background-color: #c0c0c0;">
|
|
||||||
|
|
||||||
<span>
|
|
||||||
Los Campeones
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<span>
|
|
||||||
<i class="bi bi-award-fill"></i>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card-body p-4">
|
|
||||||
|
|
||||||
<div class="text-center mb-4">
|
|
||||||
|
|
||||||
<div class="fs-1 fw-bold">
|
|
||||||
720
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="text-muted">
|
|
||||||
puntos
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h5 class="fw-bold mb-3">
|
|
||||||
<i class="bi bi-people-fill me-2"></i>
|
|
||||||
Jugadores
|
|
||||||
</h5>
|
|
||||||
|
|
||||||
<ul class="list-group">
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
1. Javier
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
2. Sofía
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
3. Diego
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
4. María
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
5. Alejandro
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
6. Paula
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
7. Álvaro
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="list-group-item">
|
|
||||||
8. Carmen
|
|
||||||
</li>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Volver al buscador -->
|
|
||||||
<div class="text-center mt-5">
|
|
||||||
|
|
||||||
<a
|
|
||||||
href="buscadorSala.php"
|
|
||||||
class="btn btn-play-kahoot">
|
|
||||||
|
|
||||||
<i class="bi bi-arrow-left-circle-fill"></i>
|
|
||||||
|
|
||||||
Volver al buscador de salas
|
|
||||||
|
|
||||||
</a>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</main>
|
|
||||||
|
|
||||||
|
|
||||||
<script
|
|
||||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js">
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user