Compare commits
37 Commits
7969685d02
..
prueba
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bf5b7a3bc | |||
| e8accf949e | |||
| fa883cde39 | |||
| ae213a3d12 | |||
| cd0685f41c | |||
| e3395a017c | |||
| 396aca8b03 | |||
| c6db380ef9 | |||
| 8d5d7da615 | |||
| 7f70112f63 | |||
| a66ac7086d | |||
| eed77db62f | |||
| 83545152bb | |||
| 71fb45b94c | |||
| 5b6352b4ee | |||
| 7e1344a395 | |||
| db5061ec7f | |||
| 737b76e83b | |||
| 3705a9ea9e | |||
| 72134b405c | |||
| 91056a05d9 | |||
| 18a56e0bbd | |||
| ed7067161a | |||
| 2531ef321a | |||
| d3e523ad73 | |||
| 77249ba51b | |||
| 5446352cf9 | |||
| 95f7d8dad6 | |||
| 4f6e15863e | |||
| 2169586cd9 | |||
| 98b383d16f | |||
| 87c8ea871a | |||
| 1980f7582f | |||
| d8837484b0 | |||
| d5cd07b135 | |||
| fc7629143d | |||
| d22a642cca |
@@ -59,7 +59,7 @@ Configuración de acceso al servidor de producción:
|
|||||||
- SSH/SCP/SFTP:
|
- SSH/SCP/SFTP:
|
||||||
- Host: desarrolloalcala.com
|
- Host: desarrolloalcala.com
|
||||||
- Puerto: 2222
|
- Puerto: 2222
|
||||||
- Usuario: alumnado
|
- Usuario: my_webapp
|
||||||
- Contraseña: epdsrntr\*\*
|
- Contraseña: epdsrntr\*\*
|
||||||
- Acceso WEB al panel de control:
|
- Acceso WEB al panel de control:
|
||||||
- URL: http://desarrolloalcala.com
|
- URL: http://desarrolloalcala.com
|
||||||
|
|||||||
+1
-1
@@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
||||||
<button type="button" class="btn btn-kahoot-login" id="btnCrearSala">Crear sala</button>
|
<button type="button" class="btn btn-kahoot-register" id="btnCrearSala">Crear sala</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+6
-8
@@ -49,6 +49,11 @@
|
|||||||
<input type="password" class="form-control border-dark" id="loginPassword" name="contrasena" placeholder="Contraseña" required>
|
<input type="password" class="form-control border-dark" id="loginPassword" name="contrasena" placeholder="Contraseña" required>
|
||||||
<label for="loginPassword">Contraseña</label>
|
<label for="loginPassword">Contraseña</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" id="recordar" name="recordar" type="checkbox" />
|
||||||
|
<label for="recordar" class="small">Recuérdeme durante 10 días</label>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" name="orden" value="validar">
|
||||||
</form>
|
</form>
|
||||||
<div id="errorLogin" class="text-danger fw-bold mt-2"></div>
|
<div id="errorLogin" class="text-danger fw-bold mt-2"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -88,14 +93,7 @@
|
|||||||
<input type="password" class="form-control border-dark" id="regPasswordConfirm" name="contrasenaConfirm" placeholder="Confirmar contraseña" required>
|
<input type="password" class="form-control border-dark" id="regPasswordConfirm" name="contrasenaConfirm" placeholder="Confirmar contraseña" required>
|
||||||
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
<label for="regPasswordConfirm">Confirmar contraseña</label>
|
||||||
</div>
|
</div>
|
||||||
|
<input type="hidden" name="orden" value="registrar">
|
||||||
<!-- Checkbox Recuérdame -->
|
|
||||||
<div class="form-check mb-3">
|
|
||||||
<input class="form-check-input border-dark" type="checkbox" value="" id="recuerdameCheck">
|
|
||||||
<label class="form-check-label fw-semibold" for="recuerdameCheck">
|
|
||||||
Recuérdame en 10 días
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
<div id="errorRegistro" class="text-danger fw-bold mt-2"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
require_once __DIR__ . '/ClaseRespuestaAlmacenada.php';
|
require_once __DIR__ . '/claseRespuestaAlmacenada.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lógica de la dinámica de juego (la usa juego.php a través de ControladorJuego.php):
|
* Lógica de la dinámica de juego (la usa juego.php a través de controladorJuego.php):
|
||||||
* - deja preparadas las 10 preguntas de la partida
|
* - deja preparadas las 10 preguntas de la partida
|
||||||
* - se las devuelve al jugador con sus respuestas SIN decir cuál es la correcta
|
* - se las devuelve al jugador con sus respuestas SIN decir cuál es la correcta
|
||||||
* - guarda la respuesta de cada jugador y le dice si ha acertado
|
* - guarda la respuesta de cada jugador y le dice si ha acertado
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
@@ -8,17 +7,27 @@ 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();
|
||||||
@@ -26,12 +35,7 @@ class Partida
|
|||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("
|
$consulta = $conexion->prepare("INSERT INTO partida (nombrePartida,idUsuario) VALUES (:nombrePartida,:idUsuario)");
|
||||||
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();
|
||||||
@@ -47,8 +51,7 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listar()
|
public function listar(){
|
||||||
{
|
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
@@ -65,18 +68,13 @@ 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("
|
$consulta = $conexion->prepare("SELECT * FROM partida WHERE idPartida=:idPartida");
|
||||||
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);
|
||||||
@@ -88,20 +86,14 @@ 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("
|
$consulta = $conexion->prepare("UPDATE partida SET nombrePartida=:nombrePartida, idUsuario=:idUsuario WHERE idPartida=:idPartida");
|
||||||
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);
|
||||||
@@ -118,17 +110,13 @@ 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("
|
$consulta = $conexion->prepare("DELETE FROM partida WHERE idPartida=:idPartida");
|
||||||
DELETE FROM partida
|
|
||||||
WHERE idPartida=:idPartida
|
|
||||||
");
|
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
return [
|
return [
|
||||||
@@ -143,48 +131,36 @@ class Partida
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function iniciar()
|
|
||||||
{
|
public function iniciarPartida(){
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)){
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("
|
$consulta = $conexion->prepare("UPDATE partida SET fechaInicio=NOW() WHERE idPartida=:idPartida AND fechaInicio IS NULL");
|
||||||
UPDATE partida
|
|
||||||
SET fechaInicio = NOW()
|
|
||||||
WHERE idPartida = :idPartida
|
|
||||||
AND fechaInicio IS NULL
|
|
||||||
");
|
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
return [
|
return [
|
||||||
"exito" => "La partida se inició correctamente.",
|
"exito" => "La partida ha comenzado.",
|
||||||
"exito_tecnico" => $this->idPartida
|
"exito_tecnico" => $this->idPartida
|
||||||
];
|
];
|
||||||
} catch (PDOException $error) {
|
} catch (PDOException $error) {
|
||||||
return [
|
return [
|
||||||
"error" => "No se pudo iniciar la partida.",
|
"error" => "Ocurrió un error al iniciar la partida.",
|
||||||
'error_tecnico' => $error->getMessage()
|
'error_tecnico' => $error->getMessage()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function finalizar()
|
public function finalizar(){
|
||||||
{
|
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("
|
$consulta = $conexion->prepare("UPDATE partida SET fechaFin=NOW() WHERE idPartida=:idPartida AND fechaFin IS NULL");
|
||||||
UPDATE partida
|
|
||||||
SET fechaFin = NOW()
|
|
||||||
WHERE idPartida = :idPartida
|
|
||||||
AND fechaInicio IS NOT NULL
|
|
||||||
AND fechaFin IS NULL
|
|
||||||
");
|
|
||||||
$consulta->bindParam(":idPartida", $this->idPartida);
|
$consulta->bindParam(":idPartida", $this->idPartida);
|
||||||
$consulta->execute();
|
$consulta->execute();
|
||||||
return [
|
return [
|
||||||
@@ -193,30 +169,83 @@ class Partida
|
|||||||
];
|
];
|
||||||
} catch (PDOException $error) {
|
} catch (PDOException $error) {
|
||||||
return [
|
return [
|
||||||
"error" => "No se pudo finalizar la partida.",
|
"error" => "Ocurrió un error al finalizar la partida.",
|
||||||
'error_tecnico' => $error->getMessage()
|
'error_tecnico' => $error->getMessage()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getPreguntas()
|
//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();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
return $conexion;
|
return $conexion;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$consulta = $conexion->prepare("
|
$consulta = $conexion->prepare("SELECT * FROM partida WHERE idUsuario=:idUsuario AND fechaFin IS NULL ORDER BY idPartida DESC LIMIT 1");
|
||||||
SELECT
|
$consulta->bindParam(":idUsuario", $this->idUsuario);
|
||||||
pxp.idPartidaxPregunta,
|
$consulta->execute();
|
||||||
p.*
|
return $consulta->fetch(PDO::FETCH_ASSOC);
|
||||||
FROM partidaxpregunta pxp
|
} catch (PDOException $error) {
|
||||||
INNER JOIN pregunta p
|
return [
|
||||||
ON pxp.idPregunta=p.idPregunta
|
"error" => "Ocurrió un error al buscar la partida en curso.",
|
||||||
WHERE pxp.idPartida=:idPartida
|
'error_tecnico' => $error->getMessage()
|
||||||
ORDER BY pxp.idPartidaxPregunta
|
];
|
||||||
");
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
* idPartidaxPregunta (necesario para guardar respuestas después).
|
||||||
|
*/
|
||||||
|
public function getPreguntas(){
|
||||||
|
$conexion = conexionBD();
|
||||||
|
if (is_array($conexion)) {
|
||||||
|
return $conexion;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$consulta = $conexion->prepare("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);
|
||||||
@@ -229,19 +258,13 @@ class Partida
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function asignarPregunta($idPregunta)
|
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("
|
$consulta = $conexion->prepare("INSERT INTO partidaxpregunta (idPartida,idPregunta) VALUES (:idPartida,:idPregunta)");
|
||||||
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();
|
||||||
@@ -257,18 +280,13 @@ 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("
|
$consulta = $conexion->prepare("SELECT COUNT(*) AS total FROM partidaxpregunta WHERE idPartida=:idPartida");
|
||||||
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);
|
||||||
@@ -281,21 +299,14 @@ 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("
|
$consulta = $conexion->prepare("SELECT COUNT(*) AS total FROM respuestaalmacenada ra INNER JOIN partidaxpregunta pxp
|
||||||
SELECT COUNT(*) AS total
|
ON ra.idPartidaxPregunta=pxp.idPartidaxPregunta WHERE pxp.idPartida=:idPartida AND ra.idUsuario=:idUsuario");
|
||||||
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();
|
||||||
@@ -310,11 +321,11 @@ class Partida
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sustituye al antiguo campo `terminada`: compara cuántas preguntas
|
* Indica si ESTE usuario ya ha respondido todas las preguntas:
|
||||||
* tiene la partida contra cuántas ha respondido este usuario.
|
* compara cuántas preguntas tiene la partida contra cuántas ha
|
||||||
|
* 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;
|
||||||
@@ -329,19 +340,13 @@ 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("
|
$consulta = $conexion->prepare("SELECT * FROM partida WHERE idUsuario=:idUsuario ORDER BY idPartida DESC");
|
||||||
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);
|
||||||
@@ -353,22 +358,13 @@ 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("
|
$consulta = $conexion->prepare("SELECT COUNT(*) AS total FROM partidaxpregunta WHERE idPartida=:idPartida AND idPregunta=:idPregunta");
|
||||||
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();
|
||||||
@@ -388,24 +384,13 @@ 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; // Si hay error en la conexión, lo devuelve
|
return $conexion;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Preparamos la consulta para insertar la relación en la tabla intermedia real
|
$consulta = $conexion->prepare("INSERT INTO equipoxpartida (idPartida, idEquipo) VALUES (:idPartida, :idEquipo)");
|
||||||
$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();
|
||||||
@@ -415,7 +400,6 @@ 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()
|
||||||
@@ -427,28 +411,14 @@ 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 {
|
try {
|
||||||
// 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
|
||||||
$consulta = $conexion->prepare("
|
INNER JOIN equipo e ON exp.idEquipo = e.idEquipo WHERE exp.idPartida = :idPartida ORDER BY e.nombreEquipo ASC");
|
||||||
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();
|
||||||
|
|
||||||
@@ -465,78 +435,29 @@ 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
|
||||||
$consulta = $conexion->prepare("
|
FROM equipoxpartida exp INNER JOIN equipoxusuario exu ON exp.idEquipo = exu.idEquipo INNER JOIN usuario u
|
||||||
SELECT DISTINCT
|
ON exu.idUsuario = u.idUsuario INNER JOIN equipo e ON exu.idEquipo = e.idEquipo WHERE exp.idPartida = :idPartida
|
||||||
u.idUsuario,
|
ORDER BY e.nombreEquipo ASC, u.nombreUsuario ASC");
|
||||||
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,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
// Clase encargada de registrar las respuestas de los jugadores en tiempo real durante la partida
|
// clase encargada de registrar las respuestas de los jugadores en tiempo real durante la partida
|
||||||
class RespuestaAlmacenada {
|
class RespuestaAlmacenada {
|
||||||
public $idRespuestaAlmacenada;
|
public $idRespuestaAlmacenada;
|
||||||
public $idPartidaxPregunta;
|
public $idPartidaxPregunta;
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
session_start();
|
|
||||||
|
|
||||||
require_once '../clases/ClaseJuego.php';
|
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
|
||||||
|
|
||||||
// Hay que estar logueado y decir de qué partida se trata
|
|
||||||
if (!isset($_SESSION['idUsuario'])) {
|
|
||||||
echo json_encode(['error' => 'Debes iniciar sesión para jugar.']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$idUsuario = (int)$_SESSION['idUsuario'];
|
|
||||||
$idPartida = intval($_POST['idPartida'] ?? 0);
|
|
||||||
|
|
||||||
if ($idPartida <= 0) {
|
|
||||||
echo json_encode(['error' => 'No se ha indicado la partida.']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Solo pueden jugar los usuarios que están en uno de los equipos de la partida
|
|
||||||
$perteneceAPartida = Juego::usuarioEnPartida($idPartida, $idUsuario);
|
|
||||||
|
|
||||||
if (is_array($perteneceAPartida)) {
|
|
||||||
echo json_encode($perteneceAPartida);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$perteneceAPartida) {
|
|
||||||
echo json_encode(['error' => 'No formas parte de esta partida.']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
switch ($_POST['orden'] ?? '') {
|
|
||||||
|
|
||||||
// Devuelve las 10 preguntas con sus respuestas (sin marcar la correcta)
|
|
||||||
case 'cargarPreguntas':
|
|
||||||
|
|
||||||
echo json_encode(Juego::cargarPreguntas($idPartida, $idUsuario));
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
// Guarda la respuesta del usuario y dice si ha acertado
|
|
||||||
case 'responder':
|
|
||||||
|
|
||||||
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta'] ?? 0);
|
|
||||||
$idRespuesta = intval($_POST['idRespuesta'] ?? 0);
|
|
||||||
|
|
||||||
if ($idPartidaxPregunta <= 0 || $idRespuesta <= 0) {
|
|
||||||
echo json_encode(['error' => 'Faltan datos para registrar la respuesta.']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode(
|
|
||||||
Juego::registrarRespuesta(
|
|
||||||
$idPartida,
|
|
||||||
$idUsuario,
|
|
||||||
$idPartidaxPregunta,
|
|
||||||
$idRespuesta
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
// Recibe los aciertos del jugador al terminar sus 10 preguntas,
|
|
||||||
// para que resultados.php los pueda usar al montar la hoja de resultados
|
|
||||||
case 'finalizarPartida':
|
|
||||||
|
|
||||||
$aciertos = intval($_POST['aciertos'] ?? 0);
|
|
||||||
|
|
||||||
if (!isset($_SESSION['aciertosPorPartida'])) {
|
|
||||||
$_SESSION['aciertosPorPartida'] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$_SESSION['aciertosPorPartida'][$idPartida] = $aciertos;
|
|
||||||
|
|
||||||
echo json_encode([
|
|
||||||
'exito' => 'Aciertos registrados correctamente.',
|
|
||||||
'idPartida' => $idPartida,
|
|
||||||
'aciertos' => $aciertos
|
|
||||||
]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
echo json_encode(['error' => 'La orden indicada no existe.']);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClaseCategoria.php';
|
require_once '../clases/claseCategoria.php';
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClaseEquipo.php';
|
require_once '../clases/claseEquipo.php';
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClaseEquipoxUsuario.php';
|
require_once '../clases/claseEquipoxUsuario.php';
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once '../clases/claseJuego.php';
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
// Comprobamos que haya un usuario conectado
|
||||||
|
|
||||||
|
if (!isset($_SESSION['idUsuario'])) {
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'Debes iniciar sesión para jugar.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$idUsuario = (int) $_SESSION['idUsuario'];
|
||||||
|
|
||||||
|
// Comprobamos que se haya indicado la partida
|
||||||
|
|
||||||
|
if (!isset($_POST['idPartida'])) {
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'No se ha indicado la partida.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$idPartida = intval($_POST['idPartida']);
|
||||||
|
|
||||||
|
if ($idPartida <= 0) {
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'La partida indicada no es válida.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprobamos que el usuario pertenezca a la partida
|
||||||
|
|
||||||
|
$perteneceAPartida = Juego::usuarioEnPartida($idPartida,$idUsuario);
|
||||||
|
|
||||||
|
if (is_array($perteneceAPartida)) {
|
||||||
|
echo json_encode($perteneceAPartida);
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!$perteneceAPartida) {
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'No formas parte de esta partida.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprobamos la orden
|
||||||
|
|
||||||
|
$orden = $_POST['orden'] ?? '';
|
||||||
|
|
||||||
|
switch ($orden) {
|
||||||
|
|
||||||
|
// CARGAR LAS PREGUNTAS DE LA PARTIDA
|
||||||
|
|
||||||
|
case 'cargarPreguntas':
|
||||||
|
|
||||||
|
$resultado = Juego::cargarPreguntas($idPartida, $idUsuario);
|
||||||
|
echo json_encode($resultado);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
// REGISTRAR RESPUESTA
|
||||||
|
|
||||||
|
case 'responder':
|
||||||
|
|
||||||
|
if (!isset($_POST['idPartidaxPregunta']) || !isset($_POST['idRespuesta'])){
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'Faltan datos para registrar la respuesta.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
|
||||||
|
|
||||||
|
$idRespuesta = intval($_POST['idRespuesta']);
|
||||||
|
|
||||||
|
if ($idPartidaxPregunta <= 0 || $idRespuesta <= 0){
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'Los datos de la respuesta no son válidos.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Registramos la respuesta del usuario
|
||||||
|
|
||||||
|
$resultado = Juego::registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta);
|
||||||
|
|
||||||
|
echo json_encode($resultado);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Finalizar la partida y registrar los aciertos del usuario
|
||||||
|
|
||||||
|
case 'finalizarPartida':
|
||||||
|
|
||||||
|
$aciertos = intval($_POST['aciertos'] ?? 0);
|
||||||
|
|
||||||
|
// Guardamos los aciertos en la sesión
|
||||||
|
|
||||||
|
if (!isset($_SESSION['aciertosPorPartida'])) {
|
||||||
|
|
||||||
|
$_SESSION['aciertosPorPartida'] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$_SESSION['aciertosPorPartida'][$idPartida] = $aciertos;
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'exito' => 'Aciertos registrados correctamente.',
|
||||||
|
|
||||||
|
'idPartida' => $idPartida,
|
||||||
|
|
||||||
|
'aciertos' => $aciertos
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'error' => 'La orden indicada no existe.'
|
||||||
|
]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -2,11 +2,11 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClasePartida.php';
|
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';
|
require_once '../clases/clasePregunta.php';
|
||||||
|
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClasePregunta.php';
|
require_once '../clases/clasePregunta.php';
|
||||||
require_once '../clases/ClaseRespuesta.php';
|
require_once '../clases/claseRespuesta.php';
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClaseRespuesta.php';
|
require_once '../clases/claseRespuesta.php';
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClaseRespuestaAlmacenada.php';
|
require_once '../clases/claseRespuestaAlmacenada.php';
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/triviagmatico/includes/conexionBD.php';
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/conexionBD.php';
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once '../clases/ClaseUsuario.php';
|
require_once '../clases/claseUsuario.php';
|
||||||
|
|
||||||
switch ($_POST['orden']) {
|
switch ($_POST['orden']) {
|
||||||
|
|
||||||
@@ -77,8 +77,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn-unirse:hover {
|
.btn-unirse:hover {
|
||||||
background-color: #0f56ab;
|
background-color: #1f6f09;
|
||||||
color: white;
|
color: white;
|
||||||
|
transform: translateY(-2px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-kahoot {
|
.modal-kahoot {
|
||||||
|
|||||||
@@ -401,3 +401,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.modal-kahoot {
|
||||||
|
border: none;
|
||||||
|
border-radius: 20px;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-kahoot-header {
|
||||||
|
background-color: var(--kahoot-purple);
|
||||||
|
color: white;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
@@ -1,9 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
//CARGA DE ARCHIVOS .ENV CON PHPDOTENV
|
//CARGA DE ARCHIVOS .ENV CON PHPDOTENV VERSION LOCAL
|
||||||
require('c:/laragon/vendor/autoload.php');//Se carga el módulo instalado con composer
|
require('c:/laragon/vendor/autoload.php');//Se carga el módulo instalado con composer
|
||||||
$dotenv = Dotenv\Dotenv::createImmutable('c:/laragon/', 'triviagmatico.env');//leemos el archivo. El primer parámetro es la ruta para llegar y el segundo el nombre del archivo .env
|
$dotenv = Dotenv\Dotenv::createImmutable('c:/laragon/', 'triviagmatico.env');//leemos el archivo. El primer parámetro es la ruta para llegar y el segundo el nombre del archivo .env
|
||||||
$dotenv->load();
|
$dotenv->load();
|
||||||
|
|
||||||
|
//CARGA DE ARCHIVOS .ENV CON PHPDOTENV VERSION SERVIDOR
|
||||||
|
/*
|
||||||
|
require('/var/vendor/autoload.php');//Se carga el módulo instalado con composer
|
||||||
|
$dotenv = Dotenv\Dotenv::createImmutable('/var/', 'triviagmatico.env');//leemos el archivo. El primer parámetro es la ruta para llegar y el segundo el nombre del archivo .env
|
||||||
|
$dotenv->load();
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
function conexionBD (){
|
function conexionBD (){
|
||||||
try{
|
try{
|
||||||
$servidor = 'mysql:host='.$_ENV['bDatosServer'].';dbname='.$_ENV['bDatos'];
|
$servidor = 'mysql:host='.$_ENV['bDatosServer'].';dbname='.$_ENV['bDatos'];
|
||||||
|
|||||||
+4
-4
@@ -9,7 +9,7 @@ function comprobarSalaUsuario() {
|
|||||||
$("#cargandoSalas").remove();
|
$("#cargandoSalas").remove();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/ControladorEquipoxUsuario.php",
|
url: "controladores/controladorEquipoxUsuario.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: { orden: "obtenerSalaUsuario" },
|
data: { orden: "obtenerSalaUsuario" },
|
||||||
@@ -231,7 +231,7 @@ $(document).on("click", ".btn-unirse-equipo", function () {
|
|||||||
boton.prop("disabled", true).text("Uniéndose...");
|
boton.prop("disabled", true).text("Uniéndose...");
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/ControladorEquipoxUsuario.php",
|
url: "controladores/controladorEquipoxUsuario.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: {
|
data: {
|
||||||
@@ -276,7 +276,7 @@ $(document).on("click", ".btn-abandonar-sala", function () {
|
|||||||
mensaje.text(
|
mensaje.text(
|
||||||
"Si abandonas la sala como anfitrión, la partida terminará para todos los jugadores.",
|
"Si abandonas la sala como anfitrión, la partida terminará para todos los jugadores.",
|
||||||
);
|
);
|
||||||
botonConfirmar.text("Sí, abandonar");
|
botonConfirmar.text("Sí, terminar partida");
|
||||||
} else {
|
} else {
|
||||||
titulo.text("¿Abandonar la sala?");
|
titulo.text("¿Abandonar la sala?");
|
||||||
mensaje.text(
|
mensaje.text(
|
||||||
@@ -302,7 +302,7 @@ $(document).on("click", "#btnConfirmarAbandonar", function () {
|
|||||||
btnConfirmar.prop("disabled", true).text("Saliendo...");
|
btnConfirmar.prop("disabled", true).text("Saliendo...");
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/ControladorEquipoxUsuario.php",
|
url: "controladores/controladorEquipoxUsuario.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: { orden: "salirDeSala" },
|
data: { orden: "salirDeSala" },
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ function comprobarSesion() {
|
|||||||
contenedor.empty();
|
contenedor.empty();
|
||||||
|
|
||||||
if (respuesta.activa && respuesta.usuario) {
|
if (respuesta.activa && respuesta.usuario) {
|
||||||
|
// Recogemos el idUsuario de la sesion en una variable para usarlo (no me lo volváis a borrar por favor os lo pido)
|
||||||
|
idUsuarioSesion = respuesta.usuario.idUsuario;
|
||||||
// Obtenemos la ruta del avatar o la de por defecto
|
// Obtenemos la ruta del avatar o la de por defecto
|
||||||
const avatarUrl =
|
const avatarUrl =
|
||||||
respuesta.usuario.avatar || "img/avatars/defaultProfile.jpeg";
|
respuesta.usuario.avatar || "img/avatars/defaultProfile.jpeg";
|
||||||
@@ -201,3 +203,4 @@ $(document).on("click", "#botonCerrarSesion", function (event) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -36,11 +36,11 @@ function renderizarTablaRanking(jugadores) {
|
|||||||
<thead class="table-dark">
|
<thead class="table-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" style="width: 10%;">#</th>
|
<th scope="col" style="width: 10%;">#</th>
|
||||||
<th scope="col" class="text-start" style="width: 35%;">Jugador</th>
|
<th scope="col" class="text-start" style="width: 30%;"><i class="fa-solid fa-user"></i> <br> Jugador</th>
|
||||||
<th scope="col" style="width: 15%;"><i class="fa-solid fa-trophy text-warning me-1"></i> Vic</th>
|
<th scope="col" style="width: 15%;"><i class="fa-solid fa-trophy text-warning me-1"></i> <br> Victorias</th>
|
||||||
<th scope="col" style="width: 15%;"><i class="fa-solid fa-xmark text-danger me-1"></i> Der</th>
|
<th scope="col" style="width: 15%;"><i class="fa-solid fa-xmark text-danger me-1"></i> <br> Derrotas</th>
|
||||||
<th scope="col" style="width: 15%;"><i class="fa-solid fa-bullseye text-success me-1"></i> Aciertos</th>
|
<th scope="col" style="width: 15%;"><i class="fa-solid fa-bullseye text-success me-1"></i> <br> Aciertos</th>
|
||||||
<th scope="col" style="width: 10%;"><i class="fa-solid fa-percent text-info me-1"></i> % Vic</th>
|
<th scope="col" style="width: 15%;"><i class="fa-solid fa-medal text-info me-1"></i> <br> Efectividad</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|||||||
+14
-2
@@ -2,7 +2,7 @@
|
|||||||
// Carga las preguntas de la partida, las muestra de una en una,
|
// Carga las preguntas de la partida, las muestra de una en una,
|
||||||
// guarda cada respuesta en el servidor y al terminar lleva a resultados.php
|
// guarda cada respuesta en el servidor y al terminar lleva a resultados.php
|
||||||
|
|
||||||
const URL_CONTROLADOR = "controladores/ControladorJuego.php";
|
const URL_CONTROLADOR = "controladores/controladorJuego.php";
|
||||||
const PAUSA_FEEDBACK = 1800; // ms que se ve si has acertado o fallado
|
const PAUSA_FEEDBACK = 1800; // ms que se ve si has acertado o fallado
|
||||||
|
|
||||||
// Colores y formas de los botones (estilo Kahoot, definidos en juego.css)
|
// Colores y formas de los botones (estilo Kahoot, definidos en juego.css)
|
||||||
@@ -20,7 +20,18 @@ let bloqueado = false; // true mientras se envía una respuesta o se ve el feedb
|
|||||||
let numeroAciertos = 0; // número de aciertos del jugador
|
let numeroAciertos = 0; // número de aciertos del jugador
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
idPartida = parseInt($("body").data("id-partida"), 10);
|
|
||||||
|
// Obtenemos el idPartida de la URL
|
||||||
|
// Ejemplo: juego.php?idPartida=3
|
||||||
|
|
||||||
|
const parametros = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
idPartida = parseInt(parametros.get("idPartida"), 10);
|
||||||
|
|
||||||
|
if (!idPartida || idPartida < 1) {
|
||||||
|
mostrarError("La partida indicada no es válida.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Un solo listener para todos los botones de respuesta
|
// Un solo listener para todos los botones de respuesta
|
||||||
$("#respuestas").on("click", ".btn-answer", function () {
|
$("#respuestas").on("click", ".btn-answer", function () {
|
||||||
@@ -103,6 +114,7 @@ function responder($botonPulsado) {
|
|||||||
if (bloqueado) {
|
if (bloqueado) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bloqueado = true;
|
bloqueado = true;
|
||||||
|
|
||||||
const pregunta = preguntas[indice];
|
const pregunta = preguntas[indice];
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
function comprobarEstadoPartida(idPartida, intervalo = null) {
|
function comprobarEstadoPartida(idPartida, intervalo = null) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/ControladorResultados.php",
|
url: "controladores/controladorResultados.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -1,22 +1,6 @@
|
|||||||
<?php
|
|
||||||
session_start();
|
|
||||||
|
|
||||||
// Hay que estar logueado para jugar
|
|
||||||
if (!isset($_SESSION['idUsuario'])) {
|
|
||||||
header('Location: index.php');
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// La partida llega por la URL: juego.php?idPartida=3
|
|
||||||
$idPartida = filter_input(INPUT_GET, 'idPartida', FILTER_VALIDATE_INT);
|
|
||||||
|
|
||||||
if (!$idPartida || $idPartida < 1) {
|
|
||||||
header('Location: buscadorSala.php');
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
@@ -24,28 +8,48 @@ if (!$idPartida || $idPartida < 1) {
|
|||||||
<title>Proyecto Trivial</title>
|
<title>Proyecto Trivial</title>
|
||||||
<link rel="stylesheet" href="css/juego.css">
|
<link rel="stylesheet" href="css/juego.css">
|
||||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body data-id-partida="<?= (int)$idPartida ?>">
|
|
||||||
|
|
||||||
<!-- Progreso: "Pregunta 3 de 10" + barra -->
|
<body>
|
||||||
|
|
||||||
|
<!-- CABECERA Y PROGRESO -->
|
||||||
|
|
||||||
<div class="game-header">
|
<div class="game-header">
|
||||||
<span id="contadorPregunta">Cargando…</span>
|
|
||||||
|
<span id="contadorPregunta">
|
||||||
|
Cargando…
|
||||||
|
</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="progress-track">
|
<div class="progress-track">
|
||||||
|
|
||||||
<div class="progress-fill" id="barraProgreso"></div>
|
<div class="progress-fill" id="barraProgreso"></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Contenedor de la Pregunta (lo rellena js/juego.js) -->
|
<!-- PREGUNTA -->
|
||||||
|
|
||||||
<div class="question-container">
|
<div class="question-container">
|
||||||
<div id="textoPregunta">Cargando preguntas…</div>
|
|
||||||
|
<div id="textoPregunta">
|
||||||
|
Cargando preguntas…
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="feedback" class="feedback" aria-live="polite"></div>
|
<div id="feedback" class="feedback" aria-live="polite"></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Contenedor de Respuestas (Estilo Kahoot, lo rellena js/juego.js) -->
|
<!-- RESPUESTAS -->
|
||||||
|
|
||||||
<div class="answers-grid" id="respuestas"></div>
|
<div class="answers-grid" id="respuestas"></div>
|
||||||
|
|
||||||
|
<!-- JAVASCRIPT -->
|
||||||
|
|
||||||
<script src="js/jquery-4.0.0.min.js"></script>
|
<script src="js/jquery-4.0.0.min.js"></script>
|
||||||
<script src="js/juego.js"></script>
|
<script src="js/juego.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -293,7 +293,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
Cancelar
|
Cancelar
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button type="submit" form="formCrearPregunta" class="btn btn-kahoot-login" id="btnCrearPregunta">
|
<button type="submit" form="formCrearPregunta" class="btn btn-kahoot-register" id="btnCrearPregunta">
|
||||||
<i class="bi bi-check-lg me-1"></i>
|
<i class="bi bi-check-lg me-1"></i>
|
||||||
Crear pregunta
|
Crear pregunta
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/triviagmatico/includes/conexionBD.php';
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/conexionBD.php';
|
||||||
|
|
||||||
$idPartida = intval($_GET['idPartida'] ?? 0);
|
$idPartida = intval($_GET['idPartida'] ?? 0);
|
||||||
if ($idPartida <= 0) {
|
if ($idPartida <= 0) {
|
||||||
@@ -89,7 +89,7 @@ usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos'];
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Resultados - Trivial</title>
|
<title>Resultados - Trivial</title>
|
||||||
<link rel="stylesheet" href="css/resultados.css">
|
<link rel="stylesheet" href="css/resultados.css">
|
||||||
<script src="https://jquery.com"></script>
|
<script src="https://cdn.jsdelivr.net/npm/jquery@4.0.0/dist/jquery.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body data-id-partida="<?php echo $idPartida; ?>">
|
<body data-id-partida="<?php echo $idPartida; ?>">
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
bDatosServer="localhost"
|
||||||
|
bDatos="my_webapp"
|
||||||
|
bDatosUser="my_webapp"
|
||||||
|
bDatosPass="07tCqBO3B6Q3cncKMF2FHcpgsLjFTx"
|
||||||
|
urlBase="http://triviagmatico.test"
|
||||||
|
dirBase="/var/www/my_webapp/www"
|
||||||
Reference in New Issue
Block a user