RM metodos no usados Preguntas
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user