Files
paad/api/horario_profesor_log.php
2024-10-07 19:31:30 +00:00

34 lines
1.2 KiB
PHP

<?php
require_once "{$_SERVER['DOCUMENT_ROOT']}/class/database.php";
$rawInput = file_get_contents('php://input');
$input = json_decode($rawInput, true);
if (!$rawInput || !isset($input['profesor_id'], $input['log_id']) || $_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(400);
echo json_encode(['error' => 'Request error.']);
die();
}
$periodos = array_map(fn($array) => $array['id_periodo_sgu'], $db
->join('periodo', 'periodo.periodo_id = horario_view.periodo_id')
->join('horario_profesor', 'horario_profesor.horario_id = horario_view.horario_id')
->where('profesor_id', $input['profesor_id'])
->groupBy('id_periodo_sgu')
->orderBy('id_periodo_sgu', 'DESC')
->get('horario_view', 5, 'id_periodo_sgu'));
$clave_profesor = $db->where('profesor_id', $input['profesor_id'])->getOne('profesor', 'profesor_clave')['profesor_clave'];
$horarios = [];
$rest = new Horarios();
foreach ($periodos as $periodo) {
$horarios = array_merge($horarios, $rest->get(data: ['idPeriodo' => $periodo, 'claveProfesor' => $clave_profesor, 'fecha' => date('Y-m-d')]));
}
$db
->where('log_id', $input['log_id'])
->update("log_registro", ['horario_web' => json_encode($horarios)]);