197 lines
7.3 KiB
PHP
197 lines
7.3 KiB
PHP
<?
|
|
#input $_GET['id_espacio_sgu']
|
|
#output rutas: [ ...ruta, salones: [{...salon}] ]
|
|
header('Content-Type: application/json charset=utf-8');
|
|
ini_set('memory_limit', '2048M');
|
|
ini_set('post_max_size', '2048M');
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
$ruta = "..";
|
|
require_once "$ruta/class/c_login.php";
|
|
if (!isset($_SESSION['user'])) {
|
|
http_response_code(401);
|
|
die(json_encode(['error' => 'unauthorized']));
|
|
}
|
|
$user = unserialize($_SESSION['user']);
|
|
|
|
// check method
|
|
try {
|
|
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
|
// pg_send_query($db->getConnection(), "REFRESH MATERIALIZED VIEW CONCURRENTLY PUBLIC.AUDITORIA_MAT");
|
|
$baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null;
|
|
|
|
$params = [
|
|
// ':periodo_id' => $_GET['periodo_id'] > 0 ? $user->periodo_id : null,
|
|
|
|
'usuario_id' => $user->user['id'],
|
|
];
|
|
|
|
$db->where('usuario_id', $user->user['id'])->delete('last_auditoria');
|
|
|
|
// Define relevant columns
|
|
$relevant_columns = [
|
|
'registro_id',
|
|
'registro_fecha_ideal',
|
|
'horario_id',
|
|
'profesor_id',
|
|
'salon',
|
|
'profesor_clave',
|
|
'profesor_nombre',
|
|
'horario_hora',
|
|
'horario_fin',
|
|
'registro_fecha',
|
|
'color',
|
|
'estado_color',
|
|
'estado_icon',
|
|
'estado_supervisor_id',
|
|
'facultad_id',
|
|
'usuario_nombre',
|
|
'registro_fecha_supervisor',
|
|
'comentario',
|
|
'registro_justificada',
|
|
'justificacion',
|
|
'reposicion_id'
|
|
];
|
|
|
|
$relevant_columns_string = implode(', ', $relevant_columns);
|
|
|
|
$_SESSION['fecha_inicio'] = $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d');
|
|
$_SESSION['fecha_fin'] = date('Y-m-d H:i:s', strtotime(($baseDate ?? 'now') . ' +24 hours'));
|
|
|
|
$periodos = array_column($db->query('SELECT periodo_id FROM periodo WHERE (:fecha_inicio, :fecha_fin) OVERLAPS (periodo_fecha_inicio, periodo_fecha_fin)', [
|
|
'fecha_inicio' => $_SESSION['fecha_inicio'],
|
|
'fecha_fin' => $_SESSION['fecha_fin'],
|
|
]), 'periodo_id');
|
|
|
|
$daysArray = array_values(array_unique(array_map(
|
|
fn(DateTime $date) => (int) $date->format('w'),
|
|
iterator_to_array(new DatePeriod(
|
|
new DateTime($_SESSION['fecha_inicio']),
|
|
new DateInterval('P1D'),
|
|
(new DateTime($_SESSION['fecha_fin']))->modify('+1 day')
|
|
))
|
|
)));
|
|
$relevant_columns_string = implode(', ', $relevant_columns);
|
|
$days_array_string = implode(', ', $daysArray);
|
|
$periodos_string = implode(', ', $periodos);
|
|
|
|
$data = $db->query(
|
|
"WITH horarios AS (
|
|
SELECT horario.horario_id,
|
|
horario.facultad_id,
|
|
horario.horario_fecha_inicio,
|
|
horario.horario_fecha_fin,
|
|
horario.horario_grupo,
|
|
horario.horario_hora,
|
|
salon_view_mat.salon,
|
|
salon_view_mat.salon_array,
|
|
COALESCE(materia.materia_nombre, materia_asignacion.materia_asignacion_materia) AS materia,
|
|
COALESCE(carrera.carrera_nombre, materia_asignacion.materia_asignacion_carrera) AS carrera,
|
|
facultad_1.facultad_nombre AS facultad,
|
|
nivel.nivel_nombre AS nivel,
|
|
horario.horario_fin
|
|
FROM horario
|
|
LEFT JOIN materia USING (materia_id)
|
|
LEFT JOIN carrera USING (carrera_id)
|
|
LEFT JOIN materia_asignacion USING (horario_id)
|
|
JOIN facultad facultad_1 ON facultad_1.facultad_id = horario.facultad_id
|
|
JOIN nivel ON carrera.nivel_id = nivel.nivel_id
|
|
JOIN salon_view_mat USING (salon_id)
|
|
|
|
WHERE
|
|
:fecha_inicio BETWEEN HORARIO_FECHA_INICIO AND COALESCE(HORARIO_FECHA_FIN, CURRENT_DATE)
|
|
AND HORARIO_DIA IN ($days_array_string)
|
|
AND PERIODO_ID IN ($periodos_string)
|
|
AND CARRERA.FACULTAD_ID = COALESCE(:facultad_id, CARRERA.FACULTAD_ID)
|
|
|
|
), fechas AS (
|
|
SELECT fechas_clase(h.horario_id, false) AS registro_fecha_ideal,
|
|
h.horario_id
|
|
FROM horarios h
|
|
)
|
|
SELECT usuario.usuario_id,
|
|
usuario.usuario_nombre,
|
|
registro.registro_id,
|
|
registro.registro_fecha,
|
|
registro.registro_retardo,
|
|
registro.registro_justificada,
|
|
registro.registro_fecha_supervisor,
|
|
registro.justificacion,
|
|
registro.comentario,
|
|
registro.registro_fecha_justificacion,
|
|
profesor.profesor_id,
|
|
profesor.profesor_nombre,
|
|
profesor.profesor_clave,
|
|
profesor.profesor_correo,
|
|
horarios.horario_id,
|
|
horarios.materia,
|
|
horarios.carrera,
|
|
horarios.facultad_id,
|
|
horarios.facultad,
|
|
horarios.nivel,
|
|
horarios.horario_hora,
|
|
horarios.horario_fin,
|
|
horarios.horario_grupo,
|
|
horarios.salon,
|
|
horarios.salon_array,
|
|
fechas.registro_fecha_ideal,
|
|
estado_supervisor.estado_supervisor_id,
|
|
estado_supervisor.nombre,
|
|
estado_supervisor.estado_color,
|
|
estado_supervisor.estado_icon,
|
|
justificador.usuario_nombre AS justificador_nombre,
|
|
justificador.usuario_clave AS justificador_clave,
|
|
facultad.facultad_nombre AS justificador_facultad,
|
|
rol.rol_titulo AS justificador_rol,
|
|
registro.reposicion_id,
|
|
reposicion.reposicion_fecha,
|
|
reposicion.reposicion_hora,
|
|
salon_reposicion.salon AS reposicion_salon,
|
|
salon_reposicion.salon_array AS reposicion_salon_array,
|
|
CASE
|
|
WHEN registro.registro_retardo THEN 'warning'::text
|
|
ELSE 'primary'::text
|
|
END AS color
|
|
FROM horarios
|
|
JOIN fechas USING (horario_id)
|
|
JOIN horario_profesor USING (horario_id)
|
|
JOIN profesor USING (profesor_id)
|
|
LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
|
|
LEFT JOIN reposicion USING (reposicion_id)
|
|
LEFT JOIN salon_view_mat salon_reposicion ON salon_reposicion.salon_id = reposicion.salon_id
|
|
JOIN estado_supervisor ON estado_supervisor.estado_supervisor_id = COALESCE(registro.estado_supervisor_id, 0)
|
|
LEFT JOIN usuario ON usuario.usuario_id = registro.supervisor_id
|
|
LEFT JOIN usuario justificador ON justificador.usuario_id = registro.justificador_id
|
|
LEFT JOIN rol ON rol.rol_id = justificador.rol_id
|
|
LEFT JOIN facultad ON facultad.facultad_id = justificador.facultad_id
|
|
WHERE REGISTRO_FECHA_IDEAL + HORARIO_HORA between :fecha_inicio AND :fecha_fin
|
|
ORDER BY registro_fecha_ideal, horario_fin desc",
|
|
[
|
|
':facultad_id' => $user->facultad['facultad_id'],
|
|
':fecha_inicio' => $_SESSION['fecha_inicio'],
|
|
':fecha_fin' => $_SESSION['fecha_fin'],
|
|
]
|
|
);
|
|
|
|
echo json_encode($data);
|
|
} else {
|
|
http_response_code(405);
|
|
echo json_encode(['error' => 'method not allowed']);
|
|
exit;
|
|
}
|
|
} catch (PDOException $th) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'error' => $th->getMessage(),
|
|
// 'query' => $db->getLastQuery(),
|
|
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
|
|
exit;
|
|
} catch (Exception $th) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'error' => $th->getMessage(),
|
|
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|
exit;
|
|
} |