201 lines
9.2 KiB
PHP
201 lines
9.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Helpers;
|
|
|
|
class ReportColumnRegistry
|
|
{
|
|
private static array $columns = [];
|
|
|
|
public static function getColumns(string $entityType): array
|
|
{
|
|
if (empty(self::$columns)) {
|
|
self::boot();
|
|
}
|
|
|
|
return self::$columns[$entityType] ?? [];
|
|
}
|
|
|
|
public static function allEntityTypes(): array
|
|
{
|
|
if (empty(self::$columns)) {
|
|
self::boot();
|
|
}
|
|
|
|
return array_keys(self::$columns);
|
|
}
|
|
|
|
public static function getColumnLabel(string $entityType, string $column): ?string
|
|
{
|
|
$cols = self::getColumns($entityType);
|
|
return $cols[$column]['label'] ?? null;
|
|
}
|
|
|
|
public static function resolveRelationValue(object $item, string $column): mixed
|
|
{
|
|
$parts = explode('.', $column);
|
|
|
|
if (count($parts) === 1) {
|
|
return $item->{$column} ?? '';
|
|
}
|
|
|
|
$current = $item;
|
|
|
|
for ($i = 0; $i < count($parts); $i++) {
|
|
$part = $parts[$i];
|
|
|
|
if ($current === null || $current === '') {
|
|
return '';
|
|
}
|
|
|
|
if ($current instanceof \Illuminate\Support\Collection) {
|
|
$remaining = array_slice($parts, $i);
|
|
$filterKey = $remaining[0] ?? null;
|
|
|
|
if ($filterKey && $current->isNotEmpty() && $current->first()->getAttribute('tipo') !== null) {
|
|
return $current->where('tipo', $filterKey)
|
|
->pluck('valore')
|
|
->filter()
|
|
->implode(', ');
|
|
}
|
|
|
|
$pluckKey = implode('.', $remaining);
|
|
return $current->pluck($pluckKey)->filter()->implode(', ');
|
|
}
|
|
|
|
if ($current instanceof \Illuminate\Database\Eloquent\Model) {
|
|
try {
|
|
$relation = $current->{$part};
|
|
if ($relation instanceof \Illuminate\Support\Collection) {
|
|
$current = $relation;
|
|
} elseif ($relation instanceof \Illuminate\Database\Eloquent\Model) {
|
|
$current = $relation;
|
|
} else {
|
|
$current = $relation;
|
|
}
|
|
} catch (\Exception) {
|
|
try {
|
|
$current = $current->getAttribute($part) ?? '';
|
|
} catch (\Exception) {
|
|
return '';
|
|
}
|
|
}
|
|
} elseif (is_array($current)) {
|
|
$current = $current[$part] ?? '';
|
|
} elseif (is_object($current)) {
|
|
$current = $current->{$part} ?? '';
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
if ($current instanceof \Carbon\Carbon) {
|
|
return $current->format('d/m/Y');
|
|
}
|
|
|
|
if ($current instanceof \Illuminate\Support\Collection) {
|
|
return $current->implode(', ');
|
|
}
|
|
|
|
if (is_bool($current)) {
|
|
return $current ? 'Si' : 'No';
|
|
}
|
|
|
|
return $current ?? '';
|
|
}
|
|
|
|
private static function boot(): void
|
|
{
|
|
self::$columns = [
|
|
'individui' => [
|
|
'id' => ['label' => 'ID', 'type' => 'direct'],
|
|
'codice_id' => ['label' => 'Codice', 'type' => 'direct'],
|
|
'cognome' => ['label' => 'Cognome', 'type' => 'direct'],
|
|
'nome' => ['label' => 'Nome', 'type' => 'direct'],
|
|
'nome_completo' => ['label' => 'Nome Completo', 'type' => 'accessor'],
|
|
'data_nascita' => ['label' => 'Data Nascita', 'type' => 'direct'],
|
|
'genere' => ['label' => 'Genere', 'type' => 'direct'],
|
|
'indirizzo' => ['label' => 'Indirizzo', 'type' => 'direct'],
|
|
'cap' => ['label' => 'CAP', 'type' => 'direct'],
|
|
'città' => ['label' => 'Città', 'type' => 'direct'],
|
|
'sigla_provincia' => ['label' => 'Provincia', 'type' => 'direct'],
|
|
'tipo_documento' => ['label' => 'Tipo Documento', 'type' => 'direct'],
|
|
'numero_documento' => ['label' => 'Numero Documento', 'type' => 'direct'],
|
|
'scadenza_documento' => ['label' => 'Scadenza Documento', 'type' => 'direct'],
|
|
'note' => ['label' => 'Note', 'type' => 'direct'],
|
|
'created_at' => ['label' => 'Data Creazione', 'type' => 'direct'],
|
|
'updated_at' => ['label' => 'Ultimo Aggiornamento', 'type' => 'direct'],
|
|
'email_primaria' => ['label' => 'Email Primaria', 'type' => 'accessor'],
|
|
'telefono_primario' => ['label' => 'Telefono Primario', 'type' => 'accessor'],
|
|
'contatti.email' => ['label' => 'Email (da contatti)', 'type' => 'relation'],
|
|
'contatti.telefono' => ['label' => 'Telefono (da contatti)', 'type' => 'relation'],
|
|
'contatti.cellulare' => ['label' => 'Cellulare (da contatti)', 'type' => 'relation'],
|
|
'gruppi.nome' => ['label' => 'Gruppi', 'type' => 'relation'],
|
|
],
|
|
|
|
'gruppi' => [
|
|
'id' => ['label' => 'ID', 'type' => 'direct'],
|
|
'nome' => ['label' => 'Nome', 'type' => 'direct'],
|
|
'descrizione' => ['label' => 'Descrizione', 'type' => 'direct'],
|
|
'parent_id' => ['label' => 'ID Gruppo Padre', 'type' => 'direct'],
|
|
'diocesi_id' => ['label' => 'ID Diocesi', 'type' => 'direct'],
|
|
'indirizzo_incontro' => ['label' => 'Indirizzo Incontro', 'type' => 'direct'],
|
|
'cap_incontro' => ['label' => 'CAP Incontro', 'type' => 'direct'],
|
|
'città_incontro' => ['label' => 'Città Incontro', 'type' => 'direct'],
|
|
'sigla_provincia_incontro' => ['label' => 'Provincia Incontro', 'type' => 'direct'],
|
|
'mappa_posizione' => ['label' => 'Mappa', 'type' => 'direct'],
|
|
'created_at' => ['label' => 'Data Creazione', 'type' => 'direct'],
|
|
'updated_at' => ['label' => 'Ultimo Aggiornamento', 'type' => 'direct'],
|
|
'full_path' => ['label' => 'Percorso Completo', 'type' => 'accessor'],
|
|
'parent.nome' => ['label' => 'Gruppo Padre', 'type' => 'relation'],
|
|
'diocesi.nome' => ['label' => 'Diocesi', 'type' => 'relation'],
|
|
'individui_count' => ['label' => 'Numero Membri', 'type' => 'relation'],
|
|
],
|
|
|
|
'eventi' => [
|
|
'id' => ['label' => 'ID', 'type' => 'direct'],
|
|
'nome_evento' => ['label' => 'Nome Evento', 'type' => 'direct'],
|
|
'descrizione_evento' => ['label' => 'Descrizione', 'type' => 'direct'],
|
|
'tipo_evento' => ['label' => 'Tipo Evento', 'type' => 'direct'],
|
|
'tipo_recorrenza' => ['label' => 'Ricorrenza', 'type' => 'direct'],
|
|
'data_specifica' => ['label' => 'Data', 'type' => 'direct'],
|
|
'ora_inizio' => ['label' => 'Ora Inizio', 'type' => 'direct'],
|
|
'durata_minuti' => ['label' => 'Durata (minuti)', 'type' => 'direct'],
|
|
'luogo_indirizzo' => ['label' => 'Luogo', 'type' => 'direct'],
|
|
'luogo_url_maps' => ['label' => 'URL Mappe', 'type' => 'direct'],
|
|
'note' => ['label' => 'Note', 'type' => 'direct'],
|
|
'is_incontro_gruppo' => ['label' => 'Incontro Gruppo', 'type' => 'direct'],
|
|
'created_at' => ['label' => 'Data Creazione', 'type' => 'direct'],
|
|
'periodicita_label' => ['label' => 'Periodicità', 'type' => 'accessor'],
|
|
'info_ricorrenza' => ['label' => 'Info Ricorrenza', 'type' => 'accessor'],
|
|
'gruppi.nome' => ['label' => 'Gruppi', 'type' => 'relation'],
|
|
'responsabili.nome_completo' => ['label' => 'Responsabili', 'type' => 'relation'],
|
|
],
|
|
|
|
'documenti' => [
|
|
'id' => ['label' => 'ID', 'type' => 'direct'],
|
|
'nome_file' => ['label' => 'Nome File', 'type' => 'direct'],
|
|
'tipologia' => ['label' => 'Tipologia', 'type' => 'direct'],
|
|
'visibilita' => ['label' => 'Visibilità', 'type' => 'direct'],
|
|
'mime_type' => ['label' => 'Tipo MIME', 'type' => 'direct'],
|
|
'dimensione' => ['label' => 'Dimensione (bytes)', 'type' => 'direct'],
|
|
'note' => ['label' => 'Note', 'type' => 'direct'],
|
|
'created_at' => ['label' => 'Data Caricamento', 'type' => 'direct'],
|
|
'user.name' => ['label' => 'Caricato Da', 'type' => 'relation'],
|
|
],
|
|
|
|
'contatti' => [
|
|
'id' => ['label' => 'ID', 'type' => 'direct'],
|
|
'tipo' => ['label' => 'Tipo', 'type' => 'direct'],
|
|
'valore' => ['label' => 'Valore', 'type' => 'direct'],
|
|
'etichetta' => ['label' => 'Etichetta', 'type' => 'direct'],
|
|
'is_primary' => ['label' => 'Primario', 'type' => 'direct'],
|
|
'created_at' => ['label' => 'Data Creazione', 'type' => 'direct'],
|
|
'individuo.nome_completo' => ['label' => 'Individuo', 'type' => 'relation'],
|
|
'individuo.codice_id' => ['label' => 'Codice Individuo', 'type' => 'relation'],
|
|
],
|
|
];
|
|
}
|
|
}
|