Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8199aa261 | |||
| 7661343572 | |||
| e97586b033 | |||
| 42cc1489e9 | |||
| a694f19667 | |||
| 3cc0dfb122 |
+2
-2
@@ -82,8 +82,8 @@
|
|||||||
<div class="modal-content modal-kahoot text-center p-3">
|
<div class="modal-content modal-kahoot text-center p-3">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="mb-3 fs-1">⚠️</div>
|
<div class="mb-3 fs-1">⚠️</div>
|
||||||
<h4 class="modal-title mb-2 fw-bold text-white" id="modalAbandonarSalaLabel">¿Abandonar la sala?</h4>
|
<h4 class="modal-title mb-2 fw-bold" id="modalAbandonarSalaLabel">¿Abandonar la sala?</h4>
|
||||||
<p class="text-white-50">Si sales de la sala, perderás tu lugar en el equipo.</p>
|
<p class="text-dark-50">Si sales de la sala, perderás tu lugar en el equipo.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer justify-content-center border-0 gap-2">
|
<div class="modal-footer justify-content-center border-0 gap-2">
|
||||||
<button type="button" class="btn btn-secondary px-4 py-2" data-bs-dismiss="modal">
|
<button type="button" class="btn btn-secondary px-4 py-2" data-bs-dismiss="modal">
|
||||||
|
|||||||
+184
-156
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
@@ -7,27 +8,17 @@ class Partida
|
|||||||
public $idPartida;
|
public $idPartida;
|
||||||
public $nombrePartida;
|
public $nombrePartida;
|
||||||
public $idUsuario;
|
public $idUsuario;
|
||||||
public $fechaCreacion;
|
|
||||||
public $fechaInicio;
|
|
||||||
public $fechaFin;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$idPartida = null,
|
$idPartida = null,
|
||||||
$nombrePartida = null,
|
$nombrePartida = null,
|
||||||
$idUsuario = null,
|
$idUsuario = null
|
||||||
$fechaCreacion = null,
|
|
||||||
$fechaInicio = null,
|
|
||||||
$fechaFin = null
|
|
||||||
) {
|
) {
|
||||||
$this->idPartida = $idPartida;
|
$this->idPartida = $idPartida;
|
||||||
$this->nombrePartida = $nombrePartida;
|
$this->nombrePartida = $nombrePartida;
|
||||||
$this->idUsuario = $idUsuario;
|
$this->idUsuario = $idUsuario;
|
||||||
$this->fechaCreacion = $fechaCreacion;
|
|
||||||
$this->fechaInicio = $fechaInicio;
|
|
||||||
$this->fechaFin = $fechaFin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function insertar()
|
public function insertar()
|
||||||
{
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
@@ -35,7 +26,12 @@ class Partida
|
|||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("INSERT INTO partida (nombrePartida,idUsuario) VALUES (:nombrePartida,:idUsuario)");
|
$consulta = $conexion->prepare("
|
||||||
|
INSERT INTO partida
|
||||||
|
(nombrePartida,idUsuario)
|
||||||
|
VALUES
|
||||||
|
(:nombrePartida,:idUsuario)
|
||||||
|
");
|
||||||
$consulta->bindParam(":nombrePartida", $this->nombrePartida);
|
$consulta->bindParam(":nombrePartida", $this->nombrePartida);
|
||||||
$consulta->bindParam(":idUsuario", $this->idUsuario);
|
$consulta->bindParam(":idUsuario", $this->idUsuario);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
@@ -51,7 +47,8 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listar(){
|
public function listar()
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
@@ -68,13 +65,18 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buscar(){
|
public function buscar()
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("SELECT * FROM partida WHERE idPartida=:idPartida");
|
$consulta = $conexion->prepare("
|
||||||
|
SELECT *
|
||||||
|
FROM partida
|
||||||
|
WHERE idPartida=:idPartida
|
||||||
|
");
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
return $consulta->fetch(PDO::FETCH_ASSOC);
|
return $consulta->fetch(PDO::FETCH_ASSOC);
|
||||||
@@ -86,14 +88,20 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function editar()
|
||||||
public function editar(){
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("UPDATE partida SET nombrePartida=:nombrePartida, idUsuario=:idUsuario WHERE idPartida=:idPartida");
|
$consulta = $conexion->prepare("
|
||||||
|
UPDATE partida
|
||||||
|
SET
|
||||||
|
nombrePartida=:nombrePartida,
|
||||||
|
idUsuario=:idUsuario
|
||||||
|
WHERE idPartida=:idPartida
|
||||||
|
");
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->bindParam(":nombrePartida", $this->nombrePartida);
|
$consulta->bindParam(":nombrePartida", $this->nombrePartida);
|
||||||
$consulta->bindParam(":idUsuario", $this->idUsuario);
|
$consulta->bindParam(":idUsuario", $this->idUsuario);
|
||||||
@@ -110,13 +118,17 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function eliminar(){
|
public function eliminar()
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("DELETE FROM partida WHERE idPartida=:idPartida");
|
$consulta = $conexion->prepare("
|
||||||
|
DELETE FROM partida
|
||||||
|
WHERE idPartida=:idPartida
|
||||||
|
");
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
return [
|
return [
|
||||||
@@ -131,121 +143,27 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function iniciarPartida(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if (is_array($conexion)){
|
|
||||||
return $conexion;
|
|
||||||
}
|
|
||||||
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" => "Ocurrió un error al iniciar la partida.",
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function finalizar(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if (is_array($conexion)) {
|
|
||||||
return $conexion;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$consulta = $conexion->prepare("UPDATE partida SET fechaFin=NOW() WHERE idPartida=:idPartida AND fechaFin IS NULL");
|
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
|
||||||
$consulta->execute();
|
|
||||||
return [
|
|
||||||
"exito" => "La partida se finalizó correctamente.",
|
|
||||||
"exito_tecnico" => $this->idPartida
|
|
||||||
];
|
|
||||||
} catch (PDOException $error) {
|
|
||||||
return [
|
|
||||||
"error" => "Ocurrió un error al finalizar la partida.",
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//true si la partida ya tiene fecha de fin (fechaFin no es NULL)
|
|
||||||
//Devuelve false si la partida no existe
|
|
||||||
|
|
||||||
public function estaFinalizada() {
|
|
||||||
$datos = $this->buscar();
|
|
||||||
if (is_array($datos) && isset($datos["error"])) {
|
|
||||||
return $datos;
|
|
||||||
}
|
|
||||||
if (!$datos) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $datos["fechaFin"] !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Devuelve la partida más reciente del usuario que aún no ha
|
|
||||||
//terminado (fechaFin NULL), o false si no tiene ninguna.
|
|
||||||
//Incluye también las salas que todavía no han empezado.
|
|
||||||
|
|
||||||
public function partidaEnCursoDeUsuario(){
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if (is_array($conexion)) {
|
|
||||||
return $conexion;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$consulta = $conexion->prepare("SELECT * FROM partida WHERE idUsuario=:idUsuario AND fechaFin IS NULL ORDER BY idPartida DESC LIMIT 1");
|
|
||||||
$consulta->bindParam(":idUsuario", $this->idUsuario);
|
|
||||||
$consulta->execute();
|
|
||||||
return $consulta->fetch(PDO::FETCH_ASSOC);
|
|
||||||
} catch (PDOException $error) {
|
|
||||||
return [
|
|
||||||
"error" => "Ocurrió un error al buscar la partida en curso.",
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function listarSalasAbiertas() {
|
|
||||||
$conexion = conexionBD();
|
|
||||||
if (is_array($conexion)) {
|
|
||||||
return $conexion;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$consulta = $conexion->prepare("SELECT p.idPartida, p.nombrePartida, e.idEquipo, e.nombreEquipo, u.idUsuario, u.nombreUsuario
|
|
||||||
FROM partida p INNER JOIN equipoxpartida exp ON exp.idPartida=p.idPartida INNER JOIN equipo e ON e.idEquipo=exp.idEquipo
|
|
||||||
LEFT JOIN equipoxusuario exu ON exu.idEquipo=e.idEquipo LEFT JOIN usuario u ON u.idUsuario=exu.idUsuario WHERE p.fechaInicio IS NULL
|
|
||||||
AND p.fechaFin IS NULL ORDER BY p.idPartida DESC, e.idEquipo ASC");
|
|
||||||
$consulta->execute();
|
|
||||||
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
} catch (PDOException $error) {
|
|
||||||
return [
|
|
||||||
"error" => "Ocurrió un error al recuperar las salas abiertas.",
|
|
||||||
'error_tecnico' => $error->getMessage()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Devuelve las preguntas asignadas a la partida, junto con el
|
* Devuelve las preguntas asignadas a la partida, junto con el
|
||||||
* idPartidaxPregunta (necesario para guardar respuestas después).
|
* idPartidaxPregunta (necesario para guardar respuestas después).
|
||||||
*/
|
*/
|
||||||
public function getPreguntas(){
|
public function getPreguntas()
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("SELECT pxp.idPartidaxPregunta, p.* FROM partidaxpregunta pxp INNER JOIN pregunta p ON pxp.idPregunta=p.idPregunta
|
$consulta = $conexion->prepare("
|
||||||
WHERE pxp.idPartida=:idPartida ORDER BY pxp.idPartidaxPregunta");
|
SELECT
|
||||||
|
pxp.idPartidaxPregunta,
|
||||||
|
p.*
|
||||||
|
FROM partidaxpregunta pxp
|
||||||
|
INNER JOIN pregunta p
|
||||||
|
ON pxp.idPregunta=p.idPregunta
|
||||||
|
WHERE pxp.idPartida=:idPartida
|
||||||
|
ORDER BY pxp.idPartidaxPregunta
|
||||||
|
");
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
||||||
@@ -257,14 +175,22 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public function asignarPregunta($idPregunta) {
|
* Asocia una pregunta ya existente a esta partida.
|
||||||
|
*/
|
||||||
|
public function asignarPregunta($idPregunta)
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("INSERT INTO partidaxpregunta (idPartida,idPregunta) VALUES (:idPartida,:idPregunta)");
|
$consulta = $conexion->prepare("
|
||||||
|
INSERT INTO partidaxpregunta
|
||||||
|
(idPartida,idPregunta)
|
||||||
|
VALUES
|
||||||
|
(:idPartida,:idPregunta)
|
||||||
|
");
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->bindParam(":idPregunta", $idPregunta);
|
$consulta->bindParam(":idPregunta", $idPregunta);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
@@ -280,13 +206,18 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Cuenta cuántas preguntas tiene la partida en total. Es la primera mitad de la comprobación "¿ha terminado el usuario de jugar?".
|
//Cuenta cuántas preguntas tiene la partida en total. Es la primera mitad de la comprobación "¿ha terminado el usuario de jugar?".
|
||||||
public function contarPreguntasAsignadas() {
|
public function contarPreguntasAsignadas()
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("SELECT COUNT(*) AS total FROM partidaxpregunta WHERE idPartida=:idPartida");
|
$consulta = $conexion->prepare("
|
||||||
|
SELECT COUNT(*) AS total
|
||||||
|
FROM partidaxpregunta
|
||||||
|
WHERE idPartida=:idPartida
|
||||||
|
");
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
$fila = $consulta->fetch(PDO::FETCH_ASSOC);
|
$fila = $consulta->fetch(PDO::FETCH_ASSOC);
|
||||||
@@ -299,14 +230,21 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function contarRespuestasUsuario($idUsuario){
|
public function contarRespuestasUsuario($idUsuario)
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("SELECT COUNT(*) AS total FROM respuestaalmacenada ra INNER JOIN partidaxpregunta pxp
|
$consulta = $conexion->prepare("
|
||||||
ON ra.idPartidaxPregunta=pxp.idPartidaxPregunta WHERE pxp.idPartida=:idPartida AND ra.idUsuario=:idUsuario");
|
SELECT COUNT(*) AS total
|
||||||
|
FROM respuestaalmacenada ra
|
||||||
|
INNER JOIN partidaxpregunta pxp
|
||||||
|
ON ra.idPartidaxPregunta=pxp.idPartidaxPregunta
|
||||||
|
WHERE pxp.idPartida=:idPartida
|
||||||
|
AND ra.idUsuario=:idUsuario
|
||||||
|
");
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->bindParam(":idUsuario", $idUsuario);
|
$consulta->bindParam(":idUsuario", $idUsuario);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
@@ -321,11 +259,11 @@ class Partida
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indica si ESTE usuario ya ha respondido todas las preguntas:
|
* Sustituye al antiguo campo `terminada`: compara cuántas preguntas
|
||||||
* compara cuántas preguntas tiene la partida contra cuántas ha
|
* tiene la partida contra cuántas ha respondido este usuario.
|
||||||
* respondido él. (La partida completa se marca con finalizar().)
|
|
||||||
*/
|
*/
|
||||||
public function estaFinalizadaParaUsuario($idUsuario){
|
public function estaFinalizadaParaUsuario($idUsuario)
|
||||||
|
{
|
||||||
$totalPreguntas = $this->contarPreguntasAsignadas();
|
$totalPreguntas = $this->contarPreguntasAsignadas();
|
||||||
if (is_array($totalPreguntas)) {
|
if (is_array($totalPreguntas)) {
|
||||||
return $totalPreguntas;
|
return $totalPreguntas;
|
||||||
@@ -340,13 +278,19 @@ class Partida
|
|||||||
/**
|
/**
|
||||||
* Partidas creadas por un usuario, de más reciente a más antigua.
|
* Partidas creadas por un usuario, de más reciente a más antigua.
|
||||||
*/
|
*/
|
||||||
public function listarDelUsuario(){
|
public function listarDelUsuario()
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("SELECT * FROM partida WHERE idUsuario=:idUsuario ORDER BY idPartida DESC");
|
$consulta = $conexion->prepare("
|
||||||
|
SELECT *
|
||||||
|
FROM partida
|
||||||
|
WHERE idUsuario=:idUsuario
|
||||||
|
ORDER BY idPartida DESC
|
||||||
|
");
|
||||||
$consulta->bindParam(":idUsuario", $this->idUsuario);
|
$consulta->bindParam(":idUsuario", $this->idUsuario);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
||||||
@@ -358,13 +302,22 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function preguntaAsignada($idPregunta) {
|
public function preguntaAsignada($idPregunta)
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
|
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("SELECT COUNT(*) AS total FROM partidaxpregunta WHERE idPartida=:idPartida AND idPregunta=:idPregunta");
|
$consulta = $conexion->prepare("
|
||||||
|
SELECT COUNT(*) AS total
|
||||||
|
FROM partidaxpregunta
|
||||||
|
WHERE idPartida=:idPartida
|
||||||
|
AND idPregunta=:idPregunta
|
||||||
|
");
|
||||||
|
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->bindParam(":idPregunta", $idPregunta);
|
$consulta->bindParam(":idPregunta", $idPregunta);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
@@ -384,13 +337,24 @@ class Partida
|
|||||||
* Vincula un equipo a esta partida en la tabla intermedia 'equipoxpartida'.
|
* Vincula un equipo a esta partida en la tabla intermedia 'equipoxpartida'.
|
||||||
* Permite registrar qué grupos están participando en este torneo.
|
* Permite registrar qué grupos están participando en este torneo.
|
||||||
*/
|
*/
|
||||||
public function registrarEquipoEnPartida($idEquipo){
|
public function registrarEquipoEnPartida($idEquipo)
|
||||||
$conexion = conexionBD();
|
{
|
||||||
|
$conexion = conexionBD(); // Obtenemos la conexión modular del proyecto
|
||||||
|
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion; // Si hay error en la conexión, lo devuelve
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("INSERT INTO equipoxpartida (idPartida, idEquipo) VALUES (:idPartida, :idEquipo)");
|
// Preparamos la consulta para insertar la relación en la tabla intermedia real
|
||||||
|
$consulta = $conexion->prepare("
|
||||||
|
INSERT INTO equipoxpartida
|
||||||
|
(idPartida, idEquipo)
|
||||||
|
VALUES
|
||||||
|
(:idPartida, :idEquipo)
|
||||||
|
");
|
||||||
|
|
||||||
|
// Vinculamos los parámetros con el objeto de la partida actual y el equipo recibido
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->bindParam(":idEquipo", $idEquipo);
|
$consulta->bindParam(":idEquipo", $idEquipo);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
@@ -400,6 +364,7 @@ class Partida
|
|||||||
"exito_tecnico" => $conexion->lastInsertId()
|
"exito_tecnico" => $conexion->lastInsertId()
|
||||||
];
|
];
|
||||||
} catch (PDOException $error) {
|
} catch (PDOException $error) {
|
||||||
|
// Capturamos el error extrayendo solo el mensaje de texto limpio
|
||||||
return [
|
return [
|
||||||
"error" => "Ocurrió un error al asignar el equipo a la partida.",
|
"error" => "Ocurrió un error al asignar el equipo a la partida.",
|
||||||
"error_tecnico" => $error->getMessage()
|
"error_tecnico" => $error->getMessage()
|
||||||
@@ -411,14 +376,28 @@ class Partida
|
|||||||
* Obtiene todos los equipos que están compitiendo en esta partida.
|
* Obtiene todos los equipos que están compitiendo en esta partida.
|
||||||
* Es útil para mostrar la lista de rivales antes de empezar a responder.
|
* Es útil para mostrar la lista de rivales antes de empezar a responder.
|
||||||
*/
|
*/
|
||||||
public function getEquiposParticipantes(){
|
public function getEquiposParticipantes()
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
|
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
$consulta = $conexion->prepare("SELECT exp.idEquipoxPartida, e.idEquipo, e.nombreEquipo FROM equipoxpartida exp
|
try {
|
||||||
INNER JOIN equipo e ON exp.idEquipo = e.idEquipo WHERE exp.idPartida = :idPartida ORDER BY e.nombreEquipo ASC");
|
// Hacemos un INNER JOIN para traer los nombres de los equipos desde la tabla intermedia
|
||||||
|
$consulta = $conexion->prepare("
|
||||||
|
SELECT
|
||||||
|
exp.idEquipoxPartida,
|
||||||
|
e.idEquipo,
|
||||||
|
e.nombreEquipo
|
||||||
|
FROM equipoxpartida exp
|
||||||
|
INNER JOIN equipo e
|
||||||
|
ON exp.idEquipo = e.idEquipo
|
||||||
|
WHERE exp.idPartida = :idPartida
|
||||||
|
ORDER BY e.nombreEquipo ASC
|
||||||
|
");
|
||||||
|
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
|
|
||||||
@@ -435,29 +414,78 @@ class Partida
|
|||||||
* Obtiene todos los jugadores reales (Usuarios) que están jugando en esta partida.
|
* Obtiene todos los jugadores reales (Usuarios) que están jugando en esta partida.
|
||||||
* Utiliza la tabla 'equipoxusuario' en SQL para cruzar los datos.
|
* Utiliza la tabla 'equipoxusuario' en SQL para cruzar los datos.
|
||||||
*/
|
*/
|
||||||
public function getJugadoresDeLaPartida(){
|
public function getJugadoresDeLaPartida()
|
||||||
|
{
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
|
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("SELECT DISTINCT u.idUsuario, u.nombreUsuario, u.email, e.idEquipo, e.nombreEquipo
|
|
||||||
FROM equipoxpartida exp INNER JOIN equipoxusuario exu ON exp.idEquipo = exu.idEquipo INNER JOIN usuario u
|
$consulta = $conexion->prepare("
|
||||||
ON exu.idUsuario = u.idUsuario INNER JOIN equipo e ON exu.idEquipo = e.idEquipo WHERE exp.idPartida = :idPartida
|
SELECT DISTINCT
|
||||||
ORDER BY e.nombreEquipo ASC, u.nombreUsuario ASC");
|
u.idUsuario,
|
||||||
|
u.nombreUsuario,
|
||||||
|
u.email,
|
||||||
|
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
|
||||||
|
|
||||||
|
ORDER BY e.nombreEquipo ASC,
|
||||||
|
u.nombreUsuario ASC
|
||||||
|
");
|
||||||
|
|
||||||
$consulta->bindParam(
|
$consulta->bindParam(
|
||||||
":idPartida",
|
":idPartida",
|
||||||
$this->idPartida
|
$this->idPartida
|
||||||
);
|
);
|
||||||
|
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
|
|
||||||
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
return $consulta->fetchAll(PDO::FETCH_ASSOC);
|
||||||
} catch (PDOException $error) {
|
} catch (PDOException $error) {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
"error" =>
|
"error" =>
|
||||||
"Ocurrió un error al obtener la lista de jugadores.",
|
"Ocurrió un error al obtener la lista de jugadores.",
|
||||||
|
|
||||||
"error_tecnico" =>
|
"error_tecnico" =>
|
||||||
$error->getMessage()
|
$error->getMessage()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function contar()
|
||||||
|
{
|
||||||
|
$conexion = conexionBD();
|
||||||
|
if (is_array($conexion)) {
|
||||||
|
return $conexion;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$sql="SELECT COUNT(*) AS total FROM partida";
|
||||||
|
$consulta = $conexion->prepare($sql);
|
||||||
|
$consulta->execute();
|
||||||
|
return (int) $consulta->fetchColumn();
|
||||||
|
} catch (PDOException $error) {
|
||||||
|
return [
|
||||||
|
"error" => "Ocurrió un error al obtener el listado.",
|
||||||
|
'error_tecnico' => $error->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
@@ -110,4 +111,22 @@ class Pregunta {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getTodosIds()//devuelve solamente los id de todas las preguntas
|
||||||
|
{
|
||||||
|
$conexion = conexionBD();
|
||||||
|
if (is_array($conexion)) {
|
||||||
|
return $conexion;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$consulta = $conexion->prepare("SELECT idPregunta FROM pregunta");
|
||||||
|
$consulta->execute();
|
||||||
|
return $consulta->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
} catch (PDOException $error) {
|
||||||
|
return [
|
||||||
|
"error" => "Ocurrió un error al obtener el listado.",
|
||||||
|
'error_tecnico' => $error->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ require_once '../clases/ClasePartida.php';
|
|||||||
require_once '../clases/ClaseEquipo.php';
|
require_once '../clases/ClaseEquipo.php';
|
||||||
require_once '../clases/ClaseEquipoxUsuario.php';
|
require_once '../clases/ClaseEquipoxUsuario.php';
|
||||||
require_once '../clases/ClaseEquipoxPartida.php';
|
require_once '../clases/ClaseEquipoxPartida.php';
|
||||||
|
require_once '../clases/ClasePregunta.php';
|
||||||
|
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
@@ -119,6 +120,7 @@ switch ($_POST['orden']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$idPartida = (int)$resultadoPartida['exito_tecnico'];
|
$idPartida = (int)$resultadoPartida['exito_tecnico'];
|
||||||
|
$partida->idPartida = $idPartida;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -211,6 +213,42 @@ switch ($_POST['orden']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ==========================================
|
||||||
|
* 5. ASIGNAMOS 10 PREGUNTAS ALEATORIAS A LA PARTIDA
|
||||||
|
* ==========================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Obtenemos todos los IDs de las preguntas
|
||||||
|
|
||||||
|
$listaPreguntas = Pregunta::getTodosIds();
|
||||||
|
|
||||||
|
$totalPreguntas = count($listaPreguntas);
|
||||||
|
|
||||||
|
// Guardamos las preguntas que ya hemos asignado
|
||||||
|
$preguntasAsignadas = [];
|
||||||
|
|
||||||
|
// Generamos 10 posiciones aleatorias sin repetir
|
||||||
|
while (count($preguntasAsignadas) < 10) {
|
||||||
|
|
||||||
|
// Generamos una posición aleatoria del array
|
||||||
|
$posicionAleatoria = rand(0, $totalPreguntas - 1);
|
||||||
|
|
||||||
|
// Obtenemos el ID real de la pregunta
|
||||||
|
$idPreguntaAleatoria = $listaPreguntas[$posicionAleatoria];
|
||||||
|
|
||||||
|
// Comprobamos que esa pregunta no haya sido asignada ya
|
||||||
|
if (!in_array($idPreguntaAleatoria, $preguntasAsignadas)) {
|
||||||
|
$preguntasAsignadas[] = $idPreguntaAleatoria;
|
||||||
|
|
||||||
|
// Asignamos el ID real de la pregunta a la partida
|
||||||
|
$partida->asignarPregunta($idPreguntaAleatoria);
|
||||||
|
}
|
||||||
|
}//fin shile
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ==========================================
|
* ==========================================
|
||||||
* TODO CORRECTO
|
* TODO CORRECTO
|
||||||
@@ -218,7 +256,7 @@ switch ($_POST['orden']) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'exito' => 'Sala creada correctamente.',
|
'exito' => 'Sala creada correctamente. Preguntas preparadas.',
|
||||||
'idPartida' => $resultadoPartida['exito_tecnico'],
|
'idPartida' => $resultadoPartida['exito_tecnico'],
|
||||||
'idEquipo1' => $equipo1->idEquipo,
|
'idEquipo1' => $equipo1->idEquipo,
|
||||||
'idEquipo2' => $equipo2->idEquipo
|
'idEquipo2' => $equipo2->idEquipo
|
||||||
|
|||||||
@@ -55,10 +55,11 @@ switch ($_POST['orden']) {
|
|||||||
|
|
||||||
if ($resultado instanceof Usuario) {
|
if ($resultado instanceof Usuario) {
|
||||||
|
|
||||||
// === AÑADIR ESTAS LÍNEAS PARA GUARDAR EN SESIÓN ===
|
// === GUARDAR EN SESIÓN (incluido avatar)===
|
||||||
$_SESSION['idUsuario'] = $resultado->getIdUsuario();
|
$_SESSION['idUsuario'] = $resultado->getIdUsuario();
|
||||||
$_SESSION['nombreUsuario'] = $resultado->getNombreUsuario();
|
$_SESSION['nombreUsuario'] = $resultado->getNombreUsuario();
|
||||||
$_SESSION['email'] = $resultado->getEmail();
|
$_SESSION['email'] = $resultado->getEmail();
|
||||||
|
$_SESSION['avatar'] = $resultado->getAvatar();
|
||||||
// =================================================
|
// =================================================
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
@@ -83,6 +84,7 @@ switch ($_POST['orden']) {
|
|||||||
unset($_SESSION['idUsuario']);
|
unset($_SESSION['idUsuario']);
|
||||||
unset($_SESSION['email']);
|
unset($_SESSION['email']);
|
||||||
unset($_SESSION['nombreUsuario']);
|
unset($_SESSION['nombreUsuario']);
|
||||||
|
unset($_SESSION['avatar']);
|
||||||
|
|
||||||
// Destruimos la sesión
|
// Destruimos la sesión
|
||||||
session_destroy();
|
session_destroy();
|
||||||
@@ -92,7 +94,6 @@ switch ($_POST['orden']) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'mostrarEstadisticas':
|
case 'mostrarEstadisticas':
|
||||||
|
|
||||||
$usuario = Usuario::buscarPorId($_SESSION['idUsuario']);
|
$usuario = Usuario::buscarPorId($_SESSION['idUsuario']);
|
||||||
@@ -237,16 +238,17 @@ switch ($_POST['orden']) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'comprobarSesion':
|
case 'comprobarSesion':
|
||||||
if (isset($_SESSION['idUsuario']) && !empty($_SESSION['idUsuario'])) {
|
if (isset($_SESSION['idUsuario']) && !empty($_SESSION['idUsuario'])) {
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'activa' => true,
|
'activa' => true,
|
||||||
'usuario' => [
|
'usuario' => [
|
||||||
'idUsuario' => $_SESSION['idUsuario'],
|
'idUsuario' => $_SESSION['idUsuario'],
|
||||||
'nombreUsuario' => $_SESSION['nombreUsuario'] ?? ''
|
'nombreUsuario' => $_SESSION['nombreUsuario'] ?? '',
|
||||||
]
|
'avatar' => $_SESSION['avatar'] ?? ''
|
||||||
]);
|
]
|
||||||
} else {
|
]);
|
||||||
echo json_encode(['activa' => false]);
|
} else {
|
||||||
}
|
echo json_encode(['activa' => false]);
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -68,8 +68,8 @@
|
|||||||
|
|
||||||
.btn-unirse {
|
.btn-unirse {
|
||||||
border: none;
|
border: none;
|
||||||
border-bottom: 3px solid #0c4891;
|
border-bottom: 3px solid #1f6f09;
|
||||||
background-color: var(--kahoot-blue);
|
background-color: #26890c;
|
||||||
color: white;
|
color: white;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -105,3 +105,11 @@
|
|||||||
border-color: var(--kahoot-purple);
|
border-color: var(--kahoot-purple);
|
||||||
box-shadow: 0 0 0 3px rgba(70, 23, 143, 0.15);
|
box-shadow: 0 0 0 3px rgba(70, 23, 143, 0.15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.jugador-host {
|
||||||
|
background-color: #fff3cd;
|
||||||
|
border: 1px solid #ffc107;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.9 KiB |
+51
-20
@@ -123,12 +123,24 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
let jugadoresHTML = "";
|
let jugadoresHTML = "";
|
||||||
if (jugadoresEquipo.length > 0) {
|
if (jugadoresEquipo.length > 0) {
|
||||||
jugadoresEquipo.forEach(function (jugador) {
|
jugadoresEquipo.forEach(function (jugador) {
|
||||||
|
const esHost = jugador.idUsuario == partida.idUsuario;
|
||||||
|
|
||||||
jugadoresHTML += `
|
jugadoresHTML += `
|
||||||
<div class="jugador">
|
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||||
<span class="avatar">👤</span>
|
esHost ? "jugador-host" : ""
|
||||||
${escapeHTML(jugador.nombreUsuario)}
|
}">
|
||||||
</div>
|
<div>
|
||||||
`;
|
<span class="avatar">${esHost ? "👑" : "👤"}</span>
|
||||||
|
${escapeHTML(jugador.nombreUsuario)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
esHost
|
||||||
|
? `<span class="badge bg-warning text-dark ms-2">HOST</span>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
jugadoresHTML = `<div class="text-muted small">Sin jugadores</div>`;
|
jugadoresHTML = `<div class="text-muted small">Sin jugadores</div>`;
|
||||||
@@ -138,7 +150,7 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
let botonUnirseHTML = "";
|
let botonUnirseHTML = "";
|
||||||
if (!usuarioYaEstaEnEquipo) {
|
if (!usuarioYaEstaEnEquipo) {
|
||||||
botonUnirseHTML = `
|
botonUnirseHTML = `
|
||||||
<button type="button" class="btn btn-unirse w-100 btn-unirse-equipo mt-2"
|
<button type="button" class="btn-unirse w-100 btn-unirse-equipo mt-2"
|
||||||
data-id-partida="${partida.idPartida}"
|
data-id-partida="${partida.idPartida}"
|
||||||
data-id-equipo="${equipo.idEquipo}">
|
data-id-equipo="${equipo.idEquipo}">
|
||||||
Unirse
|
Unirse
|
||||||
@@ -157,25 +169,42 @@ function mostrarSala(partida, equipos, jugadores) {
|
|||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
||||||
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
||||||
let accionesSalaHTML = "";
|
let accionesSalaHTML = "";
|
||||||
|
|
||||||
if (usuarioYaEstaEnEquipo) {
|
if (usuarioYaEstaEnEquipo) {
|
||||||
accionesSalaHTML = `
|
let botonIniciarHTML = "";
|
||||||
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
|
||||||
<button type="button" class="btn btn-outline-danger btn-abandonar-sala" data-id-partida="${partida.idPartida}">
|
// Solo el host puede iniciar la partida
|
||||||
Abandonar sala
|
if (partida.idUsuario == idUsuarioSesion) {
|
||||||
</button>
|
botonIniciarHTML = `
|
||||||
<a href="juego.php?idPartida=${partida.idPartida}" class="btn btn-success btn-lg px-4">
|
<a href="juego.php?idPartida=${partida.idPartida}"
|
||||||
🎮 ¡Iniciar Partida!
|
class="btn btn-success btn-lg px-4">
|
||||||
</a>
|
🎮 ¡Iniciar Partida!
|
||||||
</div>
|
</a>
|
||||||
`;
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
accionesSalaHTML = `
|
||||||
|
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
||||||
|
|
||||||
|
<button type="button"
|
||||||
|
class="btn btn-outline-danger btn-abandonar-sala"
|
||||||
|
data-id-partida="${partida.idPartida}">
|
||||||
|
Abandonar sala
|
||||||
|
</button>
|
||||||
|
|
||||||
|
${botonIniciarHTML}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const salaHTML = `
|
const salaHTML = `
|
||||||
<div class="col-12 col-md-10 col-lg-8">
|
<div class="col-12 col-md-10 col-lg-8">
|
||||||
<div class="sala card p-3 shadow-sm mb-4">
|
<div class="sala card p-3 shadow-sm mb-4">
|
||||||
<div class="sala-header h4 text-center mb-3">
|
<div class="sala-header h4 text-center mb-3 text-white">
|
||||||
${escapeHTML(partida.nombrePartida)}
|
${escapeHTML(partida.nombrePartida)}
|
||||||
</div>
|
</div>
|
||||||
<div class="sala-body">
|
<div class="sala-body">
|
||||||
@@ -234,13 +263,15 @@ let botonAbandonarReferencia = null;
|
|||||||
// A. Al hacer clic en el botón "Abandonar sala" de la tarjeta, abrimos el modal
|
// A. Al hacer clic en el botón "Abandonar sala" de la tarjeta, abrimos el modal
|
||||||
$(document).on("click", ".btn-abandonar-sala", function () {
|
$(document).on("click", ".btn-abandonar-sala", function () {
|
||||||
botonAbandonarReferencia = $(this);
|
botonAbandonarReferencia = $(this);
|
||||||
const modal = new bootstrap.Modal(document.getElementById('modalAbandonarSala'));
|
const modal = new bootstrap.Modal(
|
||||||
|
document.getElementById("modalAbandonarSala"),
|
||||||
|
);
|
||||||
modal.show();
|
modal.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
||||||
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||||
const modalEl = document.getElementById('modalAbandonarSala');
|
const modalEl = document.getElementById("modalAbandonarSala");
|
||||||
const modalInstance = bootstrap.Modal.getInstance(modalEl);
|
const modalInstance = bootstrap.Modal.getInstance(modalEl);
|
||||||
|
|
||||||
const btnConfirmar = $(this);
|
const btnConfirmar = $(this);
|
||||||
@@ -253,7 +284,7 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
|||||||
data: { orden: "salirDeSala" },
|
data: { orden: "salirDeSala" },
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
||||||
|
|
||||||
if (modalInstance) {
|
if (modalInstance) {
|
||||||
modalInstance.hide();
|
modalInstance.hide();
|
||||||
}
|
}
|
||||||
@@ -275,7 +306,7 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
|||||||
if (modalInstance) {
|
if (modalInstance) {
|
||||||
modalInstance.hide();
|
modalInstance.hide();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// 8. Evento: Crear Sala
|
// 8. Evento: Crear Sala
|
||||||
|
|||||||
+18
-17
@@ -1,3 +1,5 @@
|
|||||||
|
let idUsuarioSesion = null;
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// Comprobar la sesión activa al cargar la página
|
// Comprobar la sesión activa al cargar la página
|
||||||
comprobarEstadoSesion();
|
comprobarEstadoSesion();
|
||||||
@@ -26,7 +28,7 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comprueba con el servidor si existe una sesión PHP activa.
|
* Comprueba con el servidor si existe una sesión PHP
|
||||||
*/
|
*/
|
||||||
function comprobarEstadoSesion() {
|
function comprobarEstadoSesion() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -36,8 +38,8 @@ function comprobarEstadoSesion() {
|
|||||||
data: { orden: 'comprobarSesion' },
|
data: { orden: 'comprobarSesion' },
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
if (respuesta.activa) {
|
if (respuesta.activa) {
|
||||||
|
idUsuarioSesion = respuesta.usuario.idUsuario;
|
||||||
renderizarCabeceraConSesion(respuesta.usuario);
|
renderizarCabeceraConSesion(respuesta.usuario);
|
||||||
// Si existe el contenedor del botón Jugar en index, lo mostramos
|
|
||||||
$('#colBotonJugar').removeClass('d-none');
|
$('#colBotonJugar').removeClass('d-none');
|
||||||
} else {
|
} else {
|
||||||
renderizarCabeceraSinSesion();
|
renderizarCabeceraSinSesion();
|
||||||
@@ -79,13 +81,8 @@ function ejecutarLogin() {
|
|||||||
$('#modalLogin').modal('hide');
|
$('#modalLogin').modal('hide');
|
||||||
$('#formLogin')[0].reset();
|
$('#formLogin')[0].reset();
|
||||||
|
|
||||||
renderizarCabeceraConSesion({
|
// Cargar datos de la sesión actualizados
|
||||||
idUsuario: respuesta.idUsuario,
|
comprobarEstadoSesion();
|
||||||
nombreUsuario: respuesta.nombreUsuario,
|
|
||||||
avatar: respuesta.avatar
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#colBotonJugar').removeClass('d-none');
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function () {
|
||||||
@@ -132,7 +129,7 @@ function ejecutarRegistro() {
|
|||||||
$('#modalRegistro').modal('hide');
|
$('#modalRegistro').modal('hide');
|
||||||
$('#formRegistro')[0].reset();
|
$('#formRegistro')[0].reset();
|
||||||
|
|
||||||
// Autologin
|
// Autologin tras registrarse
|
||||||
$('#loginEmail').val(email);
|
$('#loginEmail').val(email);
|
||||||
$('#loginPassword').val(pass);
|
$('#loginPassword').val(pass);
|
||||||
ejecutarLogin();
|
ejecutarLogin();
|
||||||
@@ -165,15 +162,21 @@ function cerrarSesion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza la cabecera cuando HAY sesión iniciada (Menú Perfil + Avatar)
|
* Renderiza la cabecera cuando HAY sesión iniciada
|
||||||
*/
|
*/
|
||||||
function renderizarCabeceraConSesion(usuario) {
|
function renderizarCabeceraConSesion(usuario) {
|
||||||
let avatarImg = usuario.avatar ? usuario.avatar : 'img/avatars/defaultProfile.jpeg';
|
//Mete el avatar en cabecera
|
||||||
|
let avatarImg = (usuario.avatar && usuario.avatar !== '')
|
||||||
|
? usuario.avatar
|
||||||
|
: 'img/avatars/defaultProfile.jpeg';
|
||||||
|
|
||||||
|
// Refrescar avatar si se cambia
|
||||||
|
let avatarConCacheBuster = avatarImg + '?v=' + new Date().getTime();
|
||||||
|
|
||||||
let html = `
|
let html = `
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button class="btn btn-outline-light dropdown-toggle d-flex align-items-center gap-2 rounded-pill px-3 py-1 fw-bold" type="button" id="userMenu" data-bs-toggle="dropdown" aria-expanded="false">
|
<button class="btn btn-outline-light dropdown-toggle d-flex align-items-center gap-2 rounded-pill px-3 py-1 fw-bold" type="button" id="userMenu" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<img src="${avatarImg}" alt="Avatar" class="rounded-circle border" style="width: 32px; height: 32px; object-fit: cover;">
|
<img src="${avatarConCacheBuster}" alt="Avatar" class="rounded-circle border" style="width: 32px; height: 32px; object-fit: cover;">
|
||||||
<span>${escapeHtml(usuario.nombreUsuario)}</span>
|
<span>${escapeHtml(usuario.nombreUsuario)}</span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu dropdown-menu-end shadow border-0 mt-2" aria-labelledby="userMenu">
|
<ul class="dropdown-menu dropdown-menu-end shadow border-0 mt-2" aria-labelledby="userMenu">
|
||||||
@@ -195,13 +198,11 @@ function renderizarCabeceraConSesion(usuario) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza los botones originales:
|
* Renderiza los botones en la cabecera cuando NO hay sesión (Iniciar sesión azul)
|
||||||
* - "Iniciar Sesión" (Rojo -> btn-danger)
|
|
||||||
* - "Registrarse" (Verde -> btn-success)
|
|
||||||
*/
|
*/
|
||||||
function renderizarCabeceraSinSesion() {
|
function renderizarCabeceraSinSesion() {
|
||||||
let html = `
|
let html = `
|
||||||
<button class="btn btn-danger rounded-pill px-4 fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
<button class="btn btn-primary rounded-pill px-4 fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#modalLogin">
|
||||||
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar sesión
|
<i class="fa-solid fa-right-to-bracket me-1"></i> Iniciar sesión
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-success rounded-pill px-4 fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
<button class="btn btn-success rounded-pill px-4 fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#modalRegistro">
|
||||||
|
|||||||
+21
-28
@@ -26,6 +26,10 @@ $.ajax({
|
|||||||
function cambiarNombre() {
|
function cambiarNombre() {
|
||||||
let nuevoNombre = $("#nuevoNombre").val().trim();
|
let nuevoNombre = $("#nuevoNombre").val().trim();
|
||||||
|
|
||||||
|
if (nuevoNombre === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "controladores/controladorUsuario.php",
|
url: "controladores/controladorUsuario.php",
|
||||||
@@ -42,8 +46,13 @@ function cambiarNombre() {
|
|||||||
// Actualizamos el nombre mostrado en la página
|
// Actualizamos el nombre mostrado en la página
|
||||||
$("#nombre").text(respuesta.nombreUsuario);
|
$("#nombre").text(respuesta.nombreUsuario);
|
||||||
|
|
||||||
// Limpiamos el input
|
|
||||||
$("#nuevoNombre").val("");
|
$("#nuevoNombre").val("");
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof comprobarEstadoSesion === "function") {
|
||||||
|
comprobarEstadoSesion();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -74,14 +83,11 @@ $("#inputFoto").change(function () {
|
|||||||
// Comprobamos que sea una imagen
|
// Comprobamos que sea una imagen
|
||||||
if (!archivo.type.startsWith("image/")) {
|
if (!archivo.type.startsWith("image/")) {
|
||||||
alert("El archivo seleccionado no es una imagen.");
|
alert("El archivo seleccionado no es una imagen.");
|
||||||
|
|
||||||
$("#inputFoto").val("");
|
$("#inputFoto").val("");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let datos = new FormData();
|
let datos = new FormData();
|
||||||
|
|
||||||
datos.append("avatar", archivo);
|
datos.append("avatar", archivo);
|
||||||
datos.append("orden", "cambiarAvatar");
|
datos.append("orden", "cambiarAvatar");
|
||||||
|
|
||||||
@@ -97,18 +103,23 @@ $("#inputFoto").change(function () {
|
|||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
} else {
|
} else {
|
||||||
// Actualizamos la imagen sin recargar la página
|
// Actualizamos la imagen en la página de perfil sin recargar
|
||||||
$("#fotoPerfil").attr(
|
$("#fotoPerfil").attr(
|
||||||
"src",
|
"src",
|
||||||
respuesta.avatar + "?t=" + new Date().getTime(),
|
respuesta.avatar + "?t=" + new Date().getTime()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Actualizamos también el avatar superior en la cabecera
|
||||||
|
if (typeof comprobarEstadoSesion === "function") {
|
||||||
|
comprobarEstadoSesion();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// =========================
|
// =========================
|
||||||
// RECOGER CATEGORIAS
|
// RECOGER CATEGORIAS
|
||||||
// ====
|
// =========================
|
||||||
|
|
||||||
$("#modalCrearPregunta").on("show.bs.modal", function () {
|
$("#modalCrearPregunta").on("show.bs.modal", function () {
|
||||||
const selectCategoria = $("#idCategoria");
|
const selectCategoria = $("#idCategoria");
|
||||||
@@ -141,16 +152,14 @@ $("#modalCrearPregunta").on("show.bs.modal", function () {
|
|||||||
$("<option>", {
|
$("<option>", {
|
||||||
value: categoria.idCategoria,
|
value: categoria.idCategoria,
|
||||||
text: categoria.nombreCategoria,
|
text: categoria.nombreCategoria,
|
||||||
}),
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al cargar las categorías:", error);
|
console.error("Error al cargar las categorías:", error);
|
||||||
|
|
||||||
console.error("Respuesta del servidor:", xhr.responseText);
|
console.error("Respuesta del servidor:", xhr.responseText);
|
||||||
|
|
||||||
alert("No se han podido cargar las categorías.");
|
alert("No se han podido cargar las categorías.");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -158,7 +167,7 @@ $("#modalCrearPregunta").on("show.bs.modal", function () {
|
|||||||
|
|
||||||
// =========================
|
// =========================
|
||||||
// CREAR PREGUNTA
|
// CREAR PREGUNTA
|
||||||
// ====
|
// =========================
|
||||||
|
|
||||||
$("#formCrearPregunta").on("submit", function (e) {
|
$("#formCrearPregunta").on("submit", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -188,24 +197,15 @@ $("#formCrearPregunta").on("submit", function (e) {
|
|||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPregunta.php",
|
url: "controladores/controladorPregunta.php",
|
||||||
|
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "crearPregunta",
|
orden: "crearPregunta",
|
||||||
|
|
||||||
idCategoria: $("#idCategoria").val(),
|
idCategoria: $("#idCategoria").val(),
|
||||||
|
|
||||||
nombrePregunta: pregunta,
|
nombrePregunta: pregunta,
|
||||||
|
|
||||||
respuestaCorrecta: respuestaCorrecta,
|
respuestaCorrecta: respuestaCorrecta,
|
||||||
|
|
||||||
respuestaIncorrecta1: respuestaIncorrecta1,
|
respuestaIncorrecta1: respuestaIncorrecta1,
|
||||||
|
|
||||||
respuestaIncorrecta2: respuestaIncorrecta2,
|
respuestaIncorrecta2: respuestaIncorrecta2,
|
||||||
|
|
||||||
respuestaIncorrecta3: respuestaIncorrecta3,
|
respuestaIncorrecta3: respuestaIncorrecta3,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -214,10 +214,8 @@ $("#formCrearPregunta").on("submit", function (e) {
|
|||||||
|
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
|
|
||||||
boton.prop("disabled", false);
|
boton.prop("disabled", false);
|
||||||
boton.text("Crear pregunta");
|
boton.text("Crear pregunta");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,21 +231,16 @@ $("#formCrearPregunta").on("submit", function (e) {
|
|||||||
// Volvemos a activar el botón
|
// Volvemos a activar el botón
|
||||||
boton.prop("disabled", false);
|
boton.prop("disabled", false);
|
||||||
boton.text("Crear pregunta");
|
boton.text("Crear pregunta");
|
||||||
|
|
||||||
// Si tienes que actualizar la lista de preguntas:
|
|
||||||
// cargarPreguntas();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al crear la pregunta:", error);
|
console.error("Error al crear la pregunta:", error);
|
||||||
|
|
||||||
console.error("Respuesta del servidor:", xhr.responseText);
|
console.error("Respuesta del servidor:", xhr.responseText);
|
||||||
|
|
||||||
alert("No se ha podido crear la pregunta.");
|
alert("No se ha podido crear la pregunta.");
|
||||||
|
|
||||||
boton.prop("disabled", false);
|
boton.prop("disabled", false);
|
||||||
boton.text("Crear pregunta");
|
boton.text("Crear pregunta");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -2365,3 +2365,4 @@ UNLOCK TABLES;
|
|||||||
/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */;
|
/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */;
|
||||||
|
|
||||||
-- Dump completed on 2026-09-25 10:00:41
|
-- Dump completed on 2026-09-25 10:00:41
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user