Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a41c04daf | |||
| 060ea53992 | |||
| a8a4699bd4 | |||
| 85e5c2fc0b | |||
| b58db59f93 | |||
| 9ec2222d78 | |||
| 7344a0c31f | |||
| 645e2abc77 | |||
| d9020a66c6 | |||
| 9d59a9cc7c | |||
| 8ffb769861 | |||
| 1c3fbf2f90 | |||
| cd53cba69e | |||
| 5f407ce8f4 | |||
| d20b1fa7d7 | |||
| 02e725e0f3 | |||
| 3856db81ef | |||
| bdc7bef169 | |||
| 963ab50f37 | |||
| 9488d7cee7 | |||
| cbdbd8bc4b |
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/triviagmatico/includes/conexionBD.php';
|
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
class Categoria{
|
class Categoria{
|
||||||
|
|
||||||
|
|||||||
@@ -229,7 +229,13 @@ class Juego
|
|||||||
* - la respuesta pertenece a esa pregunta
|
* - la respuesta pertenece a esa pregunta
|
||||||
* - el usuario no ha respondido ya esa pregunta
|
* - el usuario no ha respondido ya esa pregunta
|
||||||
*/
|
*/
|
||||||
public static function registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta)
|
public static function registrarRespuesta(
|
||||||
|
$idPartida,
|
||||||
|
$idUsuario,
|
||||||
|
$idPartidaxPregunta,
|
||||||
|
$idRespuesta,
|
||||||
|
$tiempoRespuesta
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
@@ -298,7 +304,8 @@ class Juego
|
|||||||
null,
|
null,
|
||||||
$idPartidaxPregunta,
|
$idPartidaxPregunta,
|
||||||
$idUsuario,
|
$idUsuario,
|
||||||
$idRespuesta
|
$idRespuesta,
|
||||||
|
$tiempoRespuesta
|
||||||
);
|
);
|
||||||
$guardado = $almacenada->guardarRespuesta();
|
$guardado = $almacenada->guardarRespuesta();
|
||||||
|
|
||||||
|
|||||||
+35
-19
@@ -132,27 +132,43 @@ class Partida
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function iniciarPartida(){
|
public function iniciarPartida()
|
||||||
$conexion = conexionBD();
|
{
|
||||||
if (is_array($conexion)){
|
$conexion = conexionBD();
|
||||||
return $conexion;
|
|
||||||
}
|
if (is_array($conexion)) {
|
||||||
try {
|
return $conexion;
|
||||||
$consulta = $conexion->prepare("UPDATE partida SET fechaInicio=NOW() WHERE idPartida=:idPartida AND fechaInicio IS NULL");
|
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
|
||||||
$consulta->execute();
|
|
||||||
return [
|
|
||||||
"exito" => "La partida ha comenzado.",
|
|
||||||
"exito_tecnico" => $this->idPartida
|
|
||||||
];
|
|
||||||
} catch (PDOException $error) {
|
|
||||||
return [
|
|
||||||
"error" => "Ocurrió un error al iniciar la partida.",
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$consulta = $conexion->prepare("
|
||||||
|
UPDATE partida
|
||||||
|
SET fechaInicio = NOW()
|
||||||
|
WHERE idPartida = :idPartida
|
||||||
|
AND fechaInicio IS NULL
|
||||||
|
");
|
||||||
|
|
||||||
|
$consulta->bindParam(
|
||||||
|
":idPartida",
|
||||||
|
$this->idPartida
|
||||||
|
);
|
||||||
|
|
||||||
|
$consulta->execute();
|
||||||
|
|
||||||
|
return [
|
||||||
|
"exito" => "La partida ha comenzado.",
|
||||||
|
"exito_tecnico" => $this->idPartida
|
||||||
|
];
|
||||||
|
|
||||||
|
} catch (PDOException $error) {
|
||||||
|
|
||||||
|
return [
|
||||||
|
"error" => "ERROR REAL: " . $error->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function finalizar(){
|
public function finalizar(){
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class Respuesta{
|
|||||||
$consulta->bindParam(':idPregunta', $this->idPregunta);
|
$consulta->bindParam(':idPregunta', $this->idPregunta);
|
||||||
$consulta->bindParam(':nombreRespuesta', $this->nombreRespuesta);
|
$consulta->bindParam(':nombreRespuesta', $this->nombreRespuesta);
|
||||||
$consulta->bindParam(':correcta', $this->correcta);
|
$consulta->bindParam(':correcta', $this->correcta);
|
||||||
|
|
||||||
|
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
$respuesta = [
|
$respuesta = [
|
||||||
'exito' => 'La respuesta se guardó correctamente.',
|
'exito' => 'La respuesta se guardó correctamente.',
|
||||||
|
|||||||
@@ -7,43 +7,53 @@ class RespuestaAlmacenada {
|
|||||||
public $idPartidaxPregunta;
|
public $idPartidaxPregunta;
|
||||||
public $idUsuario;
|
public $idUsuario;
|
||||||
public $idRespuesta;
|
public $idRespuesta;
|
||||||
|
public $tiempoRespuesta;
|
||||||
|
|
||||||
public function __construct($idRespuestaAlmacenada = null, $idPartidaxPregunta = null, $idUsuario = null, $idRespuesta = null) {
|
public function __construct($idRespuestaAlmacenada = null, $idPartidaxPregunta = null, $idUsuario = null, $idRespuesta = null, $tiempoRespuesta = null) {
|
||||||
$this->idRespuestaAlmacenada = $idRespuestaAlmacenada;
|
$this->idRespuestaAlmacenada = $idRespuestaAlmacenada;
|
||||||
$this->idPartidaxPregunta = $idPartidaxPregunta;
|
$this->idPartidaxPregunta = $idPartidaxPregunta;
|
||||||
$this->idUsuario = $idUsuario;
|
$this->idUsuario = $idUsuario;
|
||||||
$this->idRespuesta = $idRespuesta;
|
$this->idRespuesta = $idRespuesta;
|
||||||
|
$this->tiempoRespuesta = $tiempoRespuesta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guarda la respuesta que ha seleccionado un usuario en una pregunta de la partida.
|
* Guarda la respuesta que ha seleccionado un usuario en una pregunta de la partida.
|
||||||
*/
|
*/
|
||||||
public function guardarRespuesta() {
|
public function guardarRespuesta() {
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) return $conexion;
|
|
||||||
|
|
||||||
try {
|
if (is_array($conexion)) {
|
||||||
$sql = "INSERT INTO respuestaalmacenada (idPartidaxPregunta, idUsuario, idRespuesta)
|
return $conexion;
|
||||||
VALUES (:idPartidaxPregunta, :idUsuario, :idRespuesta)";
|
|
||||||
$consulta = $conexion->prepare($sql);
|
|
||||||
|
|
||||||
$consulta->bindParam(':idPartidaxPregunta', $this->idPartidaxPregunta);
|
|
||||||
$consulta->bindParam(':idUsuario', $this->idUsuario);
|
|
||||||
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
|
||||||
$consulta->execute();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'exito' => 'Respuesta del usuario almacenada correctamente.',
|
|
||||||
'exito_tecnico' => $conexion->lastInsertId()
|
|
||||||
];
|
|
||||||
} catch (PDOException $error) {
|
|
||||||
return [
|
|
||||||
'error' => 'Ocurrió un error al guardar la respuesta del jugador.',
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$sql = "INSERT INTO respuestaalmacenada
|
||||||
|
(idPartidaxPregunta, idUsuario, idRespuesta, tiempoRespuesta)
|
||||||
|
VALUES
|
||||||
|
(:idPartidaxPregunta, :idUsuario, :idRespuesta, :tiempoRespuesta)";
|
||||||
|
|
||||||
|
$consulta = $conexion->prepare($sql);
|
||||||
|
|
||||||
|
$consulta->bindParam(':idPartidaxPregunta', $this->idPartidaxPregunta);
|
||||||
|
$consulta->bindParam(':idUsuario', $this->idUsuario);
|
||||||
|
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
|
||||||
|
$consulta->bindParam(':tiempoRespuesta', $this->tiempoRespuesta);
|
||||||
|
|
||||||
|
$consulta->execute();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'exito' => 'Respuesta almacenada correctamente.'
|
||||||
|
];
|
||||||
|
|
||||||
|
} catch (PDOException $error) {
|
||||||
|
return [
|
||||||
|
'error' => 'Ocurrió un error al guardar la respuesta.',
|
||||||
|
'error_tecnico' => $error->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtiene los aciertos totales de un usuario en una partida específica.
|
* Obtiene los aciertos totales de un usuario en una partida específica.
|
||||||
* Útil para calcular las estadísticas individuales al terminar el juego.
|
* Útil para calcular las estadísticas individuales al terminar el juego.
|
||||||
|
|||||||
@@ -74,34 +74,47 @@ switch ($orden) {
|
|||||||
|
|
||||||
case 'responder':
|
case 'responder':
|
||||||
|
|
||||||
if (!isset($_POST['idPartidaxPregunta']) || !isset($_POST['idRespuesta'])){
|
if (
|
||||||
echo json_encode([
|
!isset($_POST['idPartidaxPregunta']) ||
|
||||||
'error' => 'Faltan datos para registrar la respuesta.'
|
!isset($_POST['idRespuesta']) ||
|
||||||
]);
|
!isset($_POST['tiempoRespuesta'])
|
||||||
|
) {
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'Faltan datos para registrar la respuestfdfa.'
|
||||||
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
|
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
|
||||||
|
$idRespuesta = intval($_POST['idRespuesta']);
|
||||||
|
$tiempoRespuesta = intval($_POST['tiempoRespuesta']);
|
||||||
|
|
||||||
$idRespuesta = intval($_POST['idRespuesta']);
|
if (
|
||||||
|
$idPartidaxPregunta <= 0 ||
|
||||||
if ($idPartidaxPregunta <= 0 || $idRespuesta <= 0){
|
$idRespuesta <= 0 ||
|
||||||
|
$tiempoRespuesta < 0
|
||||||
echo json_encode([
|
) {
|
||||||
'error' => 'Los datos de la respuesta no son válidos.'
|
echo json_encode([
|
||||||
]);
|
'error' => 'Los datos de la respuesta no son válidos.'
|
||||||
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registramos la respuesta del usuario
|
// Registramos la respuesta del usuario junto con su tiempo de respuesta
|
||||||
|
|
||||||
$resultado = Juego::registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta);
|
$resultado = Juego::registrarRespuesta(
|
||||||
|
$idPartida,
|
||||||
|
$idUsuario,
|
||||||
|
$idPartidaxPregunta,
|
||||||
|
$idRespuesta,
|
||||||
|
$tiempoRespuesta
|
||||||
|
);
|
||||||
|
|
||||||
echo json_encode($resultado);
|
echo json_encode($resultado);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Finalizar la partida y registrar los aciertos del usuario
|
// Finalizar la partida y registrar los aciertos del usuario
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ switch ($_POST['orden']) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ==========================================
|
* ==========================================
|
||||||
* 3. INSERTAMOS LOS EQUIPOS CON SU PARTIDA EN EQUIPOXPARTIDA
|
* 3. INSERTAMOS LOS EQUIPOS CON SU PARTIDA EN EQUIPOXPARTIDA
|
||||||
* ==========================================
|
* ==========================================
|
||||||
@@ -220,9 +220,9 @@ switch ($_POST['orden']) {
|
|||||||
* 5. ASIGNAMOS 10 PREGUNTAS ALEATORIAS A LA PARTIDA
|
* 5. ASIGNAMOS 10 PREGUNTAS ALEATORIAS A LA PARTIDA
|
||||||
* ==========================================
|
* ==========================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Obtenemos todos los IDs de las preguntas
|
// Obtenemos todos los IDs de las preguntas
|
||||||
|
|
||||||
$listaPreguntas = Pregunta::getTodosIds();
|
$listaPreguntas = Pregunta::getTodosIds();
|
||||||
|
|
||||||
$totalPreguntas = count($listaPreguntas);
|
$totalPreguntas = count($listaPreguntas);
|
||||||
@@ -246,7 +246,7 @@ switch ($_POST['orden']) {
|
|||||||
// Asignamos el ID real de la pregunta a la partida
|
// Asignamos el ID real de la pregunta a la partida
|
||||||
$partida->asignarPregunta($idPreguntaAleatoria);
|
$partida->asignarPregunta($idPreguntaAleatoria);
|
||||||
}
|
}
|
||||||
}//fin shile
|
} //fin shile
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -795,13 +795,47 @@ switch ($_POST['orden']) {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$resultado = $partida->iniciar();
|
$resultado = $partida->iniciarPartida();
|
||||||
|
|
||||||
|
|
||||||
echo json_encode($resultado);
|
echo json_encode($resultado);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'comprobarInicio':
|
||||||
|
|
||||||
|
if (!isset($_POST['idPartida'])) {
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'No se ha indicado la partida.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$partida = new Partida();
|
||||||
|
|
||||||
|
$partida->idPartida =
|
||||||
|
intval($_POST['idPartida']);
|
||||||
|
|
||||||
|
$datosPartida = $partida->buscar();
|
||||||
|
|
||||||
|
if (!$datosPartida || isset($datosPartida['error'])) {
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'La partida no existe.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'iniciada' => $datosPartida['fechaInicio'] !== null
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// OBTENER LA PREGUNTA ACTUAL
|
// OBTENER LA PREGUNTA ACTUAL
|
||||||
@@ -933,7 +967,7 @@ switch ($_POST['orden']) {
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'error' => 'Faltan datos para registrar la respuesta.'
|
'error' => 'Faltan datos para registrar la respuestadd.'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// controladores/controladorResultados.php
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
if (!isset($_SESSION['idUsuario'])) {
|
if (!isset($_SESSION['idUsuario'])) {
|
||||||
@@ -26,7 +26,6 @@ if (is_array($conexion)) {
|
|||||||
switch ($orden) {
|
switch ($orden) {
|
||||||
case 'comprobarEstado':
|
case 'comprobarEstado':
|
||||||
try {
|
try {
|
||||||
// 1. Contar cuántos jugadores hay asignados en esta partida
|
|
||||||
$stmt = $conexion->prepare("
|
$stmt = $conexion->prepare("
|
||||||
SELECT COUNT(exu.idUsuario) AS total_jugadores
|
SELECT COUNT(exu.idUsuario) AS total_jugadores
|
||||||
FROM equipoxpartida exp
|
FROM equipoxpartida exp
|
||||||
@@ -38,7 +37,6 @@ switch ($orden) {
|
|||||||
|
|
||||||
$preguntasTotalesEsperadas = $totalJugadores * 10;
|
$preguntasTotalesEsperadas = $totalJugadores * 10;
|
||||||
|
|
||||||
// 2. Contar cuántas respuestas reales se han guardado
|
|
||||||
$stmtRespuestas = $conexion->prepare("
|
$stmtRespuestas = $conexion->prepare("
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM respuestaalmacenada ra
|
FROM respuestaalmacenada ra
|
||||||
@@ -50,12 +48,9 @@ switch ($orden) {
|
|||||||
|
|
||||||
$terminada = ($respuestasRespondidas >= $preguntasTotalesEsperadas && $preguntasTotalesEsperadas > 0);
|
$terminada = ($respuestasRespondidas >= $preguntasTotalesEsperadas && $preguntasTotalesEsperadas > 0);
|
||||||
|
|
||||||
// 3. Si ha terminado, guardamos los datos históricos una sola vez
|
if ($terminada && !isset($_SESSION['partidas_processed'][$idPartida])) {
|
||||||
if ($terminada && !isset($_SESSION['partidas_procesadas'][$idPartida])) {
|
|
||||||
|
|
||||||
$conexion->beginTransaction();
|
$conexion->beginTransaction();
|
||||||
|
|
||||||
// --- CÁLCULO DE VELOCIDAD ---
|
|
||||||
if (!isset($_SESSION['primeros_en_acertar'][$idPartida])) {
|
if (!isset($_SESSION['primeros_en_acertar'][$idPartida])) {
|
||||||
$_SESSION['primeros_en_acertar'][$idPartida] = [];
|
$_SESSION['primeros_en_acertar'][$idPartida] = [];
|
||||||
}
|
}
|
||||||
@@ -74,13 +69,11 @@ switch ($orden) {
|
|||||||
foreach ($todosLosAciertos as $acierto) {
|
foreach ($todosLosAciertos as $acierto) {
|
||||||
$idPxp = $acierto['idPartidaxPregunta'];
|
$idPxp = $acierto['idPartidaxPregunta'];
|
||||||
$idU = $acierto['idUsuario'];
|
$idU = $acierto['idUsuario'];
|
||||||
|
|
||||||
if (!isset($_SESSION['primeros_en_acertar'][$idPartida][$idPxp])) {
|
if (!isset($_SESSION['primeros_en_acertar'][$idPartida][$idPxp])) {
|
||||||
$_SESSION['primeros_en_acertar'][$idPartida][$idPxp] = $idU;
|
$_SESSION['primeros_en_acertar'][$idPartida][$idPxp] = $idU;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consulta de aciertos
|
|
||||||
$stmtAciertos = $conexion->prepare("
|
$stmtAciertos = $conexion->prepare("
|
||||||
SELECT ra.idUsuario, exu.idEquipo, COUNT(*) as aciertos_partida
|
SELECT ra.idUsuario, exu.idEquipo, COUNT(*) as aciertos_partida
|
||||||
FROM respuestaalmacenada ra
|
FROM respuestaalmacenada ra
|
||||||
@@ -93,11 +86,7 @@ switch ($orden) {
|
|||||||
$stmtAciertos->execute([':idPartida' => $idPartida]);
|
$stmtAciertos->execute([':idPartida' => $idPartida]);
|
||||||
$jugadoresPartida = $stmtAciertos->fetchAll(PDO::FETCH_ASSOC);
|
$jugadoresPartida = $stmtAciertos->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$updateAciertos = $conexion->prepare("
|
$updateAciertos = $conexion->prepare("UPDATE usuario SET aciertos = aciertos + :nuevos_aciertos WHERE idUsuario = :idUsuario");
|
||||||
UPDATE usuario
|
|
||||||
SET aciertos = aciertos + :nuevos_aciertos
|
|
||||||
WHERE idUsuario = :idUsuario
|
|
||||||
");
|
|
||||||
|
|
||||||
$puntosEquipos = [];
|
$puntosEquipos = [];
|
||||||
foreach ($jugadoresPartida as $jp) {
|
foreach ($jugadoresPartida as $jp) {
|
||||||
@@ -105,14 +94,9 @@ switch ($orden) {
|
|||||||
$idE = (int)$jp['idEquipo'];
|
$idE = (int)$jp['idEquipo'];
|
||||||
$nuevosAciertos = (int)$jp['aciertos_partida'];
|
$nuevosAciertos = (int)$jp['aciertos_partida'];
|
||||||
|
|
||||||
$updateAciertos->execute([
|
$updateAciertos->execute([':nuevos_aciertos' => $nuevosAciertos, ':idUsuario' => $idU]);
|
||||||
':nuevos_aciertos' => $nuevosAciertos,
|
|
||||||
':idUsuario' => $idU
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!isset($puntosEquipos[$idE])) {
|
if (!isset($puntosEquipos[$idE])) { $puntosEquipos[$idE] = 0; }
|
||||||
$puntosEquipos[$idE] = 0;
|
|
||||||
}
|
|
||||||
$puntosEquipos[$idE] += $nuevosAciertos;
|
$puntosEquipos[$idE] += $nuevosAciertos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +119,6 @@ switch ($orden) {
|
|||||||
foreach ($todosLosMiembros as $miembro) {
|
foreach ($todosLosMiembros as $miembro) {
|
||||||
$idU = (int)$miembro['idUsuario'];
|
$idU = (int)$miembro['idUsuario'];
|
||||||
$idE = (int)$miembro['idEquipo'];
|
$idE = (int)$miembro['idEquipo'];
|
||||||
|
|
||||||
if ($idE === $idEquipoGanador) {
|
if ($idE === $idEquipoGanador) {
|
||||||
$updateVictoria->execute([':idUsuario' => $idU]);
|
$updateVictoria->execute([':idUsuario' => $idU]);
|
||||||
} else {
|
} else {
|
||||||
@@ -144,37 +127,27 @@ switch ($orden) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marcar fecha fin de la partida para los históricos globales del grupo
|
$stmtFinalizar = $conexion->prepare("UPDATE partida SET fechaFin = NOW() WHERE idPartida = :idPartida AND fechaFin IS NULL");
|
||||||
$stmtFinalizar = $conexion->prepare("
|
|
||||||
UPDATE partida
|
|
||||||
SET fechaFin = NOW()
|
|
||||||
WHERE idPartida = :idPartida AND fechaFin IS NULL
|
|
||||||
");
|
|
||||||
$stmtFinalizar->execute([':idPartida' => $idPartida]);
|
$stmtFinalizar->execute([':idPartida' => $idPartida]);
|
||||||
|
|
||||||
$conexion->commit();
|
$conexion->commit();
|
||||||
$_SESSION['partidas_procesadas'][$idPartida] = true;
|
$_SESSION['partidas_procesadas'][$idPartida] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode(['terminada' => $terminada]);
|
echo json_encode(['terminada' => $terminada]);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
if ($conexion->inTransaction()) {
|
if ($conexion->inTransaction()) { $conexion->rollBack(); }
|
||||||
$conexion->rollBack();
|
|
||||||
}
|
|
||||||
echo json_encode(['error' => $e->getMessage()]);
|
echo json_encode(['error' => $e->getMessage()]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'registrarSalidaUsuario':
|
case 'registrarSalidaUsuario':
|
||||||
try {
|
try {
|
||||||
$idUsuario = (int)$_SESSION['idUsuario'];
|
$idUsuario = (int)$_SESSION['idUsuario'];
|
||||||
$conexion->beginTransaction();
|
$conexion->beginTransaction();
|
||||||
|
|
||||||
// A. LIBERACIÓN INMEDIATA DEL JUGADOR ACTUAL: Lo borramos de su equipo
|
|
||||||
$stmtSalir = $conexion->prepare("DELETE FROM equipoxusuario WHERE idUsuario = :idUsuario");
|
$stmtSalir = $conexion->prepare("DELETE FROM equipoxusuario WHERE idUsuario = :idUsuario");
|
||||||
$stmtSalir->execute([':idUsuario' => $idUsuario]);
|
$stmtSalir->execute([':idUsuario' => $idUsuario]);
|
||||||
|
|
||||||
// B. CONTADOR DE ALUMNOS QUEDAN: Contamos cuántas personas quedan en los equipos de esta partida
|
|
||||||
$stmtContarQuedan = $conexion->prepare("
|
$stmtContarQuedan = $conexion->prepare("
|
||||||
SELECT COUNT(exu.idUsuario)
|
SELECT COUNT(exu.idUsuario)
|
||||||
FROM equipoxpartida exp
|
FROM equipoxpartida exp
|
||||||
@@ -184,9 +157,7 @@ switch ($orden) {
|
|||||||
$stmtContarQuedan->execute([':idPartida' => $idPartida]);
|
$stmtContarQuedan->execute([':idPartida' => $idPartida]);
|
||||||
$jugadoresRestantes = (int)$stmtContarQuedan->fetchColumn();
|
$jugadoresRestantes = (int)$stmtContarQuedan->fetchColumn();
|
||||||
|
|
||||||
// C. DESTRUCCIÓN EN CADENA AUTOMÁTICA ATÓMICA (Si da 0, somos los últimos en salir)
|
|
||||||
if ($jugadoresRestantes === 0) {
|
if ($jugadoresRestantes === 0) {
|
||||||
// 1. Limpiar las respuestas almacenadas
|
|
||||||
$stmtBorrarRespuestas = $conexion->prepare("
|
$stmtBorrarRespuestas = $conexion->prepare("
|
||||||
DELETE ra FROM respuestaalmacenada ra
|
DELETE ra FROM respuestaalmacenada ra
|
||||||
INNER JOIN partidaxpregunta pxp ON ra.idPartidaxPregunta = pxp.idPartidaxPregunta
|
INNER JOIN partidaxpregunta pxp ON ra.idPartidaxPregunta = pxp.idPartidaxPregunta
|
||||||
@@ -194,29 +165,22 @@ switch ($orden) {
|
|||||||
");
|
");
|
||||||
$stmtBorrarRespuestas->execute([':idPartida' => $idPartida]);
|
$stmtBorrarRespuestas->execute([':idPartida' => $idPartida]);
|
||||||
|
|
||||||
// 2. Limpiar las preguntas vinculadas a la partida
|
|
||||||
$stmtBorrarPreguntas = $conexion->prepare("DELETE FROM partidaxpregunta WHERE idPartida = :idPartida");
|
$stmtBorrarPreguntas = $conexion->prepare("DELETE FROM partidaxpregunta WHERE idPartida = :idPartida");
|
||||||
$stmtBorrarPreguntas->execute([':idPartida' => $idPartida]);
|
$stmtBorrarPreguntas->execute([':idPartida' => $idPartida]);
|
||||||
|
|
||||||
// 3. NUEVO: Obtener los IDs de los dos equipos que jugaban en esta partida antes de borrar la relación
|
|
||||||
$stmtObtenerEquipos = $conexion->prepare("SELECT idEquipo FROM equipoxpartida WHERE idPartida = :idPartida");
|
$stmtObtenerEquipos = $conexion->prepare("SELECT idEquipo FROM equipoxpartida WHERE idPartida = :idPartida");
|
||||||
$stmtObtenerEquipos->execute([':idPartida' => $idPartida]);
|
$stmtObtenerEquipos->execute([':idPartida' => $idPartida]);
|
||||||
$equiposDeLaPartida = $stmtObtenerEquipos->fetchAll(PDO::FETCH_COLUMN);
|
$equiposDeLaPartida = $stmtObtenerEquipos->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
// 4. Limpiar la relación de equipos de la partida (tabla intermedia)
|
|
||||||
$stmtBorrarEquiposPartida = $conexion->prepare("DELETE FROM equipoxpartida WHERE idPartida = :idPartida");
|
|
||||||
$stmtBorrarEquiposPartida = $conexion->prepare("DELETE FROM equipoxpartida WHERE idPartida = :idPartida");
|
$stmtBorrarEquiposPartida = $conexion->prepare("DELETE FROM equipoxpartida WHERE idPartida = :idPartida");
|
||||||
$stmtBorrarEquiposPartida->execute([':idPartida' => $idPartida]);
|
$stmtBorrarEquiposPartida->execute([':idPartida' => $idPartida]);
|
||||||
|
|
||||||
// 5. NUEVO: Borrar físicamente los equipos de la tabla 'equipo' si existen
|
|
||||||
if (!empty($equiposDeLaPartida)) {
|
if (!empty($equiposDeLaPartida)) {
|
||||||
// Creamos los marcadores (?, ?) de forma dinámica según los equipos que devuelva
|
|
||||||
$inQuery = implode(',', array_fill(0, count($equiposDeLaPartida), '?'));
|
$inQuery = implode(',', array_fill(0, count($equiposDeLaPartida), '?'));
|
||||||
$stmtBorrarEquiposFisicos = $conexion->prepare("DELETE FROM equipo WHERE idEquipo IN ($inQuery)");
|
$stmtBorrarEquiposFisicos = $conexion->prepare("DELETE FROM equipo WHERE idEquipo IN ($inQuery)");
|
||||||
$stmtBorrarEquiposFisicos->execute($equiposDeLaPartida);
|
$stmtBorrarEquiposFisicos->execute($equiposDeLaPartida);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Borrar físicamente la fila de la partida principal
|
|
||||||
$stmtBorrarSala = $conexion->prepare("DELETE FROM partida WHERE idPartida = :idPartida");
|
$stmtBorrarSala = $conexion->prepare("DELETE FROM partida WHERE idPartida = :idPartida");
|
||||||
$stmtBorrarSala->execute([':idPartida' => $idPartida]);
|
$stmtBorrarSala->execute([':idPartida' => $idPartida]);
|
||||||
}
|
}
|
||||||
@@ -224,11 +188,8 @@ switch ($orden) {
|
|||||||
$conexion->commit();
|
$conexion->commit();
|
||||||
echo json_encode(['exito' => true, 'usuarios_quedan' => $jugadoresRestantes]);
|
echo json_encode(['exito' => true, 'usuarios_quedan' => $jugadoresRestantes]);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
if ($conexion->inTransaction()) {
|
if ($conexion->inTransaction()) { $conexion->rollBack(); }
|
||||||
$conexion->rollBack();
|
|
||||||
}
|
|
||||||
echo json_encode(['error' => $e->getMessage()]);
|
echo json_encode(['error' => $e->getMessage()]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -60,12 +60,25 @@ function comprobarSesion() {
|
|||||||
`;
|
`;
|
||||||
contenedor.html(htmlUsuario);
|
contenedor.html(htmlUsuario);
|
||||||
|
|
||||||
|
// Si estamos en la página de perfil, rellenamos nombre y foto
|
||||||
|
if ($("#nombre").length) {
|
||||||
|
$("#nombre").text(respuesta.usuario.nombreUsuario);
|
||||||
|
// ?t= evita que el navegador enseñe la foto antigua en caché
|
||||||
|
$("#fotoPerfil").attr("src", avatarUrl + "?t=" + new Date().getTime());
|
||||||
|
}
|
||||||
|
|
||||||
// Si estamos en la página principal, mostramos el botón JUGAR
|
// Si estamos en la página principal, mostramos el botón JUGAR
|
||||||
if ($("#colBotonJugar").length) {
|
if ($("#colBotonJugar").length) {
|
||||||
$("#colBotonJugar").removeClass("d-none");
|
$("#colBotonJugar").removeClass("d-none");
|
||||||
$("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-8");
|
$("#colRanking").removeClass("col-lg-8").addClass("col-lg-7 col-xl-8");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Si estamos en el perfil y no hay sesión, volvemos al inicio
|
||||||
|
if ($("#nombre").length) {
|
||||||
|
window.location.href = "index.php";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// No hay sesión: Botones de Login y Registro
|
// No hay sesión: Botones de Login y Registro
|
||||||
const htmlInvitado = `
|
const htmlInvitado = `
|
||||||
<button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
<button type="button" class="btn btn-kahoot-login rounded-pill px-4" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
||||||
@@ -205,4 +218,4 @@ $(document).on("click", "#botonCerrarSesion", function (event) {
|
|||||||
.fail(function () {
|
.fail(function () {
|
||||||
window.location.href = "index.php";
|
window.location.href = "index.php";
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
+89
-12
@@ -118,7 +118,12 @@ function mostrarPregunta() {
|
|||||||
// 3. El usuario pulsa una respuesta: se guarda y se enseña si ha acertado
|
// 3. El usuario pulsa una respuesta: se guarda y se enseña si ha acertado
|
||||||
function responder($botonPulsado) {
|
function responder($botonPulsado) {
|
||||||
clearInterval(intervaloTiempo);
|
clearInterval(intervaloTiempo);
|
||||||
console.log("Tiempo de respuesta: " + tiempoRespuesta / 10 + " segundos");
|
|
||||||
|
console.log(
|
||||||
|
"Tiempo de respuesta: " +
|
||||||
|
tiempoRespuesta / 10 +
|
||||||
|
" segundos"
|
||||||
|
);
|
||||||
|
|
||||||
if (bloqueado) {
|
if (bloqueado) {
|
||||||
return;
|
return;
|
||||||
@@ -127,7 +132,29 @@ function responder($botonPulsado) {
|
|||||||
bloqueado = true;
|
bloqueado = true;
|
||||||
|
|
||||||
const pregunta = preguntas[indice];
|
const pregunta = preguntas[indice];
|
||||||
const idRespuesta = parseInt($botonPulsado.attr("data-id-respuesta"), 10);
|
|
||||||
|
const idRespuesta = parseInt(
|
||||||
|
$botonPulsado.attr("data-id-respuesta"),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("PREGUNTA ACTUAL:", pregunta);
|
||||||
|
console.log(
|
||||||
|
"idPartidaxPregunta:",
|
||||||
|
pregunta.idPartidaxPregunta
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"idRespuesta:",
|
||||||
|
idRespuesta
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"tiempoRespuesta:",
|
||||||
|
tiempoRespuesta
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"idPartida:",
|
||||||
|
idPartida
|
||||||
|
);
|
||||||
|
|
||||||
$("#respuestas").addClass("bloqueado");
|
$("#respuestas").addClass("bloqueado");
|
||||||
|
|
||||||
@@ -135,46 +162,96 @@ function responder($botonPulsado) {
|
|||||||
url: URL_CONTROLADOR,
|
url: URL_CONTROLADOR,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "responder",
|
orden: "responder",
|
||||||
idPartida: idPartida,
|
idPartida: idPartida,
|
||||||
idPartidaxPregunta: pregunta.idPartidaxPregunta,
|
idPartidaxPregunta: pregunta.idPartidaxPregunta,
|
||||||
idRespuesta: idRespuesta,
|
idRespuesta: idRespuesta,
|
||||||
tiempoRespuesta: tiempoRespuesta,
|
tiempoRespuesta: tiempoRespuesta
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (datos) {
|
success: function (datos) {
|
||||||
|
|
||||||
|
console.log("RESPUESTA DEL SERVIDOR:", datos);
|
||||||
|
|
||||||
if (datos.error) {
|
if (datos.error) {
|
||||||
// No se guardó: dejamos que vuelva a intentarlo
|
|
||||||
$("#feedback").text(datos.error).removeClass("ok").addClass("ko");
|
$("#feedback")
|
||||||
|
.text(datos.error)
|
||||||
|
.removeClass("ok")
|
||||||
|
.addClass("ko");
|
||||||
|
|
||||||
$("#respuestas").removeClass("bloqueado");
|
$("#respuestas").removeClass("bloqueado");
|
||||||
|
|
||||||
bloqueado = false;
|
bloqueado = false;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pregunta.respondida = true;
|
pregunta.respondida = true;
|
||||||
mostrarFeedback($botonPulsado, datos);
|
|
||||||
|
mostrarFeedback(
|
||||||
|
$botonPulsado,
|
||||||
|
datos
|
||||||
|
);
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (datos.terminada || indice >= preguntas.length - 1) {
|
|
||||||
|
if (
|
||||||
|
datos.terminada ||
|
||||||
|
indice >= preguntas.length - 1
|
||||||
|
) {
|
||||||
terminar();
|
terminar();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
indice++;
|
indice++;
|
||||||
$("#respuestas").removeClass("bloqueado");
|
|
||||||
|
$("#respuestas")
|
||||||
|
.removeClass("bloqueado");
|
||||||
|
|
||||||
mostrarPregunta();
|
mostrarPregunta();
|
||||||
}
|
}
|
||||||
|
|
||||||
}, PAUSA_FEEDBACK);
|
}, PAUSA_FEEDBACK);
|
||||||
},
|
},
|
||||||
error: function () {
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
|
||||||
|
console.error(
|
||||||
|
"ERROR AJAX RESPONDER"
|
||||||
|
);
|
||||||
|
|
||||||
|
console.error(
|
||||||
|
"HTTP:",
|
||||||
|
xhr.status
|
||||||
|
);
|
||||||
|
|
||||||
|
console.error(
|
||||||
|
"ERROR:",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
console.error(
|
||||||
|
"RESPUESTA:",
|
||||||
|
xhr.responseText
|
||||||
|
);
|
||||||
|
|
||||||
$("#feedback")
|
$("#feedback")
|
||||||
.text("No se pudo guardar la respuesta. Inténtalo de nuevo.")
|
.text(
|
||||||
|
"No se pudo guardar la respuesta. Inténtalo de nuevo."
|
||||||
|
)
|
||||||
.removeClass("ok")
|
.removeClass("ok")
|
||||||
.addClass("ko");
|
.addClass("ko");
|
||||||
|
|
||||||
$("#respuestas").removeClass("bloqueado");
|
$("#respuestas").removeClass("bloqueado");
|
||||||
|
|
||||||
bloqueado = false;
|
bloqueado = false;
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Marca la respuesta correcta en verde y atenúa el resto
|
// Marca la respuesta correcta en verde y atenúa el resto
|
||||||
function mostrarFeedback($botonPulsado, datos) {
|
function mostrarFeedback($botonPulsado, datos) {
|
||||||
$("#respuestas .btn-answer").each(function () {
|
$("#respuestas .btn-answer").each(function () {
|
||||||
|
|||||||
+6
-6
@@ -50,10 +50,9 @@ function cambiarNombre() {
|
|||||||
$("#nuevoNombre").val("");
|
$("#nuevoNombre").val("");
|
||||||
|
|
||||||
|
|
||||||
if (typeof comprobarEstadoSesion === "function") {
|
comprobarSesion();
|
||||||
comprobarEstadoSesion();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +70,7 @@ function borrarNombre() {
|
|||||||
|
|
||||||
function seleccionarFoto() {
|
function seleccionarFoto() {
|
||||||
$("#inputFoto").click();
|
$("#inputFoto").click();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#inputFoto").change(function () {
|
$("#inputFoto").change(function () {
|
||||||
@@ -79,6 +79,7 @@ $("#inputFoto").change(function () {
|
|||||||
if (!archivo) {
|
if (!archivo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Comprobamos que sea una imagen
|
// Comprobamos que sea una imagen
|
||||||
if (!archivo.type.startsWith("image/")) {
|
if (!archivo.type.startsWith("image/")) {
|
||||||
@@ -110,9 +111,8 @@ $("#inputFoto").change(function () {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Actualizamos también el avatar superior en la cabecera
|
// Actualizamos también el avatar superior en la cabecera
|
||||||
if (typeof comprobarEstadoSesion === "function") {
|
|
||||||
comprobarEstadoSesion();
|
comprobarSesion();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+113
-44
@@ -263,15 +263,16 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
|
|
||||||
if (esHost) {
|
if (esHost) {
|
||||||
botonIniciarHTML = `
|
botonIniciarHTML = `
|
||||||
<a
|
<button
|
||||||
href="juego.php?idPartida=${partida.idPartida}"
|
type="button"
|
||||||
class="btn btn-success btn-lg px-4">
|
class="btn btn-success btn-lg px-4 btn-iniciar-partida"
|
||||||
|
data-id-partida="${partida.idPartida}">
|
||||||
|
|
||||||
<i class="bi bi-controller"></i>
|
<i class="bi bi-controller"></i>
|
||||||
¡Iniciar Partida!
|
¡Iniciar Partida!
|
||||||
|
|
||||||
</a>
|
</button>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const salaHTML = `
|
const salaHTML = `
|
||||||
@@ -313,8 +314,98 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
contenedor.html(salaHTML);
|
contenedor.html(salaHTML);
|
||||||
|
if (!partida.fechaInicio) {
|
||||||
|
iniciarComprobacionPartida(partida.idPartida);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let intervaloComprobarPartida = null;
|
||||||
|
|
||||||
|
function iniciarComprobacionPartida(idPartida) {
|
||||||
|
if (intervaloComprobarPartida) {
|
||||||
|
clearInterval(intervaloComprobarPartida);
|
||||||
|
}
|
||||||
|
|
||||||
|
intervaloComprobarPartida = setInterval(function () {
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPartida.php",
|
||||||
|
|
||||||
|
type: "POST",
|
||||||
|
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "comprobarInicio",
|
||||||
|
idPartida: idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (respuesta) {
|
||||||
|
if (respuesta.iniciada) {
|
||||||
|
clearInterval(intervaloComprobarPartida);
|
||||||
|
|
||||||
|
window.location.href = "juego.php?idPartida=" + idPartida;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on("click", ".btn-iniciar-partida", function () {
|
||||||
|
const boton = $(this);
|
||||||
|
|
||||||
|
const idPartida = boton.data("id-partida");
|
||||||
|
|
||||||
|
boton.prop("disabled", true);
|
||||||
|
|
||||||
|
boton.html(`
|
||||||
|
<span class="spinner-border spinner-border-sm"></span>
|
||||||
|
Iniciando...
|
||||||
|
`);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPartida.php",
|
||||||
|
|
||||||
|
type: "POST",
|
||||||
|
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "iniciar",
|
||||||
|
|
||||||
|
idPartida: idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (respuesta) {
|
||||||
|
if (respuesta.error) {
|
||||||
|
alert(respuesta.error);
|
||||||
|
|
||||||
|
boton.prop("disabled", false);
|
||||||
|
|
||||||
|
boton.html(`
|
||||||
|
<i class="bi bi-controller"></i>
|
||||||
|
¡Iniciar Partida!
|
||||||
|
`);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// El host entra directamente
|
||||||
|
window.location.href = "juego.php?idPartida=" + idPartida;
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function () {
|
||||||
|
alert("Ocurrió un error al iniciar la partida.");
|
||||||
|
|
||||||
|
boton.prop("disabled", false);
|
||||||
|
|
||||||
|
boton.html(`
|
||||||
|
<i class="bi bi-controller"></i>
|
||||||
|
¡Iniciar Partida!
|
||||||
|
`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on("click", ".btn-unirse-equipo", function () {
|
$(document).on("click", ".btn-unirse-equipo", function () {
|
||||||
const boton = $(this);
|
const boton = $(this);
|
||||||
|
|
||||||
@@ -364,8 +455,7 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
|||||||
botonAbandonarReferencia = $(this);
|
botonAbandonarReferencia = $(this);
|
||||||
|
|
||||||
const esHost =
|
const esHost =
|
||||||
$(this).data("es-host") === true ||
|
$(this).data("es-host") === true || $(this).data("es-host") === "true";
|
||||||
$(this).data("es-host") === "true";
|
|
||||||
|
|
||||||
const titulo = $("#modalAbandonarSalaLabel");
|
const titulo = $("#modalAbandonarSalaLabel");
|
||||||
|
|
||||||
@@ -384,9 +474,7 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
|||||||
} else {
|
} else {
|
||||||
titulo.text("¿Abandonar la sala?");
|
titulo.text("¿Abandonar la sala?");
|
||||||
|
|
||||||
mensaje.text(
|
mensaje.text("Si sales de la sala, perderás tu lugar en el equipo.");
|
||||||
"Si sales de la sala, perderás tu lugar en el equipo.",
|
|
||||||
);
|
|
||||||
|
|
||||||
botonConfirmar.text("Sí, salir");
|
botonConfirmar.text("Sí, salir");
|
||||||
}
|
}
|
||||||
@@ -399,17 +487,13 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||||
const modalEl =
|
const modalEl = document.getElementById("modalAbandonarSala");
|
||||||
document.getElementById("modalAbandonarSala");
|
|
||||||
|
|
||||||
const modalInstance =
|
const modalInstance = bootstrap.Modal.getInstance(modalEl);
|
||||||
bootstrap.Modal.getInstance(modalEl);
|
|
||||||
|
|
||||||
const btnConfirmar = $(this);
|
const btnConfirmar = $(this);
|
||||||
|
|
||||||
btnConfirmar
|
btnConfirmar.prop("disabled", true).text("Saliendo...");
|
||||||
.prop("disabled", true)
|
|
||||||
.text("Saliendo...");
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorEquipoxUsuario.php",
|
url: "controladores/controladorEquipoxUsuario.php",
|
||||||
@@ -421,9 +505,7 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
|||||||
},
|
},
|
||||||
|
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
btnConfirmar
|
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||||
.prop("disabled", false)
|
|
||||||
.text("Sí, salir");
|
|
||||||
|
|
||||||
if (modalInstance) {
|
if (modalInstance) {
|
||||||
modalInstance.hide();
|
modalInstance.hide();
|
||||||
@@ -449,16 +531,11 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
|||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error(
|
console.error("Error al salir de la sala:", error);
|
||||||
"Error al salir de la sala:",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
|
|
||||||
alert("No se pudo salir de la sala.");
|
alert("No se pudo salir de la sala.");
|
||||||
|
|
||||||
btnConfirmar
|
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||||
.prop("disabled", false)
|
|
||||||
.text("Sí, salir");
|
|
||||||
|
|
||||||
if (modalInstance) {
|
if (modalInstance) {
|
||||||
modalInstance.hide();
|
modalInstance.hide();
|
||||||
@@ -473,25 +550,19 @@ function escapeHTML(texto) {
|
|||||||
.html();
|
.html();
|
||||||
}
|
}
|
||||||
|
|
||||||
function mostrarEquipos(
|
function mostrarEquipos(partida, equipos, jugadores) {
|
||||||
partida,
|
|
||||||
equipos,
|
|
||||||
jugadores
|
|
||||||
) {
|
|
||||||
let equiposHTML = "";
|
let equiposHTML = "";
|
||||||
|
|
||||||
equipos.forEach(function (equipo) {
|
equipos.forEach(function (equipo) {
|
||||||
const jugadoresEquipo =
|
const jugadoresEquipo = jugadores.filter(function (jugador) {
|
||||||
jugadores.filter(function (jugador) {
|
return jugador.idEquipo == equipo.idEquipo;
|
||||||
return jugador.idEquipo == equipo.idEquipo;
|
});
|
||||||
});
|
|
||||||
|
|
||||||
let jugadoresHTML = "";
|
let jugadoresHTML = "";
|
||||||
|
|
||||||
if (jugadoresEquipo.length > 0) {
|
if (jugadoresEquipo.length > 0) {
|
||||||
jugadoresEquipo.forEach(function (jugador) {
|
jugadoresEquipo.forEach(function (jugador) {
|
||||||
const esHost =
|
const esHost = jugador.idUsuario == partida.idUsuario;
|
||||||
jugador.idUsuario == partida.idUsuario;
|
|
||||||
|
|
||||||
jugadoresHTML += `
|
jugadoresHTML += `
|
||||||
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||||
@@ -507,9 +578,7 @@ function mostrarEquipos(
|
|||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
${escapeHTML(
|
${escapeHTML(jugador.nombreUsuario)}
|
||||||
jugador.nombreUsuario
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${
|
${
|
||||||
@@ -547,4 +616,4 @@ function mostrarEquipos(
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#contenedorSalas .equipos").html(equiposHTML);
|
$("#contenedorSalas .equipos").html(equiposHTML);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
// modelos/PartidaModelo.php
|
||||||
|
|
||||||
|
class PartidaModelo {
|
||||||
|
private $conexion;
|
||||||
|
|
||||||
|
public function __construct($conexion) {
|
||||||
|
$this->conexion = $conexion;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene los jugadores mapeados en la partida actual
|
||||||
|
public function obtenerJugadoresPartida($idPartida) {
|
||||||
|
$stmt = $this->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]);
|
||||||
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene las respuestas guardadas por un usuario específico
|
||||||
|
public function obtenerRespuestasUsuario($idPartida, $idUsuario) {
|
||||||
|
$stmtRespuestas = $this->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' => $idUsuario]);
|
||||||
|
return $stmtRespuestas->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1476
-1388
File diff suppressed because it is too large
Load Diff
+3
-19
@@ -1,17 +1,3 @@
|
|||||||
<?php
|
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
|
||||||
session_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirección si el usuario no ha iniciado sesión
|
|
||||||
if (!isset($_SESSION['idUsuario'])) {
|
|
||||||
header('Location: login.php');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
$nombreUsuario = htmlspecialchars($_SESSION['nombreUsuario'] ?? 'Usuario');
|
|
||||||
$avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultProfile.jpeg');
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
|
|
||||||
@@ -61,15 +47,13 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
<div class="col-md-6 text-center">
|
<div class="col-md-6 text-center">
|
||||||
|
|
||||||
<!-- Nombre -->
|
<!-- Nombre -->
|
||||||
<h1 id="nombre" class="nombre">
|
<h1 id="nombre" class="nombre"></h1>
|
||||||
<?= $nombreUsuario ?>
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<!-- FOTO DE PERFIL -->
|
<!-- FOTO DE PERFIL -->
|
||||||
<div class="foto-container">
|
<div class="foto-container">
|
||||||
|
|
||||||
<img id="fotoPerfil"
|
<img id="fotoPerfil"
|
||||||
src="<?= $avatarUsuario ?>"
|
src="img/avatars/defaultProfile.jpeg"
|
||||||
alt="Foto de perfil"
|
alt="Foto de perfil"
|
||||||
class="avatar rounded-circle">
|
class="avatar rounded-circle">
|
||||||
|
|
||||||
@@ -310,7 +294,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
|
|
||||||
<!-- Tu JavaScript -->
|
<!-- Tu JavaScript -->
|
||||||
<script src="js/perfil.js"></script>
|
<script src="js/perfil.js"></script>
|
||||||
<script src="js/cabecera.js"></script>
|
<script src="js/cabecera.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
+11
-101
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// resultados.php (Actúa como el Controlador Frontal de esta pantalla)
|
||||||
session_start();
|
session_start();
|
||||||
require_once __DIR__ . '/includes/conexionBD.php';
|
require_once __DIR__ . '/includes/conexionBD.php';
|
||||||
|
require_once __DIR__ . '/modelos/PartidaModelo.php';
|
||||||
|
|
||||||
$idPartida = intval($_GET['idPartida'] ?? 0);
|
$idPartida = intval($_GET['idPartida'] ?? 0);
|
||||||
if ($idPartida <= 0) {
|
if ($idPartida <= 0) {
|
||||||
@@ -12,37 +14,22 @@ if (is_array($conexion)) {
|
|||||||
die("Error de conexión a la base de datos.");
|
die("Error de conexión a la base de datos.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtener listado de jugadores y sus equipos en esta partida
|
// Instanciamos el modelo
|
||||||
$stmt = $conexion->prepare("
|
$modelo = new PartidaModelo($conexion);
|
||||||
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);
|
|
||||||
|
|
||||||
|
// Obtenemos datos crudos del modelo
|
||||||
|
$listaJugadoresRaw = $modelo->obtenerJugadoresPartida($idPartida);
|
||||||
$primerosEnAcertar = $_SESSION['primeros_en_acertar'][$idPartida] ?? [];
|
$primerosEnAcertar = $_SESSION['primeros_en_acertar'][$idPartida] ?? [];
|
||||||
|
|
||||||
$jugadoresFinales = [];
|
$jugadoresFinales = [];
|
||||||
$equiposFinales = [];
|
$equiposFinales = [];
|
||||||
|
|
||||||
// Respuestas de velocidad (+2 o +1) procesadas en la capa de la vista
|
// Procesamiento de la lógica de negocio (puntos y velocidad)
|
||||||
foreach ($listaJugadoresRaw as $jugador) {
|
foreach ($listaJugadoresRaw as $jugador) {
|
||||||
$idU = (int)$jugador['idUsuario'];
|
$idU = (int)$jugador['idUsuario'];
|
||||||
$idE = (int)$jugador['idEquipo'];
|
$idE = (int)$jugador['idEquipo'];
|
||||||
|
|
||||||
$stmtRespuestas = $conexion->prepare("
|
$respuestasUsuario = $modelo->obtenerRespuestasUsuario($idPartida, $idU);
|
||||||
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;
|
$aciertos = 0;
|
||||||
$puntosTotalesJugador = 0;
|
$puntosTotalesJugador = 0;
|
||||||
@@ -52,6 +39,7 @@ foreach ($listaJugadoresRaw as $jugador) {
|
|||||||
$aciertos++;
|
$aciertos++;
|
||||||
$idPxp = $resp['idPartidaxPregunta'];
|
$idPxp = $resp['idPartidaxPregunta'];
|
||||||
|
|
||||||
|
// Regula si es el más rápido (+2) o normal (+1)
|
||||||
if (isset($primerosEnAcertar[$idPxp]) && $primerosEnAcertar[$idPxp] === $idU) {
|
if (isset($primerosEnAcertar[$idPxp]) && $primerosEnAcertar[$idPxp] === $idU) {
|
||||||
$puntosTotalesJugador += 2;
|
$puntosTotalesJugador += 2;
|
||||||
} else {
|
} else {
|
||||||
@@ -76,86 +64,8 @@ foreach ($listaJugadoresRaw as $jugador) {
|
|||||||
$equiposFinales[$idE]['puntos'] += $puntosTotalesJugador;
|
$equiposFinales[$idE]['puntos'] += $puntosTotalesJugador;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ordenaciones de rankings
|
||||||
usort($jugadoresFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
usort($jugadoresFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
||||||
usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
||||||
?>
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
require_once __DIR__ . '/vistas/vistaResultados.php';
|
||||||
<html lang="es">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Resultados - Trivial</title>
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">
|
|
||||||
<link rel="stylesheet" href="css/index.css">
|
|
||||||
<link rel="stylesheet" href="css/resultados.css">
|
|
||||||
<script src="js/jquery-4.0.0.min.js"></script>
|
|
||||||
</head>
|
|
||||||
<body data-id-partida="<?php echo $idPartida; ?>">
|
|
||||||
|
|
||||||
<div id="pantalla-espera" class="contenedor">
|
|
||||||
<h2> <i class="bi bi-hourglass"></i> 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>
|
|
||||||
|
|
||||||
<div id="pantalla-resultados" class="contenedor" style="display:none;">
|
|
||||||
<h1> <i class="bi bi-trophy-fill"></i> Resultados de la Partida <i class="bi bi-trophy-fill"></i> </h1>
|
|
||||||
|
|
||||||
<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="<?= $_ENV['urlBase'] ?>/" id="btnVolverInicio" data-id="<?php echo $idPartida; ?>" class="btn btn-play-kahoot"> <i class="bi bi-arrow-left"></i> Volver al Inicio <i class="bi bi-house-fill"></i> </a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script src="js/resultados.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Resultados - Trivial</title>
|
||||||
|
<link rel="stylesheet" href="css/resultados.css">
|
||||||
|
<script src="js/jquery-4.0.0.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body data-id-partida="<?php echo $idPartida; ?>">
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<div id="pantalla-resultados" class="contenedor" style="display:none;">
|
||||||
|
<h1>🏆 Resultados de la Partida 🏆</h1>
|
||||||
|
|
||||||
|
<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/" id="btnVolverInicio" data-id="<?php echo $idPartida; ?>" class="btn-inicio">Volver al Inicio 🏠</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="js/resultados.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user