database.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. header('Content-Type: application/json charset=utf-8');
  3. require_once "{$_SERVER['DOCUMENT_ROOT']}/class/c_abstract_data.php";
  4. final class Periodo_v1 extends WebServiceSGU
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct("/catalogos/periodos/v1/seleccionar");
  9. }
  10. }
  11. final class Periodo_v2 extends WebServiceSGU
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct("/catalogos/periodos/v2/seleccionar");
  16. }
  17. }
  18. final class Periodos extends WebServiceSGU
  19. {
  20. // use DatabaseModel;
  21. private readonly Periodo_v1 $periodo_v1;
  22. private readonly Periodo_v2 $periodo_v2;
  23. public function __construct()
  24. {
  25. parent::__construct("/catalogos/periodos/seleccionar");
  26. $this->periodo_v1 = new Periodo_v1();
  27. $this->periodo_v2 = new Periodo_v2();
  28. }
  29. public function get_v1(): array
  30. {
  31. return $this->periodo_v1->get();
  32. }
  33. public function get_v2(): array
  34. {
  35. return $this->periodo_v2->get();
  36. }
  37. public function get_merged(): array
  38. {
  39. $v2Data = $this->get_v2();
  40. // Create an associative array with IdPeriodo as the key for faster lookup
  41. $v2Lookup = array_column($v2Data, null, 'IdPeriodo');
  42. return array_map(function ($itemV1) use ($v2Lookup) {
  43. if (isset($v2Lookup[$itemV1['IdPeriodo']])) {
  44. $itemV2 = $v2Lookup[$itemV1['IdPeriodo']];
  45. $mergedItem = array_merge($itemV1, $itemV2);
  46. unset($mergedItem['NombreCarrera']); // Remove NombreCarrera as specified
  47. return $mergedItem;
  48. }
  49. return $itemV1; // If no matching IdPeriodo found in v2, return the original v1 item
  50. }, $this->get_v1());
  51. }
  52. }
  53. final class Espacios extends WebServiceSGU
  54. {
  55. public function __construct()
  56. {
  57. parent::__construct("/catalogos/espacios/seleccionar");
  58. }
  59. }
  60. final class Carreras extends WebServiceSGU
  61. {
  62. public function __construct()
  63. {
  64. parent::__construct("/catalogos/carreras/seleccionar");
  65. }
  66. }
  67. final class Horarios extends WebServiceSGU
  68. {
  69. public function __construct()
  70. {
  71. parent::__construct(
  72. "/seleccionar",
  73. <<<JSON
  74. {
  75. "\$schema": "http://json-schema.org/draft-07/schema#",
  76. "type": "object",
  77. "required": ["idPeriodo"],
  78. "properties": {
  79. "idPeriodo": {
  80. "type": "integer",
  81. "description": "Identificador del periodo a consultar."
  82. },
  83. "claveFacultad": {
  84. "type": "string",
  85. "description": "Clave de la facultad a consultar.",
  86. "pattern": "^[a-zA-Z0-9]*$"
  87. },
  88. "claveCarrera": {
  89. "type": "string",
  90. "description": "Clave de la carrera a consultar.",
  91. "pattern": "^[a-zA-Z0-9]*$"
  92. },
  93. "claveProfesor": {
  94. "type": "string",
  95. "description": "Clave del empleado a consultar.",
  96. "pattern": "^[a-zA-Z0-9]*$"
  97. },
  98. "fecha": {
  99. "type": "string",
  100. "description": "Fecha de la clase.",
  101. "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
  102. }
  103. }
  104. }
  105. JSON
  106. );
  107. }
  108. }