aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/app/src/App.php
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-03-09 11:04:51 +0900
committernsfisis <nsfisis@gmail.com>2024-03-09 14:07:27 +0900
commite014d9778f739956104caf686c70639914045281 (patch)
treeeccd80968b787e88d239644be8d21ce8ecec2c4c /services/app/src/App.php
parent8eaa76b2364b64ba32b10263f36404b472e10a28 (diff)
downloadphperkaigi-2024-albatross-e014d9778f739956104caf686c70639914045281.tar.gz
phperkaigi-2024-albatross-e014d9778f739956104caf686c70639914045281.tar.zst
phperkaigi-2024-albatross-e014d9778f739956104caf686c70639914045281.zip
add /admin/stats/
Diffstat (limited to 'services/app/src/App.php')
-rw-r--r--services/app/src/App.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/services/app/src/App.php b/services/app/src/App.php
index 77f24be..b2ffba0 100644
--- a/services/app/src/App.php
+++ b/services/app/src/App.php
@@ -142,6 +142,8 @@ final class App
});
});
});
+
+ $group->get('/stats/', $this->handleAdminStats(...))->setName('admin_stats');
})
->add(AdminRequiredMiddleware::create($app))
->add(AuthRequiredMiddleware::create($app, 'login'));
@@ -865,6 +867,33 @@ final class App
return $this->makeRedirectResponse($response, $routeParser->urlFor('admin_testcase_list', ['qslug' => $qslug]));
}
+ private function handleAdminStats(
+ ServerRequestInterface $request,
+ ResponseInterface $response,
+ QuizRepository $quizRepo,
+ AnswerRepository $answerRepo,
+ ): ResponseInterface {
+ $quizzes = $quizRepo->listAll();
+ $rankings = [];
+ $best_codes = [];
+ foreach ($quizzes as $quiz) {
+ $rankings[] = $answerRepo->getRankingByBestScores($quiz->quiz_id, upto: 3);
+ $best_codes[] = $answerRepo->getBestCode($quiz->quiz_id) ?? '<no answers>';
+ }
+
+ $n_attendees = $answerRepo->countUniqueAuthors();
+ $n_answers = $answerRepo->countAll();
+
+ return $this->render($request, $response, 'admin_stats.html.twig', [
+ 'page_title' => '管理画面 - 各種統計',
+ 'n_attendees' => $n_attendees,
+ 'n_answers' => $n_answers,
+ 'quizzes' => $quizzes,
+ 'rankings' => $rankings,
+ 'best_codes' => $best_codes,
+ ]);
+ }
+
private function handleApiAnswerStatuses(
string $aid,
ServerRequestInterface $request,