Skip to content

Commit 9d14a9a

Browse files
committed
✨ ajout des stats pour la generation de l'article hebdomadaire
1 parent a7e9f24 commit 9d14a9a

10 files changed

+229
-4
lines changed

app/Models/Article.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function scopeNotDeclined(Builder $query): Builder
396396
public function scopeRecent(Builder $query): Builder
397397
{
398398
return $query->orderByDesc('published_at')
399-
->orderByDesc('published_at');
399+
->orderByDesc('created_at');
400400
}
401401

402402
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace App\Widgets;
4+
5+
use App\Models\User;
6+
use Arrilot\Widgets\AbstractWidget;
7+
use Illuminate\Contracts\View\View;
8+
use Illuminate\Database\Eloquent\Builder;
9+
10+
class MostActiveUsersPerWeek extends AbstractWidget
11+
{
12+
/**
13+
* The configuration array.
14+
*
15+
* @var array
16+
*/
17+
protected $config = [];
18+
19+
/**
20+
* The number of seconds before each reload.
21+
*
22+
* @var int|float
23+
*/
24+
public $reloadTimeout = 60 * 60 * 24 * 2; // 2 days
25+
26+
/**
27+
* The number of minutes before cache expires.
28+
* False means no caching at all.
29+
*
30+
* @var int|float|bool
31+
*/
32+
public $cacheTime = 0;
33+
34+
/**
35+
* Treat this method as a controller action.
36+
* Return view() or other content to display.
37+
*/
38+
public function run(): View
39+
{
40+
$users = User::with('activities')
41+
->withCount('activities')
42+
->verifiedUsers()
43+
->whereHas('activities', function (Builder $query) {
44+
return $query->whereBetween('created_at', [
45+
now()->startOfWeek(),
46+
now()->endOfWeek()
47+
]);
48+
})
49+
->orderByDesc('activities_count')
50+
->limit(5)
51+
->get();
52+
53+
return view('widgets.most_active_users_per_week', [
54+
'config' => $this->config,
55+
'users' => $users,
56+
]);
57+
}
58+
}

app/Widgets/MostLikedPostsPerWeek.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Widgets;
4+
5+
use App\Models\Article;
6+
use Arrilot\Widgets\AbstractWidget;
7+
use Illuminate\Contracts\View\View;
8+
9+
class MostLikedPostsPerWeek extends AbstractWidget
10+
{
11+
/**
12+
* The configuration array.
13+
*
14+
* @var array
15+
*/
16+
protected $config = [];
17+
18+
/**
19+
* The number of seconds before each reload.
20+
*
21+
* @var int|float
22+
*/
23+
public $reloadTimeout = 60 * 60 * 24 * 2; // 2 days
24+
25+
/**
26+
* The number of minutes before cache expires.
27+
* False means no caching at all.
28+
*
29+
* @var int|float|bool
30+
*/
31+
public $cacheTime = 0;
32+
33+
/**
34+
* Treat this method as a controller action.
35+
* Return view() or other content to display.
36+
*/
37+
public function run(): View
38+
{
39+
$articles = Article::published()
40+
->popular()
41+
->limit(5)
42+
->get();
43+
44+
return view('widgets.most_liked_posts_per_week', [
45+
'config' => $this->config,
46+
'articles' => $articles,
47+
]);
48+
}
49+
}

app/Widgets/MostViewedPostsPerWeek.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,31 @@ class MostViewedPostsPerWeek extends AbstractWidget
1616
*/
1717
protected $config = [];
1818

19+
/**
20+
* The number of seconds before each reload.
21+
*
22+
* @var int|float
23+
*/
24+
public $reloadTimeout = 60 * 60 * 24 * 2; // 2 days
25+
26+
/**
27+
* The number of minutes before cache expires.
28+
* False means no caching at all.
29+
*
30+
* @var int|float|bool
31+
*/
32+
public $cacheTime = 90;
33+
1934
/**
2035
* Treat this method as a controller action.
2136
* Return view() or other content to display.
2237
*/
2338
public function run(): View
2439
{
25-
$articles = Article::withViewsCount()
40+
$articles = Article::withViewsCount(Period::create(now()->startOfWeek(), now()->endOfWeek()))
2641
->published()
42+
->orderByDesc('views_count')
2743
->orderByDesc('published_at')
28-
->orderByViews('desc', Period::create(now()->startOfWeek(), now()->endOfWeek()))
2944
->limit(5)
3045
->get();
3146

app/Widgets/RecentPostsPerWeek.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace App\Widgets;
4+
5+
use App\Models\Article;
6+
use Arrilot\Widgets\AbstractWidget;
7+
use Illuminate\Contracts\View\View;
8+
9+
class RecentPostsPerWeek extends AbstractWidget
10+
{
11+
/**
12+
* The configuration array.
13+
*
14+
* @var array
15+
*/
16+
protected $config = [];
17+
18+
/**
19+
* Treat this method as a controller action.
20+
* Return view() or other content to display.
21+
*/
22+
public function run(): View
23+
{
24+
$articles = Article::recent()
25+
->whereBetween('created_at', [now()->startOfWeek(), now()->endOfWeek()])
26+
->limit(5)
27+
->get();
28+
29+
return view('widgets.recent_posts_per_week', [
30+
'config' => $this->config,
31+
'articles' => $articles,
32+
]);
33+
}
34+
}

resources/css/base.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ input {
1212

1313
.affiliate img {
1414
margin-bottom: 0 !important;
15+
margin-top: 0 !important;
1516
border-bottom-left-radius: 0;
1617
border-bottom-right-radius: 0;
1718
}

resources/views/cpanel/analytics.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
(<span class=" font-medium text-green-500 capitalize">{{ __(':start - :end', ['start' => now()->startOfWeek()->isoFormat('DD MMMM'), 'end' => now()->endOfWeek()->isoFormat('DD MMMM')]) }}</span>)
1010
</p>
1111
</div>
12-
<div class="mt-10 grid grid-cols-3 gap-x-4 gap-y-6">
12+
<div class="mt-10 grid grid-cols-3 gap-x-8 gap-y-10">
13+
@widget('recentPostsPerWeek')
1314
@widget('mostViewedPostsPerWeek')
15+
@widget('mostLikedPostsPerWeek')
16+
@widget('mostActiveUsersPerWeek')
1417
</div>
1518
</div>
1619
<div class="py-10"></div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div class="overflow-hidden rounded-md bg-skin-card">
2+
<div class="p-4 flex items-center justify-between">
3+
<h4 class="text-lg font-medium text-skin-inverted">Utilisateurs actifs</h4>
4+
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">{{ $users->count() }}</span>
5+
</div>
6+
<div class="bg-skin-body px-4 py-3 flex items-center justify-between">
7+
<span class="text-xs leading-4 uppercase tracking-wider text-skin-inverted-muted">Utilisateur</span>
8+
<span class="text-xs leading-4 uppercase tracking-wider text-skin-inverted-muted">Profil</span>
9+
</div>
10+
<ul role="list" class="divide-y divide-skin-input">
11+
@forelse($users as $user)
12+
<li class="flex items-center justify-between px-4 py-2.5">
13+
<span class="flex-1 text-sm leading-4 truncate text-skin-base">
14+
{{ $user->name }} <span class="text-green-500 italic">({{ '@'.$user->username }})</span>
15+
</span>
16+
<a href="{{ route('profile', $user->username) }}" class="text-sm leading-5 text-skin-muted hover:text-flag-green hover:underline">Afficher</a>
17+
</li>
18+
@empty
19+
<li class="flex flex-col items-center justify-center px-4 py-5">
20+
<x-heroicon-o-trending-up class="w-10 h-10 text-skin-inverted-muted" />
21+
<span class="mt-2 text-sm leading-5 text-skin-base">Aucune activité disponible pour cette semaine.</span>
22+
</li>
23+
@endforelse
24+
</ul>
25+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="overflow-hidden rounded-md bg-skin-card">
2+
<div class="p-4">
3+
<h4 class="text-lg font-medium text-skin-inverted">Articles les plus likés</h4>
4+
</div>
5+
<div class="bg-skin-body px-4 py-3 flex items-center justify-between">
6+
<span class="text-xs leading-4 uppercase tracking-wider text-skin-inverted-muted">Article</span>
7+
<span class="text-xs leading-4 uppercase tracking-wider text-skin-inverted-muted">Likes</span>
8+
</div>
9+
<ul role="list" class="divide-y divide-skin-input">
10+
@foreach($articles as $article)
11+
<li class="flex items-center justify-between px-4 py-2.5">
12+
<a href="{{ route('articles.show', $article) }}" class="flex-1 text-sm leading-4 truncate text-skin-base hover:text-skin-inverted">{{ $article->title }}</a>
13+
<span class="text-sm leading-5 text-skin-muted">{{ $article->reactions_count }}</span>
14+
</li>
15+
@endforeach
16+
</ul>
17+
</div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div class="overflow-hidden rounded-md bg-skin-card">
2+
<div class="p-4 flex items-center justify-between">
3+
<h4 class="text-lg font-medium text-skin-inverted">Articles de la semaine</h4>
4+
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">{{ $articles->count() }}</span>
5+
</div>
6+
<div class="bg-skin-body px-4 py-3 flex items-center justify-between">
7+
<span class="text-xs leading-4 uppercase tracking-wider text-skin-inverted-muted">Article</span>
8+
<span class="text-xs leading-4 uppercase tracking-wider text-skin-inverted-muted">Auteur</span>
9+
</div>
10+
<ul role="list" class="divide-y divide-skin-input">
11+
@forelse($articles as $article)
12+
<li class="flex items-center justify-between px-4 py-2.5">
13+
<a href="{{ route('articles.show', $article) }}" class="flex-1 text-sm leading-4 truncate text-skin-base hover:text-skin-inverted">{{ $article->title }}</a>
14+
<a href="{{ route('profile', $article->author->username) }}" class="text-sm leading-5 text-skin-muted hover:text-flag-green hover:underline">{{ '@'.$article->author->username }}</a>
15+
</li>
16+
@empty
17+
<li class="flex flex-col items-center justify-center px-4 py-5">
18+
<x-heroicon-o-newspaper class="w-10 h-10 text-skin-inverted-muted" />
19+
<span class="mt-2 text-sm leading-5 text-skin-base">Aucun article n'a été publié cette semaine.</span>
20+
</li>
21+
@endforelse
22+
</ul>
23+
</div>

0 commit comments

Comments
 (0)