Start at 2023-08-30

This commit is contained in:
2023-08-30 15:42:47 +00:00
parent 9ce928d7ba
commit ce2e8dd2d0
7 changed files with 75 additions and 713 deletions

View File

@@ -1,15 +1,11 @@
<?
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$ruta = '../../';
require_once $_SERVER['DOCUMENT_ROOT'] . '/include/bd_pdo.php';
header('Content-Type: application/json charset=utf-8');
if (isset($_ENV['DEBUG']) and $_ENV['DEBUG']) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
if (
(!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] !== $_ENV['API_USER']) ||
(!isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_PW'] !== $_ENV['API_PASS'])
@@ -19,7 +15,6 @@ if (
exit();
}
// input
$input_raw = file_get_contents('php://input');
$input = json_decode($input_raw, true);
@@ -44,34 +39,58 @@ try {
$data = $db->query(
"WITH horarios AS (
SELECT * FROM horario_view JOIN horario_profesor USING (horario_id) WHERE :profesor_id = profesor_id
),
fechas AS (
SELECT fechas_clase(h.horario_id) as registro_fecha_ideal, h.horario_id
FROM horarios h
)
SELECT
materia,
facultad,
carrera,
registro_fecha_ideal as fecha_clase,
horarios.horario_hora as hora_clase,
horarios.dia as dia_clase,
COALESCE(
TO_CHAR(registro_fecha::TIME, 'HH24:MI:SS'),
'Sin registro'
) as hora_registro
FROM horarios
JOIN fechas using (horario_id)
LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
WHERE fechas.registro_fecha_ideal BETWEEN :fecha_inicio AND :fecha_fin
ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id",
SELECT *,
CASE
WHEN horario_dia = 1 THEN 'Lunes'
WHEN horario_dia = 2 THEN 'Martes'
WHEN horario_dia = 3 THEN 'Miércoles'
WHEN horario_dia = 4 THEN 'Jueves'
WHEN horario_dia = 5 THEN 'Viernes'
WHEN horario_dia = 6 THEN 'Sábado'
WHEN horario_dia = 7 THEN 'Domingo'
END as dia,
horario_hora + duracion_interval as horario_fin
FROM horario
JOIN horario_profesor USING (horario_id)
JOIN materia USING (materia_id)
JOIN carrera USING (carrera_id)
JOIN facultad ON facultad.facultad_id = carrera.facultad_id
JOIN periodo_carrera USING (carrera_id)
JOIN periodo_view USING (periodo_id)
JOIN duracion USING (duracion_id)
WHERE :profesor_id = profesor_id and periodo_view.activo
),
fechas AS (
SELECT fechas_clase(h.horario_id) as registro_fecha_ideal, h.horario_id
FROM horarios h
)
SELECT distinct
materia_nombre as materia,
facultad_nombre as facultad,
carrera_nombre as carrera,
registro_fecha_ideal as fecha_clase,
horarios.horario_hora as hora_clase,
horarios.horario_fin as fin_clase,
horarios.dia as dia_clase,
CASE
when registro_justificada THEN 'Justificada'
WHEN registro_retardo THEN 'Retardo'
WHEN registro_reposicion THEN 'Respuesta'
WHEN registro_fecha IS NOT NULL THEN 'Registrado'
ELSE 'Sin registro' END as registro,
TO_CHAR(registro_fecha::TIME, 'HH24:MI:SS') as hora_registro
FROM horarios
JOIN fechas using (horario_id)
LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
WHERE registro.registro_fecha_ideal BETWEEN :fecha_inicio AND :fecha_fin
ORDER BY fecha_clase DESC, materia_nombre",
[
':fecha_inicio' => $input['fecha'] ?? $input['fecha_inicio'] ?? null,
':fecha_fin' => $input['fecha'] ?? $input['fecha_fin'] ?? null,
':profesor_id' => $profesor['profesor_id'],
]
);
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} catch (PDOException $th) {
http_response_code(500);