<?php
namespace BackendApi\Application\Controller\App\Admin;
use BackendApi\Domain\Machine\Machine;
use BackendApi\Domain\Machine\Notification;
use BackendApi\Domain\Machine\ServiceHistory;
use BackendApi\Domain\Security\Account;
use BackendApi\Infrastructure\DoctrineAccounts;
use BackendApi\Infrastructure\DoctrineMachines;
use BackendApi\Infrastructure\DoctrineServiceHistories;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractDashboardController
{
private DoctrineMachines $doctrineMachines;
private DoctrineServiceHistories $doctrineServiceHistories;
private DoctrineAccounts $doctrineAccounts;
public function __construct(
DoctrineMachines $doctrineMachines,
DoctrineServiceHistories $doctrineServiceHistories,
DoctrineAccounts $doctrineAccounts
)
{
$this->doctrineMachines = $doctrineMachines;
$this->doctrineServiceHistories = $doctrineServiceHistories;
$this->doctrineAccounts = $doctrineAccounts;
}
/**
* @Route("/admin", name="app_admin")
*/
public function index(): Response
{
return $this->render('admin/dashboard.html.twig', [
'machinesCount' => $this->doctrineMachines->getMachinesCount(),
'serviceHistoriesCount' => $this->doctrineServiceHistories->allServiceHistoriesCount(),
'activeAccountsCount' => $this->doctrineAccounts->allActiveAccountsCount(),
]);
}
public function configureDashboard(): Dashboard
{
return Dashboard::new()
->setTitle('Baume Admin')
->setFaviconPath('assets/images/favicon.png');
}
public function configureMenuItems(): iterable
{
return [
MenuItem::linkToDashboard('Dashboard', 'fa fa-home'),
MenuItem::linkToCrud('Maszyny', 'fa fa-gears', Machine::class),
MenuItem::linkToCrud('Historia serwisowa', 'fa fa-screwdriver-wrench', ServiceHistory::class),
MenuItem::linkToCrud('Przypomnienia', 'fa fa-bell', Notification::class),
MenuItem::linkToCrud('Użytkownicy', 'fa fa-users', Account::class),
];
}
}