simedkom/app/Filament/Widgets/JournalistUkwChart.php

54 lines
1.6 KiB
PHP

<?php
namespace App\Filament\Widgets;
use App\Models\Journalist;
use Filament\Widgets\ChartWidget;
class JournalistUkwChart extends ChartWidget
{
use \Filament\Widgets\Concerns\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';
}
}