From c19c84cd11380901c3f8ea60fa0319cca8d7b7d3 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 6 Mar 2024 21:37:56 +0900 Subject: hide link to answer of other users --- services/app/src/App.php | 3 +++ services/app/templates/answer_list.html.twig | 8 +++++++- services/app/templates/quiz_view.html.twig | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/services/app/src/App.php b/services/app/src/App.php index 55f6ae3..e7d2816 100644 --- a/services/app/src/App.php +++ b/services/app/src/App.php @@ -260,12 +260,14 @@ final class App $ranking = $answerRepo->getRanking($quiz->quiz_id, upto: 20); } + $currentUser = $this->getCurrentUser($request); return $this->render($request, $response, 'quiz_view.html.twig', [ 'page_title' => "問題 #{$quiz->quiz_id}", 'quiz' => $quiz, 'ranking' => $ranking, 'is_ranking_hidden' => $quiz->isRankingHidden(), 'is_open' => $quiz->isOpenToAnswer(), + 'current_user_id' => $currentUser?->user_id, ]); } @@ -297,6 +299,7 @@ final class App 'answers' => $answers, 'is_ranking_hidden' => $quiz->isRankingHidden(), 'is_open' => $quiz->isOpenToAnswer(), + 'current_user_id' => isset($currentUser) ? $currentUser->user_id : null, ]); } diff --git a/services/app/templates/answer_list.html.twig b/services/app/templates/answer_list.html.twig index 03ab438..818a755 100644 --- a/services/app/templates/answer_list.html.twig +++ b/services/app/templates/answer_list.html.twig @@ -45,7 +45,13 @@ {{ loop.index }} {% endif %} - #{{ answer.answer_number }} + + {% if quiz.isOpenToAnswer() and answer.author_id != current_user_id %} + #{{ answer.answer_number }} + {% else %} + #{{ answer.answer_number }} + {% endif %} + {{ answer.author_name }}{% if answer.author_is_admin %} (staff){% endif %} {{ answer.code_size }} byte {{ answer.submitted_at|date('Y-m-d H:i:s', 'Asia/Tokyo') }} diff --git a/services/app/templates/quiz_view.html.twig b/services/app/templates/quiz_view.html.twig index ade324a..44676e2 100644 --- a/services/app/templates/quiz_view.html.twig +++ b/services/app/templates/quiz_view.html.twig @@ -41,7 +41,13 @@ {% for answer in ranking %} {{ loop.index }} - #{{ answer.answer_number }} + + {% if quiz.isOpenToAnswer() and answer.author_id != current_user_id %} + #{{ answer.answer_number }} + {% else %} + #{{ answer.answer_number }} + {% endif %} + {{ answer.author_name }}{% if answer.author_is_admin %} (staff){% endif %} {{ answer.code_size }} byte {{ answer.submitted_at|date('Y-m-d H:i:s', 'Asia/Tokyo') }} -- cgit v1.2.3-70-g09d2