++ gruppi: chi fa parte di un gruppo di servizio e' segnalato
Badge "Gruppo ..." / "Sorvegliante del gruppo ..." nell'elenco dei proclamatori (con il filtro "In un gruppo di servizio") e in testa alla scheda; nella scelta del proclamatore (Assegna, Registro) la nota "gruppo ..." accanto al nome, che resta sceglibile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -184,7 +184,7 @@ class MioGruppo extends Component
|
||||
'gruppo' => $gruppo,
|
||||
'territori' => $territori,
|
||||
'membri' => $membri,
|
||||
'opzioniMembri' => Proclamatore::opzioniScelta($membri),
|
||||
'opzioniMembri' => Proclamatore::opzioniScelta($membri, conGruppo: false),
|
||||
'invio' => $this->invioCorrente(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class ProclamatoreIndex extends Component
|
||||
// withCount rather than letting the view call
|
||||
// ->assegnazioni()->aperte()->count() per row, which issued one
|
||||
// COUNT(*) per displayed proclamatore on every render.
|
||||
$query = Proclamatore::query()->withCount([
|
||||
$query = Proclamatore::query()->with('gruppo')->withCount([
|
||||
'assegnazioni as assegnazioni_aperte_count' => fn ($q) => $q->whereNull('returned_at'),
|
||||
]);
|
||||
|
||||
@@ -124,6 +124,8 @@ class ProclamatoreIndex extends Component
|
||||
$filtered = $filtered->where('attivo', true);
|
||||
} elseif ($this->filtroStato === 'inattivo') {
|
||||
$filtered = $filtered->where('attivo', false);
|
||||
} elseif ($this->filtroStato === 'gruppo') {
|
||||
$filtered = $filtered->whereNotNull('gruppo_servizio_id');
|
||||
}
|
||||
|
||||
// Sort in-memory
|
||||
@@ -148,6 +150,8 @@ class ProclamatoreIndex extends Component
|
||||
$query->where('attivo', true);
|
||||
} elseif ($this->filtroStato === 'inattivo') {
|
||||
$query->where('attivo', false);
|
||||
} elseif ($this->filtroStato === 'gruppo') {
|
||||
$query->whereNotNull('gruppo_servizio_id');
|
||||
}
|
||||
|
||||
// cognome/nome encrypted, so sort in-memory
|
||||
|
||||
@@ -103,9 +103,13 @@ class Proclamatore extends Model
|
||||
*/
|
||||
public function opzioneScelta(?string $motivo = null): array
|
||||
{
|
||||
// Il gruppo di servizio come nota, solo se già caricato (opzioniScelta).
|
||||
$gruppo = $this->relationLoaded('gruppo') ? $this->gruppo_etichetta : null;
|
||||
|
||||
return array_filter([
|
||||
'valore' => (string) $this->id,
|
||||
'etichetta' => $this->nome_completo,
|
||||
'dettaglio' => $gruppo !== null ? lcfirst($gruppo) : null,
|
||||
'chiavi' => [(string) $this->cognome, (string) $this->nome],
|
||||
'motivo' => $motivo,
|
||||
], fn ($v) => $v !== null);
|
||||
@@ -113,10 +117,16 @@ class Proclamatore extends Model
|
||||
|
||||
/**
|
||||
* Le opzioni di un elenco di proclamatori, in ordine di cognome e nome.
|
||||
* L'ordine si fa qui: in SQL ordinerebbe i testi cifrati.
|
||||
* L'ordine si fa qui: in SQL ordinerebbe i testi cifrati. Con $conGruppo
|
||||
* chi fa parte di un gruppo di servizio lo dice accanto al nome (non serve
|
||||
* dove sono tutti dello stesso gruppo, come in "Il mio gruppo").
|
||||
*/
|
||||
public static function opzioniScelta(iterable $proclamatori): array
|
||||
public static function opzioniScelta(iterable $proclamatori, bool $conGruppo = true): array
|
||||
{
|
||||
if ($conGruppo && $proclamatori instanceof \Illuminate\Database\Eloquent\Collection) {
|
||||
$proclamatori->loadMissing('gruppo');
|
||||
}
|
||||
|
||||
return collect($proclamatori)
|
||||
->sortBy(fn (self $p) => mb_strtolower($p->cognome . ' ' . $p->nome))
|
||||
->map(fn (self $p) => $p->opzioneScelta($p->attivo ? null : 'non attivo'))
|
||||
@@ -124,6 +134,22 @@ class Proclamatore extends Model
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* "Sorvegliante del gruppo Zisa" o "Gruppo Zisa"; null fuori dai gruppi.
|
||||
* Senza gruppo_servizio_id non fa query.
|
||||
*/
|
||||
public function getGruppoEtichettaAttribute(): ?string
|
||||
{
|
||||
$gruppo = $this->gruppo;
|
||||
if (! $gruppo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $gruppo->sorvegliante_id === $this->id
|
||||
? "Sorvegliante del gruppo {$gruppo->nome}"
|
||||
: "Gruppo {$gruppo->nome}";
|
||||
}
|
||||
|
||||
public function assegnazioni()
|
||||
{
|
||||
return $this->hasMany(Assegnazione::class, 'proclamatore_id');
|
||||
|
||||
Reference in New Issue
Block a user