forked from hackgvl/hackgreenville-com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hackgreenville-com-433 - Add events widget to the dashboard
resolves hackgvl#433
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/Filament/Resources/EventResource/Widgets/TotalActiveEvents.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\EventResource\Widgets; | ||
|
||
use App\Models\Event; | ||
use Filament\Widgets\ChartWidget; | ||
|
||
class TotalActiveEvents extends ChartWidget | ||
{ | ||
protected static ?string $heading = 'Chart'; | ||
|
||
protected static ?string $description = 'All Events'; | ||
|
||
protected static ?string $maxHeight = '250px'; | ||
|
||
protected function getData(): array | ||
{ | ||
$data = Event::query() | ||
->published() | ||
->get() | ||
->groupBy('status') | ||
->map(fn ($events) => $events->count()) | ||
->toArray(); | ||
|
||
return [ | ||
'labels' => array_keys($data), | ||
'datasets' => [ | ||
[ | ||
'label' => 'Events', | ||
'data' => array_values($data), | ||
'backgroundColor' => [ | ||
'#FF6384', | ||
'#36A2EB', | ||
'#FFCE56', | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
protected function getType(): string | ||
{ | ||
return 'pie'; | ||
} | ||
} |