All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 1m55s
52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Admin;
|
|
|
|
use App\Repository\AlbumRepository;
|
|
use App\Repository\ReviewRepository;
|
|
use App\Repository\UserRepository;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Bundle\SecurityBundle\Attribute\IsGranted;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
/**
|
|
* DashboardController shows high-level site activity to admins.
|
|
*/
|
|
#[IsGranted('ROLE_ADMIN')]
|
|
class DashboardController extends AbstractController
|
|
{
|
|
/**
|
|
* Renders overall activity metrics for administrators.
|
|
*/
|
|
#[Route('/admin/dashboard', name: 'admin_dashboard', methods: ['GET'])]
|
|
public function dashboard(ReviewRepository $reviews, AlbumRepository $albums, UserRepository $users): Response
|
|
{
|
|
$totalReviews = (int) $reviews->createQueryBuilder('r')
|
|
->select('COUNT(r.id)')
|
|
->getQuery()->getSingleScalarResult();
|
|
|
|
$totalAlbums = (int) $albums->createQueryBuilder('a')
|
|
->select('COUNT(a.id)')
|
|
->getQuery()->getSingleScalarResult();
|
|
|
|
$totalUsers = (int) $users->createQueryBuilder('u')
|
|
->select('COUNT(u.id)')
|
|
->getQuery()->getSingleScalarResult();
|
|
|
|
$recentReviews = $reviews->findLatest(50);
|
|
$recentAlbums = $albums->createQueryBuilder('a')
|
|
->orderBy('a.createdAt', 'DESC')
|
|
->setMaxResults(50)
|
|
->getQuery()->getResult();
|
|
|
|
return $this->render('admin/site_dashboard.html.twig', [
|
|
'totalReviews' => $totalReviews,
|
|
'totalAlbums' => $totalAlbums,
|
|
'totalUsers' => $totalUsers,
|
|
'recentReviews' => $recentReviews,
|
|
'recentAlbums' => $recentAlbums,
|
|
]);
|
|
}
|
|
}
|