Refrescar vista materializada concurrentemente
Some checks are pending
Deploy Pruebas / deploy (push) Waiting to run
Some checks are pending
Deploy Pruebas / deploy (push) Waiting to run
This commit is contained in:
@@ -19,95 +19,24 @@ $user = unserialize($_SESSION['user']);
|
|||||||
// check method
|
// check method
|
||||||
try {
|
try {
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||||
|
$db->query(<<<SQL
|
||||||
|
REFRESH MATERIALIZED VIEW CONCURRENTLY PUBLIC.AUDITORIA_MAT
|
||||||
|
SQL
|
||||||
|
);
|
||||||
$baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null;
|
$baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null;
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
':periodo_id' => $_GET['periodo_id'] > 0 ? $user->periodo_id : null,
|
// ':periodo_id' => $_GET['periodo_id'] > 0 ? $user->periodo_id : null,
|
||||||
':facultad_id' => $user->facultad['facultad_id'],
|
':facultad_id' => $user->facultad['facultad_id'],
|
||||||
':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d'),
|
':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d'),
|
||||||
':fecha_fin' => $baseDate ? date('Y-m-d H:i:s', strtotime($baseDate . ' +24 hours')) : date('Y-m-d H:i:s'),
|
':fecha_fin' => $baseDate ? date('Y-m-d H:i:s', strtotime($baseDate . ' +24 hours')) : date('Y-m-d H:i:s'),
|
||||||
];
|
];
|
||||||
$data = $db->query(
|
$data = $db->query(
|
||||||
"WITH horarios AS (
|
"SELECT * FROM PUBLIC.AUDITORIA_MAT
|
||||||
SELECT
|
WHERE FACULTAD_ID = COALESCE(FACULTAD_ID, :facultad_id)
|
||||||
horario_id,
|
AND REGISTRO_FECHA_IDEAL + HORARIO_HORA between :fecha_inicio AND :fecha_fin",
|
||||||
horario.facultad_id,
|
|
||||||
horario_fecha_inicio,
|
|
||||||
horario_fecha_fin,
|
|
||||||
horario_grupo,
|
|
||||||
horario_hora,
|
|
||||||
PERIODO.periodo_fecha_inicio,
|
|
||||||
PERIODO.periodo_fecha_fin,
|
|
||||||
salon,
|
|
||||||
salon_array,
|
|
||||||
COALESCE(materia_nombre, materia_asignacion_materia) as materia,
|
|
||||||
coalesce(carrera_nombre, materia_asignacion_carrera) as carrera,
|
|
||||||
facultad_nombre as facultad,
|
|
||||||
nivel_nombre as nivel,
|
|
||||||
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 on facultad.facultad_id = horario.facultad_id
|
|
||||||
JOIN PERIODO USING (periodo_id)
|
|
||||||
JOIN nivel on periodo.nivel_id = nivel.nivel_id
|
|
||||||
JOIN SALON_VIEW_MAT USING (salon_id)
|
|
||||||
WHERE (PERIODO.periodo_id, horario.facultad_id) = (COALESCE(:periodo_id, PERIODO.periodo_id), COALESCE(:facultad_id, horario.facultad_id))
|
|
||||||
),
|
|
||||||
fechas AS (
|
|
||||||
SELECT fechas_clase(h.horario_id, true) as registro_fecha_ideal, h.horario_id
|
|
||||||
FROM horarios h
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
usuario.usuario_nombre,
|
|
||||||
registro.registro_id,
|
|
||||||
registro.registro_fecha,
|
|
||||||
registro.registro_retardo,
|
|
||||||
registro.registro_justificada,
|
|
||||||
registro_fecha_supervisor,
|
|
||||||
justificacion,
|
|
||||||
comentario,
|
|
||||||
registro_fecha_justificacion,
|
|
||||||
profesor.profesor_id, profesor_nombre, profesor_clave, profesor_correo,
|
|
||||||
horario_id,
|
|
||||||
materia, carrera, horarios.facultad_id, facultad, nivel, horario_hora, horario_fin, horario_grupo, horarios_salon, horarios.salon_array,
|
|
||||||
fechas.registro_fecha_ideal,
|
|
||||||
estado_supervisor.estado_supervisor_id as estado_supervisor_id,
|
|
||||||
estado_supervisor.nombre as nombre,
|
|
||||||
estado_supervisor.estado_color as estado_color,
|
|
||||||
estado_supervisor.estado_icon as 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_fecha,
|
|
||||||
reposicion_hora,
|
|
||||||
salon_reposicion.salon as reposicion_salon,
|
|
||||||
salon_reposicion.salon_array as reposicion_salon_array,
|
|
||||||
CASE WHEN registro_retardo THEN 'warning' ELSE 'primary' 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 as 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 (fechas.registro_fecha_ideal + HORARIO_HORA) BETWEEN
|
|
||||||
GREATEST(HORARIO_FECHA_INICIO, PERIODO_FECHA_INICIO, :fecha_inicio) AND LEAST(PERIODO_FECHA_FIN, HORARIO_FECHA_FIN, :fecha_fin)
|
|
||||||
ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
|
|
||||||
$params
|
$params
|
||||||
);
|
);
|
||||||
$db->delete('general_log');
|
|
||||||
$db->insert('general_log', [
|
|
||||||
'general_log_json' => json_encode($params, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
|
||||||
]);
|
|
||||||
echo json_encode(array_merge($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
echo json_encode(array_merge($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||||
} else {
|
} else {
|
||||||
http_response_code(405);
|
http_response_code(405);
|
||||||
|
|||||||
Reference in New Issue
Block a user