chg: dev: increase the minimum PHP version to the latest major - and massive refactor on back-end, like Controllers and Repositories #4
This commit is contained in:
@@ -11,9 +11,10 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use App\Repository\PlayedGameRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
/**
|
||||
@@ -26,58 +27,26 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 11.
|
||||
*/
|
||||
#[AsController]
|
||||
class ProfileController extends AbstractController
|
||||
{
|
||||
#[Route('/profile', name: 'MineSeekerBundle_profile')]
|
||||
public function index(EntityManagerInterface $em): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
|
||||
public function __construct(private readonly PlayedGameRepository $repo) { }
|
||||
|
||||
#[Route('/profile', name: 'MineSeekerBundle_profile')]
|
||||
public function index(): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
$finished = '(g.redPoints IS NOT NULL OR g.resign IS NOT NULL)';
|
||||
|
||||
$total = (int) $em->createQuery(
|
||||
"SELECT COUNT(g.id) FROM App\Entity\PlayedGame g
|
||||
WHERE (g.red = :u OR g.blue = :u) AND {$finished}"
|
||||
)->setParameter('u', $user)->getSingleScalarResult();
|
||||
|
||||
$wins = (int) $em->createQuery(
|
||||
"SELECT COUNT(g.id) FROM App\Entity\PlayedGame g WHERE (
|
||||
(g.red = :u AND g.redPoints > g.bluePoints AND g.resign IS NULL) OR
|
||||
(g.blue = :u AND g.bluePoints > g.redPoints AND g.resign IS NULL) OR
|
||||
(g.red = :u AND g.resign = 'blue') OR
|
||||
(g.blue = :u AND g.resign = 'red')
|
||||
)"
|
||||
)->setParameter('u', $user)->getSingleScalarResult();
|
||||
|
||||
$losses = (int) $em->createQuery(
|
||||
"SELECT COUNT(g.id) FROM App\Entity\PlayedGame g WHERE (
|
||||
(g.red = :u AND g.bluePoints > g.redPoints AND g.resign IS NULL) OR
|
||||
(g.blue = :u AND g.redPoints > g.bluePoints AND g.resign IS NULL) OR
|
||||
(g.red = :u AND g.resign = 'red') OR
|
||||
(g.blue = :u AND g.resign = 'blue')
|
||||
)"
|
||||
)->setParameter('u', $user)->getSingleScalarResult();
|
||||
|
||||
$bombs = (int) $em->createQuery(
|
||||
"SELECT COUNT(g.id) FROM App\Entity\PlayedGame g WHERE
|
||||
(g.red = :u AND g.redExplodedBomb = true) OR
|
||||
(g.blue = :u AND g.blueExplodedBomb = true)"
|
||||
)->setParameter('u', $user)->getSingleScalarResult();
|
||||
|
||||
$recent = $em->createQuery(
|
||||
"SELECT g FROM App\Entity\PlayedGame g
|
||||
LEFT JOIN g.red rr LEFT JOIN g.blue bb
|
||||
LEFT JOIN g.redAnon ra LEFT JOIN g.blueAnon ba
|
||||
WHERE (g.red = :u OR g.blue = :u) AND {$finished}
|
||||
ORDER BY g.updated DESC"
|
||||
)->setParameter('u', $user)->setMaxResults(10)->getResult();
|
||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
|
||||
|
||||
return $this->render('Security/profile.html.twig', [
|
||||
'stats' => compact('total', 'wins', 'losses', 'bombs'),
|
||||
'recent' => $recent,
|
||||
'stats' => [
|
||||
'total' => $this->repo->countFinishedForUser($user),
|
||||
'wins' => $this->repo->countWinsForUser($user),
|
||||
'losses' => $this->repo->countLossesForUser($user),
|
||||
'bombs' => $this->repo->countBombsForUser($user),
|
||||
],
|
||||
'recent' => $this->repo->findRecentFinishedForUser($user),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user