| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace App\Http\Livewire\Traits;
- use App\Models\User;
- use Illuminate\Support\Facades\DB;
- trait HasAccertatore{
- public $currentAccertatore = 0;
- public $currentAccertatoreNumero = 0;
- public $accertatore_nome = '';
- public $accertatore_cognome = '';
- public $accertatore_grado = 0;
- public $accertatore_username = '';
- public $accertatore_email = '';
- public $accertatore_password = '';
- public $accertatore_password_conferma = '';
- public $accertatore_1;
- public $accertatore_2;
- public $accertatore_3;
- public $accertatore_4;
- public $accertatore_5;
- public function accertatoreSave(){
- if ($this->currentAccertatore > 0) {
- User::whereId($this->currentAccertatore)->update([
- 'firstname' => $this->accertatore_nome,
- 'lastname' => $this->accertatore_cognome,
- 'username' => $this->accertatore_username,
- 'email' => $this->accertatore_email,
- 'password' => $this->accertatore_password,
- ]);
- } else {
- $accertatore = User::create([
- 'firstname' => $this->accertatore_nome,
- 'lastname' => $this->accertatore_cognome,
- 'username' => $this->accertatore_username,
- 'email' => $this->accertatore_email,
- 'password' => bcrypt($this->accertatore_password),
- ]);
- switch ($this->currentAccertatoreNumero) {
- case 1:
- $this->accertatore_1 = $accertatore->id;
- break;
- case 2:
- $this->accertatore_2 = $accertatore->id;
- break;
- case 3:
- $this->accertatore_3 = $accertatore->id;
- break;
- case 4:
- $this->accertatore_4 = $accertatore->id;
- break;
- case 5:
- $this->accertatore_5 = $accertatore->id;
- break;
- }
- }
- $this->resetAccertatore();
- $this->emit('close-modal');
- }
- public function resetAccertatore() {
- $this->currentAccertatore = 0;
- $this->currentAccertatoreNumero = 0;
- $this->accertatore_nome = '';
- $this->accertatore_cognome = '';
- $this->accertatore_grado = 0;
- $this->accertatore_username = '';
- $this->accertatore_email = '';
- $this->accertatore_password = '';
- $this->accertatore_password_conferma = '';
- }
- public function getAccertatore($accertatore){
- if ($accertatore > 0) {
- $ret = DB::table('fcf_users')->where('id', $accertatore)->first();
- return @$ret->lastname . " " . @$ret->firstname;
- }
- return "";
- }
- public function editAccertatore($utente){
- $this->resetAccertatore();
- $acc = User::where('id', $utente)->first();
- if ($acc != null) {
- $this->currentAccertatore = $utente;
- $this->accertatore_nome = $acc->firstname;
- $this->accertatore_cognome = $acc->lastname;
- $this->accertatore_username = $acc->username;
- $this->accertatore_email = $acc->email;
- $this->accertatore_password = '';
- $this->accertatore_password_conferma = '';
- }
- }
- public function addAccertatore($numero){
- $this->resetAccertatore();
- $this->currentAccertatoreNumero = $numero; // Fixed typo in original code
- }
- }
|