RM metodos no usados Preguntas

This commit is contained in:
2026-09-29 11:06:49 +02:00
parent 6adcb9680c
commit b8581a611e
2 changed files with 2 additions and 82 deletions
+2 -53
View File
@@ -57,60 +57,9 @@ class Pregunta {
}
}
public function cargarRespuestas() {
if ($this->idPregunta === null) return;
$conexion = conexionBD();
if (is_array($conexion)) {
return $conexion;
}
try {
$sql = "SELECT idRespuesta, nombreRespuesta, correcta FROM respuesta WHERE idPregunta = :idPreg";
$stmt = $conexion->prepare($sql);
$stmt->execute([':idPreg' => $this->idPregunta]);
$this->respuestas = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $error) {
return [
'error' => 'Ocurrió un error al cargar las respuestas.',
'error_tecnico' => $error->getMessage()
];
}
}
public static function obtenerPorCategoria(int $idCategoria, int $limite = 10) {
$conexion = conexionBD();
if (is_array($conexion)) {
return $conexion;
}
try {
$sql = "SELECT * FROM pregunta WHERE idCategoria = :idCat ORDER BY RAND() LIMIT :limite";
$stmt = $conexion->prepare($sql);
$stmt->bindValue(':idCat', $idCategoria, PDO::PARAM_INT);
$stmt->bindValue(':limite', $limite, PDO::PARAM_INT);
$stmt->execute();
$preguntas = [];
while ($datos = $stmt->fetch(PDO::FETCH_ASSOC)) {
$preg = new Pregunta((int)$datos['idCategoria'], $datos['nombrePregunta'], (int)$datos['idPregunta']);
$preg->cargarRespuestas();
$preguntas[] = $preg;
}
return $preguntas;
} catch (PDOException $error) {
return [
'error' => 'Ocurrió un error al obtener las preguntas aleatorias.',
'error_tecnico' => $error->getMessage()
];
}
}
public static function getTodosIds()//devuelve solamente los id de todas las preguntas
{