56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Journalist;
|
|
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
|
|
|
class JournalistUkwChart extends ChartWidget
|
|
{
|
|
use HasWidgetShield, InteractsWithPageFilters;
|
|
|
|
protected ?string $heading = 'Status Sertifikasi UKW Jurnalis';
|
|
|
|
protected static ?int $sort = 6;
|
|
|
|
protected int|string|array $columnSpan = 1;
|
|
|
|
protected function getData(): array
|
|
{
|
|
$startDate = $this->filters['startDate'] ?? null;
|
|
$endDate = $this->filters['endDate'] ?? null;
|
|
|
|
$certified = Journalist::whereNotNull('ukw_certificate')
|
|
->where('ukw_certificate', '!=', '')
|
|
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
|
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
|
->count();
|
|
|
|
$notCertified = Journalist::where(function ($query) {
|
|
$query->whereNull('ukw_certificate')
|
|
->orWhere('ukw_certificate', '');
|
|
})
|
|
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
|
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
|
->count();
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => 'Jumlah Jurnalis',
|
|
'data' => [$certified, $notCertified],
|
|
'backgroundColor' => ['#10B981', '#EF4444'],
|
|
],
|
|
],
|
|
'labels' => ['Sudah Sertifikasi UKW', 'Belum Sertifikasi UKW'],
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'doughnut';
|
|
}
|
|
}
|