73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
|
require_once "connect.php";
|
|
|
|
class FechasModel {
|
|
|
|
static public function mdlLOV($campo) {
|
|
$sql = "select f.curso,
|
|
lower(replace(convert(varchar(9), f.fecha, 6), ' ', '-')) as fecha
|
|
from aca_fechas_curso f
|
|
where upper(f.curso) = upper(:campo)
|
|
order by f.fecha";
|
|
|
|
$stmt = Conexion::conectar()->prepare($sql);
|
|
$stmt->bindParam(":campo", $campo, PDO::PARAM_STR);
|
|
|
|
$stmt->execute();
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
static public function mdlValidarFechas($id_persona, $campoFecha, $campoLugar, $valorFecha, $valorLugar) {
|
|
$capacidad = 20;
|
|
|
|
$camposPermitidosFecha = [
|
|
'fecha_bp',
|
|
'fecha_b1_1',
|
|
'fecha_b1_2',
|
|
'fecha_b2_1',
|
|
'fecha_b2_2',
|
|
'fecha_b3_1',
|
|
'fecha_b3_2'
|
|
];
|
|
|
|
$camposPermitidosLugar = [
|
|
'lugar_bp',
|
|
'lugar_b1_1',
|
|
'lugar_b1_2',
|
|
'lugar_b2_1',
|
|
'lugar_b2_2',
|
|
'lugar_b3_1',
|
|
'lugar_b3_2'
|
|
];
|
|
|
|
if (!in_array($campoFecha, $camposPermitidosFecha, true) || !in_array($campoLugar, $camposPermitidosLugar, true)) {
|
|
return [
|
|
'ok' => false,
|
|
'mensaje' => 'Campos inválidos.'
|
|
];
|
|
}
|
|
|
|
$sql = "SELECT COUNT(*) AS cantidad
|
|
FROM aca_usuarios
|
|
WHERE $campoFecha = :fecha
|
|
AND $campoLugar = :lugar
|
|
AND id <> :id_persona";
|
|
|
|
$stmt = Conexion::conectar()->prepare($sql);
|
|
$stmt->bindValue(":id_persona", (int)$id_persona, PDO::PARAM_INT);
|
|
$stmt->bindValue(":fecha", $valorFecha, PDO::PARAM_STR);
|
|
$stmt->bindValue(":lugar", $valorLugar, PDO::PARAM_STR);
|
|
$stmt->execute();
|
|
|
|
$cantidad = (int)$stmt->fetchColumn();
|
|
$libres = max(0, $capacidad - $cantidad);
|
|
|
|
return [
|
|
'ok' => true,
|
|
'capacidad' => $capacidad,
|
|
'cantidad' => $cantidad,
|
|
'libres' => $libres
|
|
];
|
|
}
|
|
}
|