Show feedback in the admin panel and as aggregate stats on the briefing page
Feedback was only ever written to session_setting rows with no way to view it short of querying the database directly. Adds a FeedbackService that pulls per-player feedback entries and aggregate averages, backing two new views: - /admin/feedback: a full table of every submission (game, session, player, ratings, comment) plus summary tiles, linked from the admin sidebar. - /briefing: a "Field Reports" block with the average difficulty/ entertainment/theme ratings, shown to prospective players. Free-text comments are deliberately left off this public page since they're unmoderated player input. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Game\Controller;
|
||||||
|
|
||||||
|
use App\Game\Service\FeedbackService;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
#[Route('/admin/feedback')]
|
||||||
|
#[IsGranted('ROLE_ADMIN')]
|
||||||
|
final class GameAdminFeedbackController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('', name: 'game_admin_feedback', methods: ['GET'])]
|
||||||
|
public function index(FeedbackService $feedbackService): Response
|
||||||
|
{
|
||||||
|
return $this->render('game/admin/feedback/index.html.twig', [
|
||||||
|
'entries' => $feedbackService->getFeedbackEntries(),
|
||||||
|
'summary' => $feedbackService->getFeedbackSummary(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,4 +36,22 @@ class SessionSettingRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
return $qb->getQuery()->getOneOrNullResult();
|
return $qb->getQuery()->getOneOrNullResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return SessionSetting[]
|
||||||
|
*/
|
||||||
|
public function findFeedbackSettings(): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('s')
|
||||||
|
->andWhere('s.name IN (:names)')
|
||||||
|
->setParameter('names', [
|
||||||
|
SessionSettingType::FEEDBACK_DIFFICULTY->value,
|
||||||
|
SessionSettingType::FEEDBACK_ENTERTAINING->value,
|
||||||
|
SessionSettingType::FEEDBACK_THEME->value,
|
||||||
|
SessionSettingType::FEEDBACK_TEXT->value,
|
||||||
|
])
|
||||||
|
->orderBy('s.player', 'DESC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Game\Service;
|
||||||
|
|
||||||
|
use App\Game\Enum\SessionSettingType;
|
||||||
|
use App\Game\Repository\SessionSettingRepository;
|
||||||
|
|
||||||
|
final class FeedbackService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly SessionSettingRepository $sessionSettingRepository,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One row per player who submitted feedback, most recent first.
|
||||||
|
*
|
||||||
|
* @return array<int, array{session: \App\Game\Entity\Session, player: \App\Game\Entity\Player, difficulty: ?int, entertaining: ?int, theme: ?int, text: ?string}>
|
||||||
|
*/
|
||||||
|
public function getFeedbackEntries(): array
|
||||||
|
{
|
||||||
|
$entries = [];
|
||||||
|
|
||||||
|
foreach ($this->sessionSettingRepository->findFeedbackSettings() as $setting) {
|
||||||
|
$player = $setting->getPlayer();
|
||||||
|
if (!$player) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = $player->getId();
|
||||||
|
if (!isset($entries[$key])) {
|
||||||
|
$entries[$key] = [
|
||||||
|
'session' => $setting->getSession(),
|
||||||
|
'player' => $player,
|
||||||
|
'difficulty' => null,
|
||||||
|
'entertaining' => null,
|
||||||
|
'theme' => null,
|
||||||
|
'text' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
match ($setting->getName()) {
|
||||||
|
SessionSettingType::FEEDBACK_DIFFICULTY => $entries[$key]['difficulty'] = (int) $setting->getValue(),
|
||||||
|
SessionSettingType::FEEDBACK_ENTERTAINING => $entries[$key]['entertaining'] = (int) $setting->getValue(),
|
||||||
|
SessionSettingType::FEEDBACK_THEME => $entries[$key]['theme'] = (int) $setting->getValue(),
|
||||||
|
SessionSettingType::FEEDBACK_TEXT => $entries[$key]['text'] = $setting->getValue(),
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values($entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aggregate numbers only - free-text comments are left out since they're
|
||||||
|
* unmoderated player input and this summary is meant for the public
|
||||||
|
* briefing page. Use getFeedbackEntries() for the admin-only raw view.
|
||||||
|
*
|
||||||
|
* @return array{count: int, avgDifficulty: ?float, avgEntertaining: ?float, avgTheme: ?float}
|
||||||
|
*/
|
||||||
|
public function getFeedbackSummary(): array
|
||||||
|
{
|
||||||
|
$entries = $this->getFeedbackEntries();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'count' => count($entries),
|
||||||
|
'avgDifficulty' => $this->average(array_column($entries, 'difficulty')),
|
||||||
|
'avgEntertaining' => $this->average(array_column($entries, 'entertaining')),
|
||||||
|
'avgTheme' => $this->average(array_column($entries, 'theme')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, int|null> $values
|
||||||
|
*/
|
||||||
|
private function average(array $values): ?float
|
||||||
|
{
|
||||||
|
$values = array_filter($values, static fn ($v) => $v !== null);
|
||||||
|
|
||||||
|
return $values ? round(array_sum($values) / count($values), 1) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Website\Controller;
|
namespace App\Website\Controller;
|
||||||
|
|
||||||
|
use App\Game\Service\FeedbackService;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
@@ -17,10 +18,11 @@ final class HomeController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route(path: '/briefing', name: 'website_intro')]
|
#[Route(path: '/briefing', name: 'website_intro')]
|
||||||
public function intro(): Response
|
public function intro(FeedbackService $feedbackService): Response
|
||||||
{
|
{
|
||||||
return $this->render(
|
return $this->render('website/home/intro.html.twig', [
|
||||||
'website/home/intro.html.twig');
|
'feedbackSummary' => $feedbackService->getFeedbackSummary(),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route(path: '/looking-for-help', name: 'website_help_wanted')]
|
#[Route(path: '/looking-for-help', name: 'website_help_wanted')]
|
||||||
|
|||||||
@@ -101,6 +101,7 @@
|
|||||||
{ route: 'game_admin_users', label: 'Users', icon: '👤' },
|
{ route: 'game_admin_users', label: 'Users', icon: '👤' },
|
||||||
{ route: 'game_admin_games', label: 'Games', icon: '🎮' },
|
{ route: 'game_admin_games', label: 'Games', icon: '🎮' },
|
||||||
{ route: 'game_admin_sessions', label: 'Sessions', icon: '▶' },
|
{ route: 'game_admin_sessions', label: 'Sessions', icon: '▶' },
|
||||||
|
{ route: 'game_admin_feedback', label: 'Feedback', icon: '💬' },
|
||||||
{ route: 'game_admin_email_log', label: 'Email Log', icon: '✉' },
|
{ route: 'game_admin_email_log', label: 'Email Log', icon: '✉' },
|
||||||
] %}
|
] %}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
{% extends 'game/admin/base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Feedback — Admin{% endblock %}
|
||||||
|
|
||||||
|
{% block admin_body %}
|
||||||
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem;">
|
||||||
|
<h1 style="margin: 0; font-size: 1.5rem; color: #0f172a;">Feedback</h1>
|
||||||
|
<span style="color: #64748b; font-size: 0.9rem;">{{ entries|length }} submission{{ entries|length != 1 ? 's' : '' }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 2rem;">
|
||||||
|
{% set stats = [
|
||||||
|
{ label: 'Submissions', value: summary.count, color: '#64748b' },
|
||||||
|
{ label: 'Avg. Difficulty', value: summary.avgDifficulty is not null ? summary.avgDifficulty ~ '/10' : '—', color: '#3b82f6' },
|
||||||
|
{ label: 'Avg. Entertainment', value: summary.avgEntertaining is not null ? summary.avgEntertaining ~ '/10' : '—', color: '#8b5cf6' },
|
||||||
|
{ label: 'Avg. Theme', value: summary.avgTheme is not null ? summary.avgTheme ~ '/10' : '—', color: '#10b981' },
|
||||||
|
] %}
|
||||||
|
|
||||||
|
{% for stat in stats %}
|
||||||
|
<div style="
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
border-left: 4px solid {{ stat.color }};
|
||||||
|
box-shadow: 0 1px 3px rgba(0,0,0,.07);
|
||||||
|
">
|
||||||
|
<div style="font-size: 1.75rem; font-weight: 700; color: {{ stat.color }};">{{ stat.value }}</div>
|
||||||
|
<div style="font-size: 0.8rem; color: #64748b; margin-top: 0.25rem;">{{ stat.label }}</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.07); overflow: hidden;">
|
||||||
|
<table style="width: 100%; min-width: 760px; border-collapse: collapse; font-size: 0.9rem;">
|
||||||
|
<thead>
|
||||||
|
<tr style="background: #f1f5f9; border-bottom: 1px solid #e2e8f0;">
|
||||||
|
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Game</th>
|
||||||
|
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Session</th>
|
||||||
|
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Player</th>
|
||||||
|
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Difficulty</th>
|
||||||
|
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Entertainment</th>
|
||||||
|
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Theme</th>
|
||||||
|
<th style="padding: 0.75rem 1rem; text-align: left; color: #475569; font-weight: 600;">Comment</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for entry in entries %}
|
||||||
|
<tr style="border-bottom: 1px solid #f1f5f9;">
|
||||||
|
<td style="padding: 0.75rem 1rem; font-weight: 500; color: #0f172a;">{{ entry.session.game.name }}</td>
|
||||||
|
<td style="padding: 0.75rem 1rem;">
|
||||||
|
<a href="{{ path('game_admin_view_session', {session: entry.session.id}) }}" style="color: #3b82f6; text-decoration: none;">#{{ entry.session.id }}</a>
|
||||||
|
</td>
|
||||||
|
<td style="padding: 0.75rem 1rem; color: #475569;">{{ entry.player.user.username }}</td>
|
||||||
|
<td style="padding: 0.75rem 1rem; color: #475569;">{{ entry.difficulty ?? '—' }}</td>
|
||||||
|
<td style="padding: 0.75rem 1rem; color: #475569;">{{ entry.entertaining ?? '—' }}</td>
|
||||||
|
<td style="padding: 0.75rem 1rem; color: #475569;">{{ entry.theme ?? '—' }}</td>
|
||||||
|
<td style="padding: 0.75rem 1rem; color: #475569; max-width: 320px; white-space: pre-wrap;">{{ entry.text ?? '' }}</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" style="padding: 2rem; text-align: center; color: #94a3b8;">No feedback submitted yet.</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -30,6 +30,17 @@
|
|||||||
color: var(--brand-teal-light, #6fb8d1);
|
color: var(--brand-teal-light, #6fb8d1);
|
||||||
padding-right: .1em;
|
padding-right: .1em;
|
||||||
}
|
}
|
||||||
|
.briefing-feedback {
|
||||||
|
background: rgba(111, 184, 209, .08);
|
||||||
|
border: 1px solid #1c5a70;
|
||||||
|
border-radius: .5rem;
|
||||||
|
padding: 1.25rem;
|
||||||
|
}
|
||||||
|
.briefing-feedback-stat {
|
||||||
|
font-size: 1.75rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #6fb8d1;
|
||||||
|
}
|
||||||
.dev-watermark-wrap {
|
.dev-watermark-wrap {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@@ -101,6 +112,34 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if feedbackSummary.count > 0 %}
|
||||||
|
<div class="briefing-feedback mb-4">
|
||||||
|
<div class="text-uppercase small mb-3" style="letter-spacing: .1em; color: #6fb8d1;">
|
||||||
|
Field Reports from {{ feedbackSummary.count }} Agent{{ feedbackSummary.count != 1 ? 's' : '' }}
|
||||||
|
</div>
|
||||||
|
<div class="row text-center g-3">
|
||||||
|
{% if feedbackSummary.avgDifficulty is not null %}
|
||||||
|
<div class="col-4">
|
||||||
|
<div class="briefing-feedback-stat">{{ feedbackSummary.avgDifficulty }}/10</div>
|
||||||
|
<div class="small" style="color: #9fc7d6;">Difficulty</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if feedbackSummary.avgEntertaining is not null %}
|
||||||
|
<div class="col-4">
|
||||||
|
<div class="briefing-feedback-stat">{{ feedbackSummary.avgEntertaining }}/10</div>
|
||||||
|
<div class="small" style="color: #9fc7d6;">Entertainment</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if feedbackSummary.avgTheme is not null %}
|
||||||
|
<div class="col-4">
|
||||||
|
<div class="briefing-feedback-stat">{{ feedbackSummary.avgTheme }}/10</div>
|
||||||
|
<div class="small" style="color: #9fc7d6;">Theme</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<hr class="my-4" style="border-color: #1c5a70;">
|
<hr class="my-4" style="border-color: #1c5a70;">
|
||||||
|
|
||||||
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3">
|
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3">
|
||||||
|
|||||||
Reference in New Issue
Block a user