This commit is contained in:
1 parent
f15d9a9cfd
commit
054e970df9
36 files changed
+1434
-363
No files matched your search
@@ -0,0 +1,51 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user