Final
This commit is contained in:
@@ -19,59 +19,59 @@ $user = unserialize($_SESSION['user']);
|
||||
// check method
|
||||
try {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
/* $db->query(<<<SQL
|
||||
REFRESH MATERIALIZED VIEW CONCURRENTLY PUBLIC.AUDITORIA_MAT
|
||||
SQL
|
||||
); */
|
||||
// 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,
|
||||
':facultad_id' => $user->facultad['facultad_id'],
|
||||
':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'),
|
||||
|
||||
'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'));
|
||||
|
||||
$data = $db->query(
|
||||
"WITH AUDITORIA_DATA AS (
|
||||
SELECT * FROM PUBLIC.AUDITORIA_MAT
|
||||
"SELECT $relevant_columns_string FROM PUBLIC.AUDITORIA_MAT
|
||||
WHERE FACULTAD_ID = COALESCE(:facultad_id, FACULTAD_ID)
|
||||
AND REGISTRO_FECHA_IDEAL + HORARIO_HORA between :fecha_inicio AND :fecha_fin
|
||||
), DELETION AS (
|
||||
DELETE FROM last_auditoria
|
||||
WHERE usuario_id = :usuario_id
|
||||
), INSERTION AS (
|
||||
INSERT INTO last_auditoria
|
||||
SELECT :usuario_id, to_jsonb(AUDITORIA_DATA), registro_fecha_ideal, horario_id, profesor_id FROM AUDITORIA_DATA
|
||||
WHERE REGISTRO_FECHA_IDEAL IS NOT NULL
|
||||
)
|
||||
SELECT
|
||||
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
|
||||
FROM AUDITORIA_DATA ORDER BY registro_fecha_ideal, horario_hora",
|
||||
$params
|
||||
ORDER BY registro_fecha_ideal, horario_hora",
|
||||
[
|
||||
':facultad_id' => $user->facultad['facultad_id'],
|
||||
':fecha_inicio' => $_SESSION['fecha_inicio'],
|
||||
':fecha_fin' => $_SESSION['fecha_fin'],
|
||||
]
|
||||
);
|
||||
// Print the JSON file
|
||||
|
||||
echo json_encode($data);
|
||||
} else {
|
||||
http_response_code(405);
|
||||
|
||||
Reference in New Issue
Block a user