Add new files and make code improvements

This commit is contained in:
2024-03-06 15:14:39 +00:00
parent 113ac2aedd
commit 0a712e1864
55 changed files with 9390 additions and 973 deletions

View File

@@ -31,7 +31,7 @@ try {
$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');
->get('salon_view_mat', columns: 'id_espacio_sgu, salon, salon_id, salon_array');
$columns = [
// horario
@@ -61,47 +61,51 @@ try {
'reposicion_hora_fin',
'salon_reposicion.salon as reposicion_salon',
];
$fecha = ($_GET['fecha'] != 'null') ? ("'{$_GET['fecha']}'" ?: 'CURRENT_DATE') : 'CURRENT_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, CURRENT_DATE)', 'LEFT')
->join('reposicion', 'reposicion.reposicion_id = registro.reposicion_id', 'LEFT')
->join('salon as salon_reposicion', 'salon_reposicion.salon_id = reposicion.salon_id', 'LEFT')
->where('CURRENT_DATE BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin')
->where('horario_dia = EXTRACT(DOW FROM CURRENT_DATE)')
->where('bloque_horario.id', $_GET['bloque_horario_id'])
->where('salon_view.id_espacio_padre', $ruta['id_espacio_sgu'])
->orderBy('horario_hora')
->orderBy('salon_view.salon')
->get(
'horario_view',
columns: $columns
),
'horarios' => $db->query(
"SELECT " . implode(', ', $columns) . <<<SQL
FROM horario_view
NATURAL JOIN periodo
JOIN bloque_horario ON (bloque_horario.hora_inicio, bloque_horario.hora_fin) OVERLAPS (horario_view.horario_hora, horario_view.horario_hora + horario_view.duracion)
NATURAL JOIN salon_view_mat
NATURAL JOIN horario_profesor
NATURAL JOIN profesor
LEFT JOIN registro ON (registro.profesor_id, registro.horario_id, registro.registro_fecha_ideal) = (profesor.profesor_id, horario_view.horario_id, $fecha::DATE)
NATURAL LEFT JOIN reposicion
LEFT JOIN salon AS salon_reposicion ON salon_reposicion.salon_id = reposicion.salon_id
WHERE $fecha::DATE BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin
AND horario_dia = EXTRACT(DOW FROM $fecha::DATE)
AND bloque_horario.id = :bloque_horario_id
AND salon_view_mat.id_espacio_padre = :id_espacio_sgu
ORDER BY horario_hora, salon_view_mat.salon;
SQL,
[
'bloque_horario_id' => $_GET['bloque_horario_id'],
'id_espacio_sgu' => $ruta['id_espacio_sgu'],
]
),
// 'query' => $db->getLastQuery(),
'reposiciones' => $db->query(
'SELECT ' . implode(', ', $columns) . <<<SQL
, reposicion_hora + horario_view.duracion as reposicion_fin
, reposicion_hora + horario_view.duracion as reposicion_fin, registro_fecha_ideal
FROM horario_view
JOIN periodo USING (periodo_id)
JOIN registro USING (horario_id)
JOIN reposicion USING (reposicion_id)
NATURAL JOIN periodo
NATURAL JOIN registro
NATURAL JOIN reposicion
JOIN bloque_horario ON (bloque_horario.hora_inicio, bloque_horario.hora_fin) OVERLAPS (reposicion_hora, reposicion_hora + horario_view.duracion)
JOIN profesor USING (profesor_id)
JOIN salon_view as salon_reposicion ON (salon_reposicion.salon_id = reposicion.salon_id)
NATURAL JOIN profesor
JOIN salon_view_mat as salon_reposicion ON (salon_reposicion.salon_id = reposicion.salon_id)
WHERE
CURRENT_DATE BETWEEN periodo.periodo_fecha_inicio
$fecha::DATE BETWEEN periodo.periodo_fecha_inicio
AND periodo.periodo_fecha_fin
AND reposicion_fecha = CURRENT_DATE
AND reposicion_fecha = $fecha::DATE
AND bloque_horario.id = :bloque_horario_id
AND salon_reposicion.id_espacio_padre = :id_espacio_sgu
ORDER BY reposicion_hora
SQL,
SQL,
[
'bloque_horario_id' => $_GET['bloque_horario_id'],
'id_espacio_sgu' => $ruta['id_espacio_sgu'],