Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d6272c664 | |||
| 3a888fc6eb | |||
| 67224911dc | |||
| 9657374edd | |||
| 6b7e54f1ee | |||
| 4ee0f619cf | |||
| 18ba294dc7 | |||
| e081b831b4 |
@@ -53,10 +53,26 @@ Equipos de Backend y Frontend.
|
||||
# Notas sueltas
|
||||
|
||||
## Publicación en el servidor
|
||||
|
||||
Configuración de acceso al servidor de producción:
|
||||
|
||||
- SSH/SCP/SFTP:
|
||||
- Host: desarrolloalcala.com
|
||||
- Puerto: 2222
|
||||
- Usuario: alumnado
|
||||
- Contraseña: epdsrntr\*\*
|
||||
- Acceso WEB al panel de control:
|
||||
- URL: http://desarrolloalcala.com
|
||||
- Usuario: alumnado
|
||||
- Contraseña: epdsrntr\*\*
|
||||
- Acceso a PHPMyAdmin
|
||||
- http://desarrolloalcala.com/phpmyadmin
|
||||
- usuario: alumnado
|
||||
- contraseña: epdsrntr\*\*
|
||||
|
||||
Here are information to log into the database:
|
||||
|
||||
- Type: mysql
|
||||
- Database user: my_webapp
|
||||
- Database name: my_webapp
|
||||
- Password: 07tCqBO3B6Q3cncKMF2FHcpgsLjFTx
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once '../includes/conexionBD.php';
|
||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||
|
||||
class Partida
|
||||
{
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once '../clases/ClaseCategoria.php';
|
||||
|
||||
switch ($_POST['orden']) {
|
||||
|
||||
case 'crearCategoria':
|
||||
|
||||
$nombreCategoria = trim($_POST['nombreCategoria'] ?? '');
|
||||
|
||||
if ($nombreCategoria == '') {
|
||||
echo json_encode(['error' => 'El nombre de la categoría es obligatorio']);
|
||||
break;
|
||||
}
|
||||
|
||||
$categoria = new Categoria(null, $nombreCategoria);
|
||||
$resultado = $categoria->crear();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'listarCategorias':
|
||||
|
||||
$categoria = new Categoria();
|
||||
$resultado = $categoria->listar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'buscarCategoria':
|
||||
|
||||
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
||||
|
||||
$categoria = new Categoria($idCategoria);
|
||||
$resultado = $categoria->buscar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'borrarCategoria':
|
||||
|
||||
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
||||
|
||||
$categoria = new Categoria($idCategoria);
|
||||
$resultado = $categoria->borrar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once '../clases/ClaseEquipo.php';
|
||||
|
||||
switch ($_POST['orden']) {
|
||||
|
||||
case 'crearEquipo':
|
||||
|
||||
$nombreEquipo = trim($_POST['nombreEquipo'] ?? '');
|
||||
|
||||
if ($nombreEquipo == '') {
|
||||
echo json_encode(['error' => 'El nombre del equipo es obligatorio']);
|
||||
break;
|
||||
}
|
||||
|
||||
$equipo = new Equipo(null, $nombreEquipo);
|
||||
$resultado = $equipo->crear();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'listarEquipos':
|
||||
|
||||
$equipo = new Equipo();
|
||||
$resultado = $equipo->listar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'buscarEquipo':
|
||||
|
||||
$idEquipo = intval($_POST['idEquipo'] ?? 0);
|
||||
|
||||
$equipo = new Equipo($idEquipo);
|
||||
$resultado = $equipo->buscar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'borrarEquipo':
|
||||
|
||||
$idEquipo = intval($_POST['idEquipo'] ?? 0);
|
||||
|
||||
$equipo = new Equipo($idEquipo);
|
||||
$resultado = $equipo->borrar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,987 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once '../clases/ClasePartida.php';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
switch ($_POST['orden']) {
|
||||
|
||||
|
||||
|
||||
case 'listar':
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$listadoPartidas = $partida->listar();
|
||||
|
||||
echo json_encode($listadoPartidas);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'buscar':
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida = intval($_POST['idPartida']);
|
||||
|
||||
$resultado = $partida->buscar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'crear':
|
||||
|
||||
//Comprobamos que haya un usuario conectado
|
||||
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión para crear una partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Comprobamos que se haya introducido un nombre
|
||||
|
||||
|
||||
if (
|
||||
!isset($_POST['nombrePartida']) ||
|
||||
trim($_POST['nombrePartida']) === ''
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'El nombre de la partida es obligatorio.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Creamos la partida
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->nombrePartida = trim($_POST['nombrePartida']);
|
||||
|
||||
|
||||
//El usuario conectado será el propietario de la partida.
|
||||
|
||||
$partida->idUsuario = $_SESSION['idUsuario'];
|
||||
|
||||
|
||||
$resultado = $partida->insertar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'editar':
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------
|
||||
| Usuario conectado
|
||||
|--------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Comprobamos los datos
|
||||
|
||||
|
||||
if (
|
||||
!isset($_POST['idPartida']) ||
|
||||
!isset($_POST['nombrePartida'])
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos para editar la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida = intval($_POST['idPartida']);
|
||||
|
||||
$partida->nombrePartida = trim($_POST['nombrePartida']);
|
||||
|
||||
|
||||
|
||||
//Buscamos la partida
|
||||
|
||||
|
||||
$datosPartida = $partida->buscar();
|
||||
|
||||
|
||||
if (!$datosPartida || isset($datosPartida['error'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'La partida indicada no existe.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Comprobamos que el usuario sea el propietario
|
||||
|
||||
|
||||
if (
|
||||
$datosPartida['idUsuario'] !=
|
||||
$_SESSION['idUsuario']
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No tienes permiso para editar esta partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida->idUsuario = $datosPartida['idUsuario'];
|
||||
|
||||
$resultado = $partida->editar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'eliminar':
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida = intval($_POST['idPartida']);
|
||||
|
||||
|
||||
|
||||
//Buscamos la partida
|
||||
|
||||
|
||||
$datosPartida = $partida->buscar();
|
||||
|
||||
|
||||
if (!$datosPartida || isset($datosPartida['error'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'La partida no existe.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Solo el propietario puede eliminarla
|
||||
|
||||
|
||||
if (
|
||||
$datosPartida['idUsuario'] !=
|
||||
$_SESSION['idUsuario']
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No tienes permiso para eliminar esta partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$resultado = $partida->eliminar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'listarDelUsuario':
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idUsuario = $_SESSION['idUsuario'];
|
||||
|
||||
$resultado = $partida->listarDelUsuario();
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'getPreguntas':
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida = intval($_POST['idPartida']);
|
||||
|
||||
$resultado = $partida->getPreguntas();
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// ASIGNAR UNA PREGUNTA A UNA PARTIDA
|
||||
|
||||
|
||||
case 'asignarPregunta':
|
||||
|
||||
if (
|
||||
!isset($_POST['idPartida']) ||
|
||||
!isset($_POST['idPregunta'])
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida = intval($_POST['idPartida']);
|
||||
|
||||
$idPregunta = intval($_POST['idPregunta']);
|
||||
|
||||
|
||||
|
||||
//Comprobamos que no esté ya asignada
|
||||
|
||||
|
||||
if ($partida->preguntaAsignada($idPregunta)) {
|
||||
|
||||
echo json_encode([
|
||||
'error' =>
|
||||
'La pregunta ya está asignada a esta partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->asignarPregunta($idPregunta);
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// COMPROBAR SI UNA PREGUNTA ESTÁ ASIGNADA
|
||||
|
||||
case 'preguntaAsignada':
|
||||
|
||||
if (
|
||||
!isset($_POST['idPartida']) ||
|
||||
!isset($_POST['idPregunta'])
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->preguntaAsignada(
|
||||
intval($_POST['idPregunta'])
|
||||
);
|
||||
|
||||
|
||||
echo json_encode([
|
||||
'asignada' => $resultado
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// CONTAR PREGUNTAS DE UNA PARTIDA
|
||||
|
||||
|
||||
case 'contarPreguntas':
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->contarPreguntasAsignadas();
|
||||
|
||||
|
||||
echo json_encode([
|
||||
'totalPreguntas' => $resultado
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// REGISTRAR EQUIPO EN UNA PARTIDA
|
||||
|
||||
|
||||
case 'registrarEquipo':
|
||||
|
||||
if (
|
||||
!isset($_POST['idPartida']) ||
|
||||
!isset($_POST['idEquipo'])
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->registrarEquipoEnPartida(
|
||||
intval($_POST['idEquipo'])
|
||||
);
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// OBTENER EQUIPOS DE UNA PARTIDA
|
||||
|
||||
|
||||
case 'getEquipos':
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->getEquiposParticipantes();
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// OBTENER JUGADORES DE UNA PARTIDA
|
||||
|
||||
|
||||
case 'getJugadores':
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->getJugadoresDeLaPartida();
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'iniciar':
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------
|
||||
| Debe haber un usuario conectado
|
||||
|--------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Comprobamos que se haya indicado la partida
|
||||
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
|
||||
//Buscamos la partida
|
||||
|
||||
|
||||
$datosPartida = $partida->buscar();
|
||||
|
||||
|
||||
if (!$datosPartida || isset($datosPartida['error'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'La partida no existe.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Solo el creador puede iniciar la partida
|
||||
|
||||
|
||||
if (
|
||||
$datosPartida['idUsuario'] !=
|
||||
$_SESSION['idUsuario']
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' =>
|
||||
'Solo el creador de la partida puede iniciarla.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Comprobamos que haya preguntas
|
||||
|
||||
|
||||
$numeroPreguntas =
|
||||
$partida->contarPreguntasAsignadas();
|
||||
|
||||
|
||||
if ($numeroPreguntas <= 0) {
|
||||
|
||||
echo json_encode([
|
||||
'error' =>
|
||||
'No puedes iniciar una partida sin preguntas.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Iniciamos la partida
|
||||
|
||||
|
||||
Este método deberá cambiar el estado de la partida
|
||||
de "esperando" a "jugando".
|
||||
|
||||
*/
|
||||
|
||||
$resultado = $partida->iniciar();
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// OBTENER LA PREGUNTA ACTUAL
|
||||
|
||||
case 'getPreguntaActual':
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
|
||||
|
||||
//Obtenemos la pregunta actual
|
||||
|
||||
$resultado =
|
||||
$partida->getPreguntaActual();
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'siguientePregunta':
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
|
||||
//Comprobamos que el usuario sea el creador
|
||||
|
||||
$datosPartida = $partida->buscar();
|
||||
|
||||
|
||||
if (!$datosPartida || isset($datosPartida['error'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'La partida no existe.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
$datosPartida['idUsuario'] !=
|
||||
$_SESSION['idUsuario']
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' =>
|
||||
'Solo el creador puede pasar a la siguiente pregunta.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Pasamos a la siguiente pregunta
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->siguientePregunta();
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// REGISTRAR RESPUESTA
|
||||
|
||||
|
||||
case 'responder':
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
!isset($_POST['idPartida']) ||
|
||||
!isset($_POST['idPregunta']) ||
|
||||
!isset($_POST['idRespuesta'])
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos para registrar la respuesta.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
$idPregunta =
|
||||
intval($_POST['idPregunta']);
|
||||
|
||||
$idRespuesta =
|
||||
intval($_POST['idRespuesta']);
|
||||
|
||||
|
||||
|
||||
//Registramos la respuesta del usuario
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->registrarRespuesta(
|
||||
$_SESSION['idUsuario'],
|
||||
$idPregunta,
|
||||
$idRespuesta
|
||||
);
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// COMPROBAR SI LA PARTIDA HA TERMINADO PARA EL USUARIO
|
||||
|
||||
|
||||
case 'estaFinalizada':
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->estaFinalizadaParaUsuario(
|
||||
$_SESSION['idUsuario']
|
||||
);
|
||||
|
||||
|
||||
echo json_encode([
|
||||
'finalizada' => $resultado
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// CONTAR RESPUESTAS DEL USUARIO
|
||||
|
||||
|
||||
case 'contarRespuestas':
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->contarRespuestasUsuario(
|
||||
$_SESSION['idUsuario']
|
||||
);
|
||||
|
||||
|
||||
echo json_encode([
|
||||
'totalRespondidas' => $resultado
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
case 'finalizar':
|
||||
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$partida = new Partida();
|
||||
|
||||
$partida->idPartida =
|
||||
intval($_POST['idPartida']);
|
||||
|
||||
|
||||
|
||||
//Buscamos la partida
|
||||
|
||||
$datosPartida = $partida->buscar();
|
||||
|
||||
|
||||
if (!$datosPartida || isset($datosPartida['error'])) {
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'La partida no existe.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Solo el creador puede finalizarla
|
||||
|
||||
if (
|
||||
$datosPartida['idUsuario'] !=
|
||||
$_SESSION['idUsuario']
|
||||
) {
|
||||
|
||||
echo json_encode([
|
||||
'error' =>
|
||||
'Solo el creador puede finalizar la partida.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$resultado =
|
||||
$partida->finalizar();
|
||||
|
||||
|
||||
echo json_encode($resultado);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'La orden indicada no existe.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once '../clases/ClasePregunta.php';
|
||||
|
||||
switch ($_POST['orden']) {
|
||||
|
||||
case 'crearPregunta':
|
||||
|
||||
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
||||
$nombrePregunta = trim($_POST['nombrePregunta'] ?? '');
|
||||
|
||||
if ($idCategoria <= 0 || $nombrePregunta == '') {
|
||||
echo json_encode(['error' => 'La categoría y el texto de la pregunta son obligatorios']);
|
||||
break;
|
||||
}
|
||||
|
||||
$pregunta = new Pregunta($idCategoria, $nombrePregunta);
|
||||
$resultado = $pregunta->guardar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'obtenerPreguntasPorCategoria':
|
||||
|
||||
$idCategoria = intval($_POST['idCategoria'] ?? 0);
|
||||
$limite = intval($_POST['limite'] ?? 10);
|
||||
|
||||
$preguntas = Pregunta::obtenerPorCategoria($idCategoria, $limite);
|
||||
|
||||
// Si ha devuelto un array de errores (formato ['error'=>...]) lo mandamos tal cual
|
||||
if (isset($preguntas['error'])) {
|
||||
echo json_encode($preguntas);
|
||||
break;
|
||||
}
|
||||
|
||||
// Convertimos cada objeto Pregunta en un array simple para poder mandarlo en JSON
|
||||
$listado = [];
|
||||
foreach ($preguntas as $p) {
|
||||
$listado[] = [
|
||||
'idPregunta' => $p->getIdPregunta(),
|
||||
'idCategoria' => $p->getIdCategoria(),
|
||||
'nombrePregunta' => $p->getNombrePregunta(),
|
||||
'respuestas' => $p->getRespuestas()
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode($listado);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once '../clases/ClaseRespuesta.php';
|
||||
|
||||
switch ($_POST['orden']) {
|
||||
|
||||
case 'crearRespuesta':
|
||||
|
||||
$idPregunta = intval($_POST['idPregunta'] ?? 0);
|
||||
$nombreRespuesta = trim($_POST['nombreRespuesta'] ?? '');
|
||||
$correcta = intval($_POST['correcta'] ?? 0);
|
||||
|
||||
if ($idPregunta <= 0 || $nombreRespuesta == '') {
|
||||
echo json_encode(['error' => 'La pregunta y el texto de la respuesta son obligatorios']);
|
||||
break;
|
||||
}
|
||||
|
||||
$respuesta = new Respuesta(null, $idPregunta, $nombreRespuesta, $correcta);
|
||||
$resultado = $respuesta->insertar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'listarRespuestas':
|
||||
|
||||
$respuesta = new Respuesta();
|
||||
$resultado = $respuesta->listar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'listarRespuestasPorPregunta':
|
||||
|
||||
$idPregunta = intval($_POST['idPregunta'] ?? 0);
|
||||
|
||||
$respuesta = new Respuesta(null, $idPregunta);
|
||||
$resultado = $respuesta->listarPorPregunta();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'editarRespuesta':
|
||||
|
||||
$idRespuesta = intval($_POST['idRespuesta'] ?? 0);
|
||||
$idPregunta = intval($_POST['idPregunta'] ?? 0);
|
||||
$nombreRespuesta = trim($_POST['nombreRespuesta'] ?? '');
|
||||
$correcta = intval($_POST['correcta'] ?? 0);
|
||||
|
||||
$respuesta = new Respuesta($idRespuesta, $idPregunta, $nombreRespuesta, $correcta);
|
||||
$resultado = $respuesta->editar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
|
||||
case 'borrarRespuesta':
|
||||
|
||||
$idRespuesta = intval($_POST['idRespuesta'] ?? 0);
|
||||
|
||||
$respuesta = new Respuesta($idRespuesta);
|
||||
$resultado = $respuesta->eliminar();
|
||||
|
||||
echo json_encode($resultado);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once '../clases/ClaseRespuestaAlmacenada.php';
|
||||
|
||||
switch ($_POST['orden']) {
|
||||
|
||||
case 'guardarRespuesta':
|
||||
|
||||
// Comprobamos que haya una sesión iniciada
|
||||
if (isset($_SESSION['idUsuario'])) {
|
||||
|
||||
$respuestaAlmacenada = new RespuestaAlmacenada();
|
||||
|
||||
// Recogemos los datos de la respuesta
|
||||
$respuestaAlmacenada->idPartidaxPregunta = $_POST['idPartidaxPregunta'];
|
||||
$respuestaAlmacenada->idUsuario = $_SESSION['idUsuario'];
|
||||
$respuestaAlmacenada->idRespuesta = $_POST['idRespuesta'];
|
||||
|
||||
// Guardamos la respuesta
|
||||
$respuesta = $respuestaAlmacenada->guardarRespuesta();
|
||||
|
||||
} else {
|
||||
|
||||
$respuesta = [
|
||||
'error' => 'No hay ninguna sesión iniciada.'
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
echo json_encode($respuesta);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 'obtenerAciertosUsuarioEnPartida':
|
||||
|
||||
// Comprobamos que haya una sesión iniciada
|
||||
if (isset($_SESSION['idUsuario'])) {
|
||||
|
||||
$idPartida = $_POST['idPartida'];
|
||||
$idUsuario = $_SESSION['idUsuario'];
|
||||
|
||||
// Obtenemos los aciertos del usuario en esa partida
|
||||
$respuesta = RespuestaAlmacenada::obtenerAciertosUsuarioEnPartida(
|
||||
$idPartida,
|
||||
$idUsuario
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
$respuesta = [
|
||||
'error' => 'No hay ninguna sesión iniciada.'
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
echo json_encode($respuesta);
|
||||
|
||||
break;
|
||||
|
||||
}//fin switch
|
||||
|
||||
?>
|
||||
@@ -27,10 +27,10 @@ SET time_zone = "+00:00";
|
||||
-- Table structure for table `respuestas`
|
||||
--
|
||||
|
||||
CREATE TABLE `respuestas` (
|
||||
CREATE TABLE `respuesta` (
|
||||
`idRespuesta` int NOT NULL,
|
||||
`idPregunta` int DEFAULT NULL,
|
||||
`respuesta` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
|
||||
`nombreRespuesta` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
|
||||
`correcta` tinyint(1) DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_spanish_ci;
|
||||
|
||||
@@ -38,7 +38,7 @@ CREATE TABLE `respuestas` (
|
||||
-- Dumping data for table `respuestas`
|
||||
--
|
||||
|
||||
INSERT INTO `respuestas` (`idRespuesta`, `idPregunta`, `respuesta`, `correcta`) VALUES
|
||||
INSERT INTO `respuesta` (`idRespuesta`, `idPregunta`, `respuesta`, `correcta`) VALUES
|
||||
(3355, 2140, '1492', 1),
|
||||
(3356, 2140, '1512', 0),
|
||||
(3357, 2140, '1453', 0),
|
||||
@@ -1627,7 +1627,7 @@ INSERT INTO `respuestas` (`idRespuesta`, `idPregunta`, `respuesta`, `correcta`)
|
||||
--
|
||||
-- Indexes for table `respuestas`
|
||||
--
|
||||
ALTER TABLE `respuestas`
|
||||
ALTER TABLE `respuesta`
|
||||
ADD PRIMARY KEY (`idRespuesta`),
|
||||
ADD KEY `idPregunta` (`idPregunta`);
|
||||
|
||||
@@ -1638,7 +1638,7 @@ ALTER TABLE `respuestas`
|
||||
--
|
||||
-- AUTO_INCREMENT for table `respuestas`
|
||||
--
|
||||
ALTER TABLE `respuestas`
|
||||
ALTER TABLE `respuesta`
|
||||
MODIFY `idRespuesta` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4935;
|
||||
|
||||
--
|
||||
@@ -1648,8 +1648,8 @@ ALTER TABLE `respuestas`
|
||||
--
|
||||
-- Constraints for table `respuestas`
|
||||
--
|
||||
ALTER TABLE `respuestas`
|
||||
ADD CONSTRAINT `respuestas_ibfk_1` FOREIGN KEY (`idPregunta`) REFERENCES `preguntas` (`idPregunta`);
|
||||
ALTER TABLE `respuesta`
|
||||
ADD CONSTRAINT `respuesta_ibfk_1` FOREIGN KEY (`idPregunta`) REFERENCES `pregunta` (`idPregunta`);
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
|
||||
Reference in New Issue
Block a user