42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Journalist;
|
|
use App\Models\PartnerMedia;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
|
|
class JournalistMetricsStats extends BaseWidget
|
|
{
|
|
use \Filament\Widgets\Concerns\InteractsWithPageFilters;
|
|
|
|
protected static ?int $sort = 7;
|
|
|
|
protected int|string|array $columnSpan = 1;
|
|
|
|
protected function getStats(): array
|
|
{
|
|
$startDate = $this->filters['startDate'] ?? null;
|
|
$endDate = $this->filters['endDate'] ?? null;
|
|
|
|
$totalJournalists = Journalist::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
|
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
|
->count();
|
|
|
|
$totalMedia = PartnerMedia::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
|
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
|
->count();
|
|
|
|
$average = $totalMedia > 0 ? round($totalJournalists / $totalMedia, 1) : 0;
|
|
|
|
return [
|
|
Stat::make('Rata-rata Jurnalis / Media', $average)
|
|
->description('Rasio sebaran jurnalis')
|
|
->descriptionIcon(Heroicon::Users)
|
|
->color('primary'),
|
|
];
|
|
}
|
|
}
|