Admin panels
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Game\Controller;
|
||||
|
||||
use App\Game\Entity\Session;
|
||||
use App\Game\Enum\SessionStatus;
|
||||
use App\Game\Repository\GameRepository;
|
||||
use App\Game\Repository\SessionRepository;
|
||||
use App\Tech\Repository\UserRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -25,14 +28,23 @@ final class GameAdminController extends AbstractController
|
||||
#[Route('', name: 'game_admin_dashboard', methods: ['GET'])]
|
||||
public function index(
|
||||
UserRepository $userRepository,
|
||||
SessionRepository $sessionRepository
|
||||
SessionRepository $sessionRepository,
|
||||
GameRepository $gameRepository,
|
||||
): Response {
|
||||
$players = $userRepository->findByRole('ROLE_PLAYER');
|
||||
$sessions = $sessionRepository->findAll();
|
||||
$allUsers = $userRepository->findAll();
|
||||
$allSessions = $sessionRepository->findAll();
|
||||
$activeSessions = array_filter(
|
||||
$allSessions,
|
||||
fn(Session $s) => in_array($s->getStatus(), [SessionStatus::CREATED, SessionStatus::READY, SessionStatus::PLAYING])
|
||||
);
|
||||
|
||||
return $this->render('game/admin/index.html.twig', [
|
||||
'players' => $players,
|
||||
'sessions' => $sessions,
|
||||
'totalUsers' => count($allUsers),
|
||||
'totalPlayers' => count($userRepository->findByRole('ROLE_PLAYER')),
|
||||
'totalAdmins' => count($userRepository->findByRole('ROLE_ADMIN')),
|
||||
'totalGames' => count($gameRepository->findAll()),
|
||||
'totalSessions' => count($allSessions),
|
||||
'activeSessions' => count($activeSessions),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -44,18 +56,13 @@ final class GameAdminController extends AbstractController
|
||||
$username = $player->getUser()->getUsername();
|
||||
$logFile = $this->projectDir . '/var/log/sessions/' . $session->getId() . '/' . $username . '.txt';
|
||||
|
||||
$logs = '';
|
||||
if (file_exists($logFile)) {
|
||||
$logs = file_get_contents($logFile);
|
||||
}
|
||||
|
||||
$playersLogs[] = [
|
||||
'username' => $username,
|
||||
'logs' => $logs,
|
||||
'logs' => file_exists($logFile) ? file_get_contents($logFile) : '',
|
||||
];
|
||||
}
|
||||
|
||||
return $this->render('game/admin/session.html.twig', [
|
||||
return $this->render('game/admin/sessions/view.html.twig', [
|
||||
'session' => $session,
|
||||
'playersLogs' => $playersLogs,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user