Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
DashboardController | |
0.00% |
0 / 15 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
index | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
configureDashboard | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
configureMenuItems | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
configureUserMenu | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
configureActions | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Controller\Admin; |
4 | |
5 | use App\Entity\Pages; |
6 | use App\Entity\Projects; |
7 | use App\Entity\Quotes; |
8 | use App\Entity\User; |
9 | use EasyCorp\Bundle\EasyAdminBundle\Config\Action; |
10 | use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; |
11 | use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; |
12 | use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard; |
13 | use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem; |
14 | use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu; |
15 | use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController; |
16 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; |
17 | use Symfony\Component\Config\Definition\Exception\Exception; |
18 | use Symfony\Component\HttpFoundation\Response; |
19 | use Symfony\Component\Routing\Annotation\Route; |
20 | use Symfony\Component\Security\Core\User\UserInterface; |
21 | |
22 | class 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 | } |