Skip to content

Commit

Permalink
city event application statistics chart added.
Browse files Browse the repository at this point in the history
  • Loading branch information
karabayyazilim committed Jun 27, 2024
1 parent c9e6fe3 commit 76bcb92
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Filament\Resources\EventApplicationResource\Widgets;

use App\Models\City;
use App\Models\Event;
use App\Models\EventApplication;
use Filament\Widgets\ChartWidget;

class CityEventApplicationChart extends ChartWidget
{
protected static ?string $heading = 'Şehir Bazlı Başvurular';

protected array $colors = [
'#FF5733', '#33FF57', '#5733FF', '#FF33A5', '#33FFF5', '#FF8333', '#33FF83', '#FF3383', '#83FF33',
'#3383FF', '#FF3383', '#83FF33', '#3383FF', '#FF5733', '#33FF57', '#5733FF', '#FF33A5', '#33FFF5',
'#FF8333', '#33FF83', '#FF3383', '#83FF33', '#3383FF', '#FF3383', '#83FF33', '#3383FF', '#FF5733',
'#33FF57', '#5733FF', '#FF33A5', '#33FFF5', '#FF8333', '#33FF83', '#FF3383', '#83FF33', '#3383FF',
'#FF3383', '#83FF33', '#3383FF', '#FF5733', '#33FF57', '#5733FF', '#FF33A5', '#33FFF5', '#FF8333',
'#33FF83', '#FF3383', '#83FF33', '#3383FF', '#FF3383', '#83FF33', '#3383FF', '#FF5733', '#33FF57',
'#5733FF', '#FF33A5', '#33FFF5', '#FF8333', '#33FF83', '#FF3383', '#83FF33', '#3383FF', '#FF3383',
'#83FF33', '#3383FF', '#FF5733', '#33FF57', '#5733FF', '#FF33A5', '#33FFF5', '#FF8333', '#33FF83',
'#FF3383', '#83FF33', '#3383FF', '#FF3383', '#83FF33', '#3383FF', '#FF5733', '#33FF57', '#5733FF',
'#FF33A5', '#33FFF5', '#FF8333', '#33FF83', '#FF3383'
];

protected function getData(): array
{
$event = Event::query()->latest()->first();

$activeFilter = $this->filter == null ? $event->id : $this->filter;

$eventApplication = EventApplication::query()
->where('event_id', $activeFilter);

$cities = $eventApplication->with('city')
->get()
->groupBy('city_id')
->map(function ($group) {
return $group->first()->city->name;
})
->values()
->toArray();

info($cities);

return [
'labels' => $cities,
'datasets' => [
[
'label' => 'Etkinlik Başvuru Sayısı',
'data' => $eventApplication->selectRaw('city_id, COUNT(*) as count')
->groupBy('city_id')->pluck('count')->toArray(),
'backgroundColor' => $this->colors,
],
],
];
}

protected function getType(): string
{
return 'pie';
}

protected function getFilters(): ?array
{
return Event::query()->latest()->pluck('name', 'id')->toArray();
}
}
2 changes: 2 additions & 0 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers\Filament;

use App\Filament\Resources\EventApplicationResource\Widgets\CityEventApplicationChart;
use App\Filament\Resources\EventApplicationResource\Widgets\EventApplicationChart;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
Expand Down Expand Up @@ -42,6 +43,7 @@ public function panel(Panel $panel): Panel
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
EventApplicationChart::class,
CityEventApplicationChart::class,
])
->middleware([
EncryptCookies::class,
Expand Down

0 comments on commit 76bcb92

Please sign in to comment.