113 lines
4.9 KiB
PHP
113 lines
4.9 KiB
PHP
<?
|
|
#input $_GET['id_espacio_sgu']
|
|
$information = [
|
|
'GET' => [
|
|
'id_espacio_sgu',
|
|
'bloque_horario_id',
|
|
],
|
|
];
|
|
#output rutas: [ ...ruta, salones: [{...salon}] ]
|
|
header('Content-Type: application/json charset=utf-8');
|
|
$ruta = "../";
|
|
require_once "../class/c_login.php";
|
|
// check method
|
|
try {
|
|
global $db;
|
|
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
|
// check parameters
|
|
array_walk($information['GET'], function ($value) {
|
|
if (!array_key_exists($value, $_GET)) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => "$value is required"]);
|
|
exit;
|
|
}
|
|
});
|
|
// step 1: get subrutas
|
|
$data = $db
|
|
->where('tiene_salones')
|
|
->where("{$_GET['id_espacio_sgu']} = ANY(id_espacio_sgu_array)")
|
|
->get('salon_view', columns: 'id_espacio_sgu, salon, salon_id, salon_array');
|
|
|
|
// step 3: get horario
|
|
$columns = [
|
|
// horario
|
|
'horario_view.horario_id',
|
|
'horario_hora',
|
|
'horario_grupo',
|
|
'horario_fin',
|
|
'materia',
|
|
'carrera',
|
|
'nivel',
|
|
'horario_view.salon',
|
|
'facultad',
|
|
// profesor
|
|
'profesor.profesor_id',
|
|
'profesor_clave',
|
|
'profesor_nombre',
|
|
'profesor_correo',
|
|
// registro
|
|
'registro_fecha',
|
|
'registro_retardo',
|
|
'registro.reposicion_id',
|
|
'estado_supervisor_id',
|
|
'comentario',
|
|
// reposicion
|
|
'reposicion_fecha',
|
|
'reposicion_hora',
|
|
'salon_reposicion.salon as reposicion_salon',
|
|
];
|
|
$fecha = "'2023-09-01'::DATE";
|
|
$data = array_map(
|
|
fn($ruta) => array_merge(
|
|
[
|
|
'horarios' => $db
|
|
->join('periodo', 'periodo.periodo_id = horario_view.periodo_id')
|
|
->join('bloque_horario', '(bloque_horario.hora_inicio, bloque_horario.hora_fin) OVERLAPS (horario_view.horario_hora, horario_view.horario_hora + horario_view.duracion)')
|
|
->join('salon_view', 'salon_view.salon_id = horario_view.salon_id')
|
|
->join('horario_profesor', 'horario_profesor.horario_id = horario_view.horario_id')
|
|
->join('profesor', 'profesor.profesor_id = horario_profesor.profesor_id')
|
|
->join('registro', "(registro.profesor_id, registro.horario_id, registro.registro_fecha_ideal) = (profesor.profesor_id, horario_view.horario_id, $fecha)", 'LEFT')
|
|
->join('reposicion', 'reposicion.reposicion_id = registro.reposicion_id', 'LEFT')
|
|
->join('salon as salon_reposicion', 'salon_reposicion.salon_id = reposicion.salon_id', 'LEFT')
|
|
->where("$fecha BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin")
|
|
->where("horario_dia = EXTRACT(DOW FROM $fecha)")
|
|
->where('bloque_horario.id', $_GET['bloque_horario_id'])
|
|
->where('salon_view.id_espacio_padre', $ruta['id_espacio_sgu'])
|
|
->get('horario_view', columns: $columns),
|
|
'reposiciones' => $db
|
|
->join('periodo', 'periodo.periodo_id = horario_view.periodo_id')
|
|
->join('registro', 'registro.horario_id = horario_view.horario_id')
|
|
->join('reposicion', 'registro.reposicion_id = reposicion.reposicion_id')
|
|
->join('bloque_horario', '(bloque_horario.hora_inicio, bloque_horario.hora_fin) OVERLAPS (reposicion_hora, reposicion_hora + horario_view.duracion)')
|
|
->join('profesor', 'profesor.profesor_id = registro.profesor_id')
|
|
->join('salon as salon_reposicion', 'salon_reposicion.salon_id = reposicion.salon_id', 'LEFT')
|
|
->where("$fecha BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin")
|
|
->where("reposicion_fecha = $fecha")
|
|
->get('horario_view', columns: $columns),
|
|
],
|
|
$ruta,
|
|
),
|
|
$data
|
|
);
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|
} 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);
|
|
exit;
|
|
} catch (Exception $th) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'error' => $th->getMessage(),
|
|
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|
exit;
|
|
} |