rutas_salón_horario.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?
  2. #input $_GET['id_espacio_sgu']
  3. $information = [
  4. 'GET' => [
  5. 'id_espacio_sgu',
  6. 'bloque_horario_id',
  7. ],
  8. ];
  9. #output rutas: [ ...ruta, salones: [{...salon}] ]
  10. header('Content-Type: application/json charset=utf-8');
  11. $ruta = "../";
  12. require_once "../class/c_login.php";
  13. // check method
  14. try {
  15. global $db;
  16. if ($_SERVER['REQUEST_METHOD'] === 'GET') {
  17. // check parameters
  18. array_walk($information['GET'], function ($value) {
  19. if (!array_key_exists($value, $_GET)) {
  20. http_response_code(400);
  21. echo json_encode(['error' => "$value is required"]);
  22. exit;
  23. }
  24. });
  25. // step 1: get subrutas
  26. $data = $db
  27. ->where('tiene_salones')
  28. ->where("{$_GET['id_espacio_sgu']} = ANY(id_espacio_sgu_array)")
  29. ->get('salon_view', columns: 'id_espacio_sgu, salon, salon_id, salon_array');
  30. // step 3: get horario
  31. $columns = [
  32. // horario
  33. 'horario_view.horario_id',
  34. 'horario_hora',
  35. 'horario_grupo',
  36. 'horario_fin',
  37. 'materia',
  38. 'carrera',
  39. 'nivel',
  40. 'horario_view.salon',
  41. 'facultad',
  42. // profesor
  43. 'profesor.profesor_id',
  44. 'profesor_clave',
  45. 'profesor_nombre',
  46. 'profesor_correo',
  47. // registro
  48. 'registro_fecha',
  49. 'registro_retardo',
  50. 'registro.reposicion_id',
  51. 'estado_supervisor_id',
  52. 'comentario',
  53. // reposicion
  54. 'reposicion_fecha',
  55. 'reposicion_hora',
  56. 'salon_reposicion.salon as reposicion_salon',
  57. ];
  58. $fecha = "'2023-09-01'::DATE";
  59. $data = array_map(
  60. fn($ruta) => array_merge(
  61. [
  62. 'horarios' => $db
  63. ->join('periodo', 'periodo.periodo_id = horario_view.periodo_id')
  64. ->join('bloque_horario', '(bloque_horario.hora_inicio, bloque_horario.hora_fin) OVERLAPS (horario_view.horario_hora, horario_view.horario_hora + horario_view.duracion)')
  65. ->join('salon_view', 'salon_view.salon_id = horario_view.salon_id')
  66. ->join('horario_profesor', 'horario_profesor.horario_id = horario_view.horario_id')
  67. ->join('profesor', 'profesor.profesor_id = horario_profesor.profesor_id')
  68. ->join('registro', "(registro.profesor_id, registro.horario_id, registro.registro_fecha_ideal) = (profesor.profesor_id, horario_view.horario_id, $fecha)", 'LEFT')
  69. ->join('reposicion', 'reposicion.reposicion_id = registro.reposicion_id', 'LEFT')
  70. ->join('salon as salon_reposicion', 'salon_reposicion.salon_id = reposicion.salon_id', 'LEFT')
  71. ->where("$fecha BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin")
  72. ->where("horario_dia = EXTRACT(DOW FROM $fecha)")
  73. ->where('bloque_horario.id', $_GET['bloque_horario_id'])
  74. ->where('salon_view.id_espacio_padre', $ruta['id_espacio_sgu'])
  75. ->get('horario_view', columns: $columns),
  76. 'reposiciones' => $db
  77. ->join('periodo', 'periodo.periodo_id = horario_view.periodo_id')
  78. ->join('registro', 'registro.horario_id = horario_view.horario_id')
  79. ->join('reposicion', 'registro.reposicion_id = reposicion.reposicion_id')
  80. ->join('bloque_horario', '(bloque_horario.hora_inicio, bloque_horario.hora_fin) OVERLAPS (reposicion_hora, reposicion_hora + horario_view.duracion)')
  81. ->join('profesor', 'profesor.profesor_id = registro.profesor_id')
  82. ->join('salon as salon_reposicion', 'salon_reposicion.salon_id = reposicion.salon_id', 'LEFT')
  83. ->where("$fecha BETWEEN periodo.periodo_fecha_inicio AND periodo.periodo_fecha_fin")
  84. ->where("reposicion_fecha = $fecha")
  85. ->get('horario_view', columns: $columns),
  86. ],
  87. $ruta,
  88. ),
  89. $data
  90. );
  91. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  92. } else {
  93. http_response_code(405);
  94. echo json_encode(['error' => 'method not allowed']);
  95. exit;
  96. }
  97. } catch (PDOException $th) {
  98. http_response_code(500);
  99. echo json_encode([
  100. 'error' => $th->getMessage(),
  101. 'query' => $db->getLastQuery(),
  102. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  103. exit;
  104. } catch (Exception $th) {
  105. http_response_code(500);
  106. echo json_encode([
  107. 'error' => $th->getMessage(),
  108. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  109. exit;
  110. }