Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit f0072ae

Browse files
committed
feat(admin): Experience Points
1 parent 25e7d80 commit f0072ae

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

src/Controller/Admin/DashboardController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function configureMenuItems(): iterable
5353
yield MenuItem::section('Statistics');
5454
yield MenuItem::linkToRoute('Last login at', 'fa fa-sign-in-alt', 'admin_statistic_last_login_at');
5555
yield MenuItem::linkToRoute('Completed Questions', 'fa fa-trophy', 'admin_statistic_completed_questions');
56+
yield MenuItem::linkToRoute('Experience Points', 'fa fa-coins', 'admin_statistic_experience_points');
5657

5758
yield MenuItem::section('User management');
5859
yield MenuItem::linkToCrud('User', 'fa fa-user', User::class);

src/Controller/Admin/StatisticController.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\SolutionEventStatus;
88
use App\Repository\QuestionRepository;
99
use App\Repository\UserRepository;
10+
use App\Service\PointCalculationService;
1011
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1112
use Symfony\Component\HttpFoundation\Response;
1213
use Symfony\Component\Routing\Attribute\Route;
@@ -92,4 +93,31 @@ public function completedQuestions(UserRepository $userRepository, QuestionRepos
9293
'userSolvedQuestionsCount' => $userSolvedQuestionsCount,
9394
]);
9495
}
96+
97+
#[Route('/admin/statistic/experience-points', name: 'admin_statistic_experience_points')]
98+
public function experiencePoint(PointCalculationService $pointCalculationService, UserRepository $userRepository): Response
99+
{
100+
$users = $userRepository->findAll();
101+
102+
/**
103+
* @var list<array{id: int, email: string, points: int}> $usersWithPoints
104+
*/
105+
$usersWithPoints = [];
106+
107+
foreach ($users as $user) {
108+
$point = $pointCalculationService->calculate($user);
109+
110+
$usersWithPoints[] = [
111+
'id' => $user->getId(),
112+
'email' => $user->getEmail(),
113+
'points' => $point,
114+
];
115+
}
116+
117+
usort($usersWithPoints, fn (array $a, array $b) => $b['points'] <=> $a['points']);
118+
119+
return $this->render('admin/statistics/experience_points.html.twig', [
120+
'usersWithPoints' => $usersWithPoints,
121+
]);
122+
}
95123
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% extends '@EasyAdmin/page/content.html.twig' %}
2+
3+
{% block content_title %}統計資料 – 上次登入時間{% endblock %}
4+
5+
{% block main %}
6+
<table class="table datagrid">
7+
<thead>
8+
<tr>
9+
<th><a href="#">帳號</a></th>
10+
<th><a href="#">經驗值</a></th>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
{% for user in usersWithPoints %}
15+
<tr>
16+
<td><a href="{{ ea_url()
17+
.setController('App\\Controller\\Admin\\UserCrudController')
18+
.setAction('detail')
19+
.setEntityId(user.id) }}">{{ user.email }}</a></td>
20+
<td>{{ user.points }}</td>
21+
</tr>
22+
{% endfor %}
23+
</tbody>
24+
</table>
25+
{% endblock %}

translations/messages.zh_TW.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ EmailTemplates: 郵件範本
7171
Last login at: 最後登入時間
7272
Statistics: 統計資料
7373
Completed Questions: 完成題數
74+
Experience Points: 經驗值
7475

7576
result_presenter.tabs.result: 執行結果
7677
result_presenter.tabs.answer: 正確答案

0 commit comments

Comments
 (0)