Individual JSON's

This commit is contained in:
Your Name
2025-01-20 15:44:19 -06:00
parent 05e1f7983b
commit 37f4cc42c1
2 changed files with 35 additions and 11 deletions

View File

@@ -38,11 +38,12 @@ try {
SELECT * 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 VALUES (:usuario_id , COALESCE((
SELECT jsonb_agg(AUDITORIA_DATA) FROM AUDITORIA_DATA
), '[]'::JSONB))
ON CONFLICT (usuario_id) DO UPDATE SET auditoria = EXCLUDED.auditoria
INSERT INTO last_auditoria
SELECT :usuario_id, to_jsonb(AUDITORIA_DATA) FROM AUDITORIA_DATA
)
SELECT
registro_id,

View File

@@ -16,11 +16,34 @@ $user = unserialize($_SESSION['user']);
/* $json = file_get_contents('php://input');
$data = json_decode($json, true); */
$query = $db
->where('usuario_id', $user->user['id'])
->getOne('last_auditoria', 'auditoria')['auditoria'];
$data = json_decode($query, true);
$data = $db->query(
"SELECT
auditoria->>'registro_fecha_ideal' as registro_fecha_ideal,
auditoria->>'profesor_clave' as profesor_clave,
auditoria->>'profesor_nombre' as profesor_nombre,
auditoria->>'profesor_correo' as profesor_correo,
auditoria->>'facultad' as facultad,
auditoria->>'materia' as materia,
auditoria->>'carrera' as carrera,
auditoria->>'horario_grupo' as horario_grupo,
auditoria->>'horario_hora_completa' as horario_hora_completa,
auditoria->>'salon' as salon,
auditoria->>'salon_array' as salon_array,
auditoria->>'asistencia' as asistencia,
auditoria->>'registro_fecha' as registro_fecha,
auditoria->>'usuario_nombre' as usuario_nombre,
auditoria->>'nombre' as nombre,
auditoria->>'registro_fecha_supervisor' as registro_fecha_supervisor,
auditoria->>'comentario' as comentario,
auditoria->>'justificacion' as justificacion,
auditoria->>'horario_hora' as horario_hora,
auditoria->>'horario_fin' as horario_fin,
auditoria->>'registro_retardo' as registro_retardo
FROM last_auditoria
WHERE auditoria->>'registro_fecha_ideal' IS NOT NULL
AND USUARIO_ID = ?",
[$user->user['id']]
);
empty($data) and die(json_encode(['error' => 'No se recibieron datos', 'data' => $data]));
@@ -149,7 +172,7 @@ function getFormattedValue($key, $registro)
'nombre' => $registro[$key] ?? "Sin registro",
'horario_hora_completa' => "{$registro['horario_hora']} - {$registro['horario_fin']}",
'usuario_nombre' => $registro[$key] ?? "Sin registro",
'salon_array' => json_encode($registro[$key], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
'salon_array' => json_encode($registro[$key], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
'justificacion',
'comentario' => $registro[$key] ?? "Sin registro",
default => $registro[$key]
@@ -172,7 +195,7 @@ foreach ($data as $index => $registro) {
array_walk($values, function ($row, $column_index) use ($sheet, $index, $registro) {
$value = getFormattedValue($row, $registro);
$cellLocation = chr(65 + $column_index) . (ROW + $index + 1);
$sheet->setCellValue($cellLocation, $value);
if ($value == "Sin registro") {