rutas_salón_horario.php 5.4 KB

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