1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
4 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
5 | require_once __DIR__ . "/../lib/php/pdFaltaId.php"; |
6 | require_once __DIR__ . "/../lib/php/leeEntero.php"; |
7 | require_once __DIR__ . "/bd/usuarioBusca.php"; |
8 | |
9 | ejecutaServicio(function () { |
10 | $id = leeEntero("id"); |
11 | if ($id === null) throw pdFaltaId(); |
12 | $modelo = usuarioBusca($id); |
13 | if ($modelo === false) { |
14 | $htmlId = htmlentities($id); |
15 | throw new ProblemDetails( |
16 | status: ProblemDetails::NotFound, |
17 | type: "/error/usuarionoencontrado.html", |
18 | title: "Usuario no encontrado.", |
19 | detail: "No se encontró ningún usuario con el id $htmlId.", |
20 | ); |
21 | } |
22 | $rolIds = []; |
23 | foreach ($modelo->roles as $rol) { |
24 | $rolIds[] = $rol->id; |
25 | } |
26 | return [ |
27 | "id" => ["value" => $modelo->id], |
28 | "cue" => ["value" => $modelo->cue], |
29 | "rolIds[]" => $rolIds |
30 | ]; |
31 | }); |
32 | |