Skip to content

Commit ed5f911

Browse files
committed
merge develop into main
2 parents 4dbee6e + aabc17a commit ed5f911

File tree

70 files changed

+1130
-1257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1130
-1257
lines changed

app/Filament/Resources/ArticleResource.php

+34-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use App\Actions\Article\ApprovedArticleAction;
88
use App\Filament\Resources\ArticleResource\Pages;
99
use App\Models\Article;
10+
use Awcodes\FilamentBadgeableColumn\Components\Badge;
11+
use Awcodes\FilamentBadgeableColumn\Components\BadgeableColumn;
1012
use Filament\Resources\Resource;
1113
use Filament\Support\Enums\MaxWidth;
1214
use Filament\Tables;
@@ -67,16 +69,38 @@ public static function table(Table $table): Table
6769
->label('Soumission')
6870
->placeholder('N/A')
6971
->date(),
70-
Tables\Columns\TextColumn::make('approved_at')
71-
->label('Approbation')
72-
->placeholder('N/A')
73-
->date()
74-
->toggleable(),
75-
Tables\Columns\TextColumn::make('declined_at')
76-
->label('Décliner')
77-
->placeholder('N/A')
78-
->date()
79-
->toggleable(isToggledHiddenByDefault: true),
72+
BadgeableColumn::make('status')
73+
->label('Statut')
74+
->getStateUsing(function ($record) {
75+
if ($record->approved_at) {
76+
return $record->approved_at->format('d/m/Y');
77+
}
78+
79+
if ($record->declined_at) {
80+
return $record->declined_at->format('d/m/Y');
81+
}
82+
83+
return '';
84+
})
85+
->prefixBadges(function ($record) {
86+
if ($record->approved_at) {
87+
return [
88+
Badge::make('Approuvé')
89+
->color('success'),
90+
];
91+
}
92+
93+
if ($record->declined_at) {
94+
return [
95+
Badge::make('Décliné')
96+
->color('danger'),
97+
];
98+
}
99+
100+
return '';
101+
})
102+
->searchable()
103+
->sortable(),
80104
])
81105
->actions([
82106
ActionGroup::make([
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources\ArticleResource\Widgets;
6+
7+
use App\Models\Article;
8+
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
9+
use Filament\Widgets\StatsOverviewWidget\Stat;
10+
use Flowframe\Trend\Trend;
11+
use Flowframe\Trend\TrendValue;
12+
13+
final class ArticleStatsOverview extends BaseWidget
14+
{
15+
protected static ?string $pollingInterval = null;
16+
17+
protected ?string $heading = 'Article';
18+
19+
protected function getColumns(): int
20+
{
21+
return 2;
22+
}
23+
24+
protected function getStats(): array
25+
{
26+
$currentWeekStart = now()->startOfWeek();
27+
$currentWeekEnd = now()->endOfWeek();
28+
29+
return [
30+
Stat::make('Total Article', Article::query()->published()->count())
31+
->icon('heroicon-o-newspaper')
32+
->chart(
33+
Trend::query(Article::query()->published())
34+
->between(
35+
start: $currentWeekStart,
36+
end: $currentWeekEnd,
37+
)->perDay()
38+
->count()
39+
->map(fn (TrendValue $value) => $value->aggregate)->toArray()
40+
)->description(__('Total des articles postés')),
41+
42+
Stat::make(
43+
'Article récent publié',
44+
Article::query()
45+
->recent()
46+
->whereBetween('created_at', [
47+
$currentWeekStart,
48+
$currentWeekEnd,
49+
])->count()
50+
)
51+
->chart(
52+
Trend::query(Article::query())
53+
->between(
54+
start: $currentWeekStart,
55+
end: $currentWeekEnd,
56+
)
57+
->perDay()
58+
->count()
59+
->map(fn (TrendValue $value) => $value->aggregate)
60+
->toArray()
61+
)->icon('heroicon-o-newspaper')
62+
->color('primary')
63+
->description('Total des articles Postés de la semaine'),
64+
];
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources\ArticleResource\Widgets;
6+
7+
use App\Models\Article;
8+
use Filament\Widgets\ChartWidget;
9+
use Illuminate\Support\Str;
10+
11+
final class MostLikedPostsChart extends ChartWidget
12+
{
13+
protected static ?string $heading = 'Article le plus aimé';
14+
15+
protected static ?string $maxHeight = '200px';
16+
17+
protected int|string|array $columnSpan = 'full';
18+
19+
protected int $titleLength = 30;
20+
21+
protected function getData(): array
22+
{
23+
$articles = Article::published()
24+
->popular()
25+
->limit(10)
26+
->get();
27+
28+
return [
29+
'datasets' => [
30+
[
31+
'label' => 'Total aimé',
32+
'data' => $articles->pluck('reactions_count')->toArray(),
33+
],
34+
],
35+
'labels' => $articles->pluck('title')
36+
->map(fn ($title) => Str::limit($title, $this->titleLength, '...'))
37+
->toArray(),
38+
];
39+
}
40+
41+
protected function getType(): string
42+
{
43+
return 'bar';
44+
}
45+
46+
protected function getOptions(): array
47+
{
48+
return [
49+
'scales' => [
50+
'y' => [
51+
'beginAtZero' => true,
52+
],
53+
],
54+
];
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources\ArticleResource\Widgets;
6+
7+
use App\Models\Article;
8+
use CyrildeWit\EloquentViewable\Support\Period;
9+
use Filament\Widgets\ChartWidget;
10+
use Illuminate\Support\Str;
11+
12+
final class MostViewedPostsChart extends ChartWidget
13+
{
14+
protected static ?string $heading = 'Article le plus vu cette semaine';
15+
16+
protected static ?string $maxHeight = '200px';
17+
18+
protected int|string|array $columnSpan = 'full';
19+
20+
protected int $titleLength = 10;
21+
22+
protected function getData(): array
23+
{
24+
$articles = Article::withViewsCount(Period::create(now()->startOfWeek(), now()->endOfWeek())) // @phpstan-ignore-line
25+
->published()
26+
->orderByDesc('views_count')
27+
->orderByDesc('published_at')
28+
->limit(10)
29+
->get();
30+
31+
return [
32+
'datasets' => [
33+
[
34+
'label' => 'Article le plus vu',
35+
'data' => $articles->pluck('views_count')->toArray(),
36+
],
37+
],
38+
'labels' => $articles->pluck('title')
39+
->map(fn ($title) => Str::limit($title, $this->titleLength, '...'))
40+
->toArray(),
41+
];
42+
}
43+
44+
protected function getType(): string
45+
{
46+
return 'bar';
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources\UserResource\Widgets;
6+
7+
use App\Models\User;
8+
use Filament\Widgets\ChartWidget;
9+
use Illuminate\Database\Eloquent\Builder;
10+
11+
final class UserActivityWidget extends ChartWidget
12+
{
13+
protected static ?string $heading = 'Les utilisateurs les plus actifs cette semaine';
14+
15+
protected int|string|array $columnSpan = 'full';
16+
17+
protected static ?string $maxHeight = '200px';
18+
19+
protected function getData(): array
20+
{
21+
$users = User::with('activities')
22+
->withCount('activities')
23+
->verifiedUsers()
24+
->whereHas('activities', fn (Builder $query) => $query->whereBetween('created_at', [
25+
now()->startOfWeek(),
26+
now()->endOfWeek(),
27+
]))
28+
->orderByDesc('activities_count')
29+
->limit(10)
30+
->get();
31+
32+
return [
33+
'datasets' => [
34+
[
35+
'label' => 'Total des activités',
36+
'data' => $users->pluck('activities_count')->toArray(),
37+
],
38+
],
39+
'labels' => $users->pluck('name')->toArray(),
40+
];
41+
}
42+
43+
protected function getType(): string
44+
{
45+
return 'bar';
46+
}
47+
48+
protected function getOptions(): array
49+
{
50+
return [
51+
'scales' => [
52+
'y' => [
53+
'beginAtZero' => true,
54+
],
55+
],
56+
];
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Resources\UserResource\Widgets;
6+
7+
use App\Models\User;
8+
use Filament\Widgets\ChartWidget;
9+
use Flowframe\Trend\Trend;
10+
use Flowframe\Trend\TrendValue;
11+
12+
final class UserChartWidget extends ChartWidget
13+
{
14+
protected static ?string $heading = 'Création de compte';
15+
16+
protected int|string|array $columnSpan = 'full';
17+
18+
protected static ?string $maxHeight = '200px';
19+
20+
public ?string $filter = 'week';
21+
22+
protected function getColumns(): int
23+
{
24+
return 2;
25+
}
26+
27+
protected function getFilters(): array
28+
{
29+
return [
30+
'week' => 'Last Week',
31+
'month' => 'Last Month',
32+
'3months' => 'Last 3 Months',
33+
];
34+
}
35+
36+
protected function getData(): array
37+
{
38+
match ($this->filter) { // @phpstan-ignore-line
39+
'week' => $data = Trend::model(User::class)
40+
->between(
41+
start: now()->subWeeks(),
42+
end: now()
43+
)
44+
->perDay()
45+
->count(),
46+
47+
'month' => $data = Trend::model(User::class)
48+
->between(
49+
start: now()->subMonth(),
50+
end: now()
51+
)
52+
->perDay()
53+
->count(),
54+
55+
'3months' => $data = Trend::model(User::class)
56+
->between(
57+
start: now()->subMonths(3),
58+
end: now()
59+
)
60+
->perMonth()
61+
->count(),
62+
};
63+
64+
return [
65+
'datasets' => [
66+
[
67+
'label' => 'Compte créé',
68+
'data' => $data->map(fn (TrendValue $value) => $value->aggregate), // @phpstan-ignore-line
69+
],
70+
],
71+
'labels' => $data->map(fn (TrendValue $value) => $value->date), // @phpstan-ignore-line
72+
];
73+
}
74+
75+
protected function getType(): string
76+
{
77+
return 'line';
78+
}
79+
80+
protected function getOptions(): array
81+
{
82+
return [
83+
'scales' => [
84+
'y' => [
85+
'beginAtZero' => true,
86+
],
87+
],
88+
];
89+
}
90+
}

0 commit comments

Comments
 (0)