HasAccertatore.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Http\Livewire\Traits;
  3. use App\Models\User;
  4. use Illuminate\Support\Facades\DB;
  5. trait HasAccertatore{
  6. public $currentAccertatore = 0;
  7. public $currentAccertatoreNumero = 0;
  8. public $accertatore_nome = '';
  9. public $accertatore_cognome = '';
  10. public $accertatore_grado = 0;
  11. public $accertatore_username = '';
  12. public $accertatore_email = '';
  13. public $accertatore_password = '';
  14. public $accertatore_password_conferma = '';
  15. public $accertatore_1;
  16. public $accertatore_2;
  17. public $accertatore_3;
  18. public $accertatore_4;
  19. public $accertatore_5;
  20. public function accertatoreSave(){
  21. if ($this->currentAccertatore > 0) {
  22. User::whereId($this->currentAccertatore)->update([
  23. 'firstname' => $this->accertatore_nome,
  24. 'lastname' => $this->accertatore_cognome,
  25. 'username' => $this->accertatore_username,
  26. 'email' => $this->accertatore_email,
  27. 'password' => $this->accertatore_password,
  28. ]);
  29. } else {
  30. $accertatore = User::create([
  31. 'firstname' => $this->accertatore_nome,
  32. 'lastname' => $this->accertatore_cognome,
  33. 'username' => $this->accertatore_username,
  34. 'email' => $this->accertatore_email,
  35. 'password' => bcrypt($this->accertatore_password),
  36. ]);
  37. switch ($this->currentAccertatoreNumero) {
  38. case 1:
  39. $this->accertatore_1 = $accertatore->id;
  40. break;
  41. case 2:
  42. $this->accertatore_2 = $accertatore->id;
  43. break;
  44. case 3:
  45. $this->accertatore_3 = $accertatore->id;
  46. break;
  47. case 4:
  48. $this->accertatore_4 = $accertatore->id;
  49. break;
  50. case 5:
  51. $this->accertatore_5 = $accertatore->id;
  52. break;
  53. }
  54. }
  55. $this->resetAccertatore();
  56. $this->emit('close-modal');
  57. }
  58. public function resetAccertatore() {
  59. $this->currentAccertatore = 0;
  60. $this->currentAccertatoreNumero = 0;
  61. $this->accertatore_nome = '';
  62. $this->accertatore_cognome = '';
  63. $this->accertatore_grado = 0;
  64. $this->accertatore_username = '';
  65. $this->accertatore_email = '';
  66. $this->accertatore_password = '';
  67. $this->accertatore_password_conferma = '';
  68. }
  69. public function getAccertatore($accertatore){
  70. if ($accertatore > 0) {
  71. $ret = DB::table('fcf_users')->where('id', $accertatore)->first();
  72. return @$ret->lastname . " " . @$ret->firstname;
  73. }
  74. return "";
  75. }
  76. public function editAccertatore($utente){
  77. $this->resetAccertatore();
  78. $acc = User::where('id', $utente)->first();
  79. if ($acc != null) {
  80. $this->currentAccertatore = $utente;
  81. $this->accertatore_nome = $acc->firstname;
  82. $this->accertatore_cognome = $acc->lastname;
  83. $this->accertatore_username = $acc->username;
  84. $this->accertatore_email = $acc->email;
  85. $this->accertatore_password = '';
  86. $this->accertatore_password_conferma = '';
  87. }
  88. }
  89. public function addAccertatore($numero){
  90. $this->resetAccertatore();
  91. $this->currentAccertatoreNumero = $numero; // Fixed typo in original code
  92. }
  93. }