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 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;
|
||||
|
||||
use App\Game\Service\FeedbackService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
@@ -17,10 +18,11 @@ final class HomeController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route(path: '/briefing', name: 'website_intro')]
|
||||
public function intro(): Response
|
||||
public function intro(FeedbackService $feedbackService): Response
|
||||
{
|
||||
return $this->render(
|
||||
'website/home/intro.html.twig');
|
||||
return $this->render('website/home/intro.html.twig', [
|
||||
'feedbackSummary' => $feedbackService->getFeedbackSummary(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/looking-for-help', name: 'website_help_wanted')]
|
||||
|
||||
Reference in New Issue
Block a user