103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Filament\Pages\Supporto\TicketGestione;
|
|
use App\Filament\Pages\Supporto\TicketMobile;
|
|
use App\Filament\Pages\Supporto\TicketMobileHelp;
|
|
use App\Models\Ticket;
|
|
use App\Models\User;
|
|
use App\Support\StabileContext;
|
|
use Filament\Widgets\Widget;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class TicketMobileOverview extends Widget
|
|
{
|
|
protected string $view = 'filament.widgets.ticket-mobile-overview';
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
/** @var array<string,int> */
|
|
public array $ticketCounters = [
|
|
'open' => 0,
|
|
'urgent' => 0,
|
|
'closed' => 0,
|
|
'all' => 0,
|
|
];
|
|
|
|
public static function canView(): bool
|
|
{
|
|
$user = Auth::user();
|
|
|
|
return $user instanceof User
|
|
&& $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'collaboratore']);
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$user = Auth::user();
|
|
if (! $user instanceof User) {
|
|
return;
|
|
}
|
|
|
|
$stabileIds = StabileContext::accessibleStabili($user)
|
|
->pluck('id')
|
|
->map(fn($value) => (int) $value)
|
|
->filter(fn(int $value) => $value > 0)
|
|
->values()
|
|
->all();
|
|
|
|
if ($stabileIds === []) {
|
|
return;
|
|
}
|
|
|
|
$base = Ticket::query()->whereIn('stabile_id', $stabileIds);
|
|
|
|
$this->ticketCounters = [
|
|
'open' => (clone $base)->whereIn('stato', ['Aperto', 'Preso in Carico', 'In Lavorazione'])->count(),
|
|
'urgent' => (clone $base)->where('priorita', 'Urgente')->whereIn('stato', ['Aperto', 'Preso in Carico', 'In Lavorazione'])->count(),
|
|
'closed' => (clone $base)->whereIn('stato', ['Risolto', 'Chiuso'])->count(),
|
|
'all' => (clone $base)->count(),
|
|
];
|
|
}
|
|
|
|
public function getDashboardFilamentUrl(): string
|
|
{
|
|
return route('filament.admin-filament.pages.dashboard');
|
|
}
|
|
|
|
public function getRubricaFilamentUrl(): string
|
|
{
|
|
return route('filament.admin-filament.pages.gescon.anagrafica.rubrica-universale');
|
|
}
|
|
|
|
public function getAdminMobileHubUrl(): string
|
|
{
|
|
return route('admin.mobile');
|
|
}
|
|
|
|
public function getCondominoMobileTicketUrl(): string
|
|
{
|
|
return route('condomino.tickets.mobile');
|
|
}
|
|
|
|
public function getTicketArchivioUrl(): string
|
|
{
|
|
return TicketGestione::getUrl(panel: 'admin-filament', parameters: ['status' => 'all']);
|
|
}
|
|
|
|
public function getTicketMobileUrl(): string
|
|
{
|
|
return TicketMobile::getUrl(panel: 'admin-filament');
|
|
}
|
|
|
|
public function getGestioneTicketUrl(): string
|
|
{
|
|
return TicketGestione::getUrl(panel: 'admin-filament');
|
|
}
|
|
|
|
public function getHelpUrl(): string
|
|
{
|
|
return TicketMobileHelp::getUrl(panel: 'admin-filament');
|
|
}
|
|
}
|