1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/NOT_FOUND.php"; |
4 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
5 | require_once __DIR__ . "/../lib/php/recuperaIdEntero.php"; |
6 | require_once __DIR__ . "/../lib/php/selectFirst.php"; |
7 | require_once __DIR__ . "/../lib/php/fetchAll.php"; |
8 | require_once __DIR__ . "/../lib/php/devuelveJson.php"; |
9 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
10 | require_once __DIR__ . "/Bd.php"; |
11 | require_once __DIR__ . "/TABLA_USUARIO.php"; |
12 | |
13 | ejecutaServicio(function () { |
14 | |
15 | $usuId = recuperaIdEntero("id"); |
16 | |
17 | $pdo = Bd::pdo(); |
18 | |
19 | $modelo = selectFirst(pdo: $pdo, from: USUARIO, where: [USU_ID => $usuId]); |
20 | |
21 | if ($modelo === false) { |
22 | $htmlId = htmlentities($usuId); |
23 | throw new ProblemDetails( |
24 | title: "Usuario no encontrado.", |
25 | status: NOT_FOUND, |
26 | type: "/error/usuarionoencontrado.html", |
27 | detail: "No se encontró ningún usuario con el id $htmlId.", |
28 | ); |
29 | } else { |
30 | |
31 | $rolIds = fetchAll( |
32 | $pdo->query( |
33 | "SELECT ROL_ID |
34 | FROM USU_ROL |
35 | WHERE USU_ID = :USU_ID |
36 | ORDER BY USU_ID" |
37 | ), |
38 | [":USU_ID" => $usuId], |
39 | PDO::FETCH_COLUMN |
40 | ); |
41 | |
42 | devuelveJson([ |
43 | "id" => ["value" => $usuId], |
44 | "cue" => ["value" => $modelo[USU_CUE]], |
45 | "rolIds[]" => $rolIds |
46 | ]); |
47 | } |
48 | }); |
49 | |