- Server di posta in Impostazioni (password cifrata, email di prova): se compilato prende il posto del .env; non si esporta e l'import XML non lo cancella. MAIL_SCHEME=tls nel .env.example non era valido per Laravel 11. - Proclamatori con email e telefono facoltativi, cifrati, nell'XML e cancellati dall'anonimizzazione; il numero apre WhatsApp. - Dopo l'assegnazione un riquadro in evidenza con il link del PDF, "Invia su WhatsApp" con il messaggio pronto e la scelta "inviato / non ancora", che resta finché non si sceglie. - Conferma dell'email obbligatoria per tutti gli utenti, anche esistenti: email in italiano, link valido senza login, nuova conferma a ogni cambio di indirizzo, "Reinvia conferma" in Utenti. Senza conferma restano raggiungibili profilo, cambio password e, per l'admin, il server di posta; comando utenti:conferma-email per l'emergenza. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
3.4 KiB
PHP
116 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
use Spatie\Activitylog\LogOptions;
|
|
|
|
class Proclamatore extends Model
|
|
{
|
|
use SoftDeletes, LogsActivity;
|
|
|
|
protected $table = 'proclamatori';
|
|
|
|
protected $fillable = ['nome', 'cognome', 'email', 'telefono', 'attivo'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'nome' => '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
|
|
}
|
|
}
|