'encrypted', 'cognome' => 'encrypted', // Facoltativi. Cifrati come nome e cognome: dati personali. 'email' => 'encrypted', 'telefono' => 'encrypted', 'attivo' => 'boolean', ]; } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly(['attivo']) // Do NOT log nome/cognome/email/telefono in audit (encrypted, GDPR) ->logOnlyDirty() ->dontSubmitEmptyLogs(); } /** * Full name (decrypted, only visible in PHP/UI). */ public function getNomeCompletoAttribute(): string { return trim($this->cognome . ' ' . $this->nome); } /** * Il numero come lo vuole WhatsApp: solo cifre, con il prefisso * internazionale. Un numero senza prefisso si considera italiano: un * cellulare scritto "333 1234567" diventa 393331234567. Null se non c'è un * numero utilizzabile. */ public function telefonoInternazionale(): ?string { $grezzo = trim((string) $this->telefono); if ($grezzo === '') { return null; } $cifre = preg_replace('/\D+/', '', $grezzo); if (str_starts_with($cifre, '00') && ! str_starts_with($grezzo, '+')) { $cifre = substr($cifre, 2); } elseif (! str_starts_with($grezzo, '+') && (! str_starts_with($cifre, '39') || strlen($cifre) <= 10)) { // Senza prefisso: cellulari (3…) e fissi (0…) italiani. Un // "39…" di 11 cifre o più ha già il prefisso, scritto senza "+". $cifre = '39' . $cifre; } return strlen($cifre) >= 8 && strlen($cifre) <= 15 ? $cifre : null; } /** * Il link che apre una chat WhatsApp con il proclamatore, con un messaggio * già scritto se c'è. Null se non ha un numero utilizzabile. */ public function whatsappUrl(?string $messaggio = null): ?string { $numero = $this->telefonoInternazionale(); if ($numero === null) { return null; } return 'https://wa.me/' . $numero . ($messaggio !== null && $messaggio !== '' ? '?text=' . rawurlencode($messaggio) : ''); } public function assegnazioni() { return $this->hasMany(Assegnazione::class, 'proclamatore_id'); } public function assegnazioniAperte() { return $this->hasMany(Assegnazione::class, 'proclamatore_id') ->whereNull('returned_at'); } public function scopeAttivi($query) { return $query->where('attivo', true); } /** * Anonymize this proclamatore (GDPR right to be forgotten). */ public function anonimizza(): void { $this->nome = 'Anonimo'; $this->cognome = 'Proclamatore #' . $this->id; $this->email = null; $this->telefono = null; $this->attivo = false; $this->save(); $this->delete(); // soft delete } }