Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
DashboardController
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 5
42
0.00% covered (danger)
0.00%
0 / 1
 index
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 configureDashboard
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 configureMenuItems
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 configureUserMenu
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 configureActions
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Controller\Admin;
4
5use App\Entity\Pages;
6use App\Entity\Projects;
7use App\Entity\Quotes;
8use App\Entity\User;
9use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
10use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
11use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
12use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
13use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
14use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
15use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
16use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
17use Symfony\Component\Config\Definition\Exception\Exception;
18use Symfony\Component\HttpFoundation\Response;
19use Symfony\Component\Routing\Annotation\Route;
20use Symfony\Component\Security\Core\User\UserInterface;
21
22class DashboardController extends AbstractDashboardController
23{
24    #[isGranted(data: 'ROLE_ADMIN')]
25    #[Route(path: '/admin', name: 'admin')]
26    public function index(): Response
27    {
28        // return parent::index();
29        return $this->render(view: 'admin/index.html.twig');
30    }
31
32    public function configureDashboard(): Dashboard
33    {
34        return Dashboard::new()
35            ->setTitle(title: '24unix Admin');
36    }
37
38    public function configureMenuItems(): iterable
39    {
40        yield MenuItem::linkToUrl(label: 'Homepage', icon: 'fa fa-home', url: $this->generateUrl(route: 'app_main'));
41        yield MenuItem::linkToDashboard(label: 'Dashboard', icon: 'fa fa-dashboard');
42        yield MenuItem::linkToCrud(label: 'Users', icon: 'fa fa-users', entityFqcn: User::class);
43        yield MenuItem::linkToCrud(label: 'Projects', icon: 'fa fa-file-code-o', entityFqcn: Projects::class);
44        yield MenuItem::linkToCrud(label: 'Pages', icon: 'fa fa-newspaper-o', entityFqcn: Pages::class);
45        yield MenuItem::linkToCrud(label: 'Quotes', icon: 'fa fa-quote-left', entityFqcn: Quotes::class);
46    }
47
48    public function configureUserMenu(UserInterface $user): UserMenu
49    {
50        if (!$user instanceof User) {
51            throw new Exception(message: 'Wrong User!');
52        }
53
54        return parent::configureUserMenu(user: $user)
55            ->setAvatarUrl(url: 'uploads/avatars/' . $user->getAvatar());
56    }
57
58    public function configureActions(): Actions
59    {
60        return parent::configureActions()
61            ->add(pageName: Crud::PAGE_INDEX, actionNameOrObject: Action::DETAIL);
62    }
63}