Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b8f977e437 | |||
| c8199aa261 | |||
| 7661343572 | |||
| e97586b033 | |||
| 14e2fd48a1 |
@@ -1,3 +1,4 @@
|
||||
|
||||
<?php
|
||||
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||
|
||||
@@ -466,4 +467,25 @@ class Partida
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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/ClaseEquipoxUsuario.php';
|
||||
require_once '../clases/ClaseEquipoxPartida.php';
|
||||
require_once '../clases/ClasePregunta.php';
|
||||
|
||||
|
||||
switch ($_POST['orden']) {
|
||||
@@ -119,6 +120,7 @@ switch ($_POST['orden']) {
|
||||
}
|
||||
|
||||
$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
|
||||
@@ -218,7 +256,7 @@ switch ($_POST['orden']) {
|
||||
*/
|
||||
|
||||
echo json_encode([
|
||||
'exito' => 'Sala creada correctamente.',
|
||||
'exito' => 'Sala creada correctamente. Preguntas preparadas.',
|
||||
'idPartida' => $resultadoPartida['exito_tecnico'],
|
||||
'idEquipo1' => $equipo1->idEquipo,
|
||||
'idEquipo2' => $equipo2->idEquipo
|
||||
|
||||
+23
-26
@@ -1,29 +1,26 @@
|
||||
<?php
|
||||
//CARGA DE ARCHIVOS .ENV CON PHPDOTENV
|
||||
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->load();
|
||||
|
||||
function conexionBD() {
|
||||
// Configuración para Laragon
|
||||
$servidor = "localhost";
|
||||
$bd = "triviagmatico"; // Asegúrate de que este sea el nombre de tu BD en HeidiSQL / phpMyAdmin
|
||||
$usuario = "root";
|
||||
$pass = ""; // Laragon deja la contraseña de root vacía por defecto
|
||||
$puerto = "3306";
|
||||
|
||||
try {
|
||||
$dsn = "mysql:host=$servidor;port=$puerto;dbname=$bd;charset=utf8mb4";
|
||||
|
||||
$opciones = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
|
||||
return new PDO($dsn, $usuario, $pass, $opciones);
|
||||
|
||||
} catch (PDOException $error) {
|
||||
return [
|
||||
'error' => 'No se pudo conectar a la base de datos.',
|
||||
'error_tecnico' => $error->getMessage()
|
||||
];
|
||||
function conexionBD (){
|
||||
try{
|
||||
$servidor = 'mysql:host='.$_ENV['bDatosServer'].';dbname='.$_ENV['bDatos'];
|
||||
$user=$_ENV['bDatosUser'];
|
||||
$password=$_ENV['bDatosPass'];
|
||||
$options=array(
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
|
||||
);
|
||||
//Creamos la conexión PDO a la base de datos
|
||||
$pdo = new PDO($servidor, $user, $password, $options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
catch(PDOException $e){
|
||||
//$resultado = ['error' => $e->getMessage()];
|
||||
$resultado = ['error' => 'Error Temporal: No se puede conectar con la base de datos.'];
|
||||
return $resultado;
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
+1
-11
@@ -231,8 +231,6 @@ $("#formCrearPregunta").on("submit", function (e) {
|
||||
// Volvemos a activar el botón
|
||||
boton.prop("disabled", false);
|
||||
boton.text("Crear pregunta");
|
||||
// Toast exito
|
||||
mostrarToast()
|
||||
}
|
||||
},
|
||||
|
||||
@@ -245,12 +243,4 @@ $("#formCrearPregunta").on("submit", function (e) {
|
||||
boton.text("Crear pregunta");
|
||||
},
|
||||
});
|
||||
});
|
||||
function mostrarToast() {
|
||||
const toastMensaje = document.getElementById("ToastCrearPregunta");
|
||||
|
||||
if (toastMensaje) {
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastMensaje);
|
||||
toastBootstrap.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -166,6 +166,9 @@ CREATE TABLE `partida` (
|
||||
`idPartida` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`nombrePartida` varchar(100) NOT NULL,
|
||||
`idUsuario` int(11) NOT NULL,
|
||||
`fechaCreacion` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`fechaInicio` DATETIME NULL,
|
||||
`fechaFin` DATETIME NULL,
|
||||
PRIMARY KEY (`idPartida`),
|
||||
KEY `FK idUsuario tabla usuario` (`idUsuario`),
|
||||
CONSTRAINT `FK idUsuario tabla usuario` FOREIGN KEY (`idUsuario`) REFERENCES `usuario` (`idUsuario`)
|
||||
@@ -178,10 +181,10 @@ CREATE TABLE `partida` (
|
||||
|
||||
LOCK TABLES `partida` WRITE;
|
||||
/*!40000 ALTER TABLE `partida` DISABLE KEYS */;
|
||||
INSERT INTO `partida` VALUES
|
||||
(1,'Partida de prueba 1',1),
|
||||
(2,'Partida de prueba 2',4),
|
||||
(3,'Partida de prueba 3',9);
|
||||
INSERT INTO `partida` (idPartida, nombrePartida, idUsuario, fechaInicio, fechaFin) VALUES
|
||||
(1,'Partida de prueba 1',1, NULL, NULL),
|
||||
(2,'Partida de prueba 2',4, NULL, NULL),
|
||||
(3,'Partida de prueba 3',9, NULL, NULL);
|
||||
/*!40000 ALTER TABLE `partida` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
@@ -2362,3 +2365,4 @@ UNLOCK TABLES;
|
||||
/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */;
|
||||
|
||||
-- Dump completed on 2026-09-25 10:00:41
|
||||
|
||||
|
||||
+2
-11
@@ -174,17 +174,8 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- TOAST PREGUNTA CREADA -->
|
||||
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
||||
<div id="ToastCrearPregunta" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class=" toast-header" style="background-color: #46178f;">
|
||||
<h5 class="text-white me-auto bi bi-joystick me-2"> Pregunta Creada</h5>
|
||||
</div>
|
||||
<div class="fs-6 toast-body">
|
||||
La pregunta ha sido creada correctamente
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- MODAL CREAR PREGUNTA -->
|
||||
<div class="modal fade"
|
||||
id="modalCrearPregunta"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
bDatosServer="localhost"
|
||||
bDatos="triviagmatico"
|
||||
bDatosUser="root"
|
||||
bDatosPass=""
|
||||
urlBase="http://triviagmatico.test"
|
||||
dirBase="C:/laragon/www/triviagmatico"
|
||||
Reference in New Issue
Block a user