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