Update code with changes from git diff
This commit is contained in:
@@ -25,37 +25,50 @@ try {
|
||||
echo json_encode(['error' => 'No hay clases pendientes']);
|
||||
exit;
|
||||
}
|
||||
if (!(isset($post_data['fecha'], $post_data['bloques'], $post_data['justificacion']))) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Faltan parametros']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $db->querySingle(
|
||||
'INSERT INTO registro (profesor_id, horario_id, registro_fecha_ideal, registro_justificada, justificador_id, registro_fecha_justificacion, justificacion)
|
||||
VALUES (:profesor_id, :horario_id, :registro_fecha_ideal, :registro_justificada, :justificador_id, NOW(), :justificacion)
|
||||
ON CONFLICT (profesor_id, horario_id, registro_fecha_ideal)
|
||||
DO UPDATE SET registro_justificada = :registro_justificada, justificador_id = :justificador_id, registro_fecha_justificacion = NOW(), justificacion = :justificacion
|
||||
RETURNING *',
|
||||
$bloques = $db
|
||||
->where('id', $post_data['bloques'])
|
||||
->orderBy('hora_inicio')
|
||||
->get('bloque_horario', null, 'hora_inicio, hora_fin');
|
||||
|
||||
$min_hora_inicio = $bloques[0]['hora_inicio'];
|
||||
$max_hora_fin = $bloques[count($bloques) - 1]['hora_fin'];
|
||||
|
||||
$pdo->beginTransaction();
|
||||
$data = $db->query(
|
||||
"INSERT INTO registro (horario_id, registro_fecha_ideal, profesor_id, justificador_id, justificacion, registro_fecha_justificacion, registro_justificada)
|
||||
SELECT DISTINCT
|
||||
horario_id, :fecha::DATE, profesor_id, :justificador_id::INT, :justificacion, NOW(), true
|
||||
from horario_view
|
||||
join horario_profesor using (horario_id)
|
||||
where
|
||||
(:hora_inicio::TIME, :hora_fin::TIME) OVERLAPS (horario_hora, horario_fin) AND
|
||||
horario_dia = EXTRACT(DOW FROM :fecha::DATE) AND
|
||||
periodo_id = :periodo_id AND
|
||||
(horario_view.facultad_id = :facultad_id OR :facultad_id IS NULL)
|
||||
ON CONFLICT (horario_id, registro_fecha_ideal, profesor_id) DO UPDATE SET
|
||||
justificador_id = :justificador_id,
|
||||
justificacion = :justificacion,
|
||||
registro_fecha_justificacion = NOW(),
|
||||
registro_justificada = true
|
||||
RETURNING *;",
|
||||
array(
|
||||
'profesor_id' => $post_data['profesor_id'],
|
||||
'horario_id' => $post_data['horario_id'],
|
||||
'registro_fecha_ideal' => $post_data['registro_fecha_ideal'],
|
||||
'registro_justificada' => $post_data['registro_justificada'],
|
||||
'justificador_id' => $user->user['id'],
|
||||
'justificacion' => empty($post_data['justificacion']) ? null : $post_data['justificacion'],
|
||||
'fecha' => $post_data['fecha'],
|
||||
'periodo_id' => $user->periodo_id,
|
||||
'facultad_id' => $user->facultad['facultad_id'],
|
||||
'hora_inicio' => $min_hora_inicio,
|
||||
'hora_fin' => $max_hora_fin,
|
||||
)
|
||||
);
|
||||
|
||||
$data_justificador = $db->querySingle(
|
||||
"SELECT justificador.usuario_nombre as justificador_nombre,
|
||||
justificador.usuario_clave as justificador_clave,
|
||||
facultad.facultad_nombre as justificador_facultad, rol.rol_titulo as justificador_rol
|
||||
|
||||
FROM USUARIO JUSTIFICADOR
|
||||
JOIN ROL on ROL.rol_id = justificador.rol_id
|
||||
LEFT JOIN facultad on facultad.facultad_id = justificador.facultad_id
|
||||
where justificador.usuario_id = :justificador_id",
|
||||
array(
|
||||
'justificador_id' => $user->user['id'],
|
||||
)
|
||||
);
|
||||
echo json_encode(array_merge($data, $data_justificador), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
$pdo->commit();
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
http_response_code(405);
|
||||
echo json_encode(['error' => 'method not allowed']);
|
||||
@@ -70,6 +83,7 @@ try {
|
||||
'query' => $db->getLastQuery(),
|
||||
'post_data' => $post_data,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
$pdo->rollBack();
|
||||
exit;
|
||||
} catch (Exception $th) {
|
||||
http_response_code(500);
|
||||
|
||||
Reference in New Issue
Block a user