FunctionsController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Validator;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Hash;
  7. use Illuminate\Support\Carbon;
  8. class FunctionsController extends Controller{
  9. public function __construct(){}
  10. public static function uuidv5($namespace, $name) {
  11. if(!self::is_valid($namespace)) return false;
  12. // Get hexadecimal components of namespace
  13. $nhex = str_replace(array('-','{','}'), '', $namespace);
  14. // Binary Value
  15. $nstr = '';
  16. // Convert Namespace UUID to bits
  17. for($i = 0; $i < strlen($nhex); $i+=2) {
  18. $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1]));
  19. }
  20. // Calculate hash value
  21. $hash = sha1($nstr . $name);
  22. return sprintf('%08s-%04s-%04x-%04x-%12s',
  23. // 32 bits for "time_low"
  24. substr($hash, 0, 8),
  25. // 16 bits for "time_mid"
  26. substr($hash, 8, 4),
  27. // 16 bits for "time_hi_and_version",
  28. // four most significant bits holds version number 5
  29. (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000,
  30. // 16 bits, 8 bits for "clk_seq_hi_res",
  31. // 8 bits for "clk_seq_low",
  32. // two most significant bits holds zero and one for variant DCE1.1
  33. (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
  34. // 48 bits for "node"
  35. substr($hash, 20, 12)
  36. );
  37. }
  38. public static function is_valid($uuid) {
  39. return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'.
  40. '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1;
  41. }
  42. public function generateID(){
  43. }
  44. public function getType($type){
  45. switch($type){
  46. case "insert":
  47. return "CREATE";
  48. break;
  49. case "update":
  50. return strtoupper($type);
  51. break;
  52. case "select":
  53. return "READ";
  54. break;
  55. case "delete":
  56. return strtoupper($type);
  57. break;
  58. default:
  59. return "UNKNOWN";
  60. break;
  61. }
  62. }
  63. public function registerActivity($actions, $user, $date, $line){
  64. $cont = 1;
  65. foreach($actions as $action){
  66. $typeStr = explode(" ", $action['query'])[0];
  67. $type = $this->getType($typeStr);
  68. $params = json_encode($action['bindings']);
  69. $code = $this->uuidv5('1546058f-5a25-4334-85ae-e68f2a44bbaf', $user . $date . $cont);
  70. $cont++;
  71. $id = DB::table('S002V01TACCI')->insertGetId([
  72. 'ACCI_NULI' => $line,
  73. 'ACCI_COAC' => $code,
  74. 'ACCI_TIAC' => $type,
  75. 'ACCI_QUER' => $action['query'],
  76. 'ACCI_PARA' => $params,
  77. 'ACCI_FEAC' => $date,
  78. 'ACCI_IDUS' => $user,
  79. ]);
  80. DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $user)->update([
  81. 'USUA_ULAC' => $id
  82. ]);
  83. }
  84. }
  85. }