1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
4 | require_once __DIR__ . "/../lib/php/recuperaTexto.php"; |
5 | require_once __DIR__ . "/../lib/php/recuperaArray.php"; |
6 | require_once __DIR__ . "/../lib/php/validaCue.php"; |
7 | require_once __DIR__ . "/../lib/php/insert.php"; |
8 | require_once __DIR__ . "/../lib/php/insertBridges.php"; |
9 | require_once __DIR__ . "/../lib/php/devuelveCreated.php"; |
10 | require_once __DIR__ . "/Bd.php"; |
11 | require_once __DIR__ . "/TABLA_USUARIO.php"; |
12 | require_once __DIR__ . "/TABLA_ROL.php"; |
13 | require_once __DIR__ . "/TABLA_USU_ROL.php"; |
14 | |
15 | ejecutaServicio(function () { |
16 | |
17 | $cue = recuperaTexto("cue"); |
18 | $rolIds = recuperaArray("rolIds"); |
19 | |
20 | $cue = validaCue($cue); |
21 | |
22 | $pdo = Bd::pdo(); |
23 | $pdo->beginTransaction(); |
24 | |
25 | insert(pdo: $pdo, into: USUARIO, values: [USU_CUE => $cue]); |
26 | $usuId = $pdo->lastInsertId(); |
27 | insertBridges( |
28 | pdo: $pdo, |
29 | into: USU_ROL, |
30 | valuesDePadre: [USU_ID => $usuId], |
31 | valueDeHijos: [ROL_ID => $rolIds] |
32 | ); |
33 | |
34 | $pdo->commit(); |
35 | |
36 | $encodeUsuId = urlencode($usuId); |
37 | devuelveCreated("/srv/usuario.php?id=$encodeUsuId", [ |
38 | "id" => ["value" => $usuId], |
39 | "cue" => ["value" => $cue], |
40 | "rolIds" => ["value" => $rolIds], |
41 | ]); |
42 | }); |
43 | |