src/Controller/Admin/DashboardController.php line 91

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\Country;
  4. use App\Entity\Department;
  5. use App\Entity\Digest;
  6. use App\Entity\GameProvider;
  7. use App\Entity\Invoice;
  8. use App\Entity\InvoiceChatChannel;
  9. use App\Entity\InvoicePeriod;
  10. use App\Entity\Language;
  11. use App\Entity\PaymentProvider;
  12. use App\Entity\SalaryPeriod;
  13. use App\Entity\SalaryPeriodExport;
  14. use App\Entity\User;
  15. use App\Entity\UserAnalytics;
  16. use App\Entity\UserNotification;
  17. use App\Entity\UserShiftPeriod;
  18. use App\Model\UserRoles;
  19. use App\Repository\UserNotificationRepository;
  20. use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
  21. use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
  22. use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
  23. use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
  24. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
  25. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. use Symfony\Component\Security\Core\User\UserInterface;
  30. use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
  31. /**
  32.  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  33.  */
  34. class DashboardController extends AbstractDashboardController
  35. {
  36.     private UserNotificationRepository $userNotificationRepository;
  37.     private UploaderHelper $uploaderHelper;
  38.     private AdminUrlGenerator $adminUrlGenerator;
  39.     public function __construct(UserNotificationRepository $userNotificationRepositoryUploaderHelper $uploaderHelperAdminUrlGenerator $adminUrlGenerator)
  40.     {
  41.         $this->userNotificationRepository $userNotificationRepository;
  42.         $this->uploaderHelper $uploaderHelper;
  43.         $this->adminUrlGenerator $adminUrlGenerator;
  44.     }
  45.     /**
  46.      * @Route("/admin", name="admin")
  47.      */
  48.     public function index(): Response
  49.     {
  50.         return $this->redirect($this->adminUrlGenerator->setController(UserInvoicePeriodCrudController::class)->generateUrl());
  51.     }
  52.     public function configureAssets(): Assets
  53.     {
  54.         $assets parent::configureAssets();
  55.         return $assets
  56.             ->addCssFile('/assets/css/main.css');
  57.     }
  58.     public function configureUserMenu(UserInterface $user): UserMenu
  59.     {
  60.         if (!$user instanceof User) {
  61.             throw new \Exception('Wrong user');
  62.         }
  63.         $userMenu parent::configureUserMenu($user);
  64.         $userMenu->setAvatarUrl($this->uploaderHelper->asset($user'imageFile'));
  65. //        if ($user instanceof User) {
  66.         $profileUrl $this->adminUrlGenerator
  67.             ->setController(UserCrudController::class)
  68.             ->setAction('edit')
  69.             ->setEntityId(
  70.                 $user->getId()
  71.             )->generateUrl();
  72.         $userMenu->addMenuItems(
  73.             [
  74.                 MenuItem::linkToUrl('My Profile''fa fa-id-card'$profileUrl),
  75.             ]
  76.         );
  77. //        }
  78.         return $userMenu;
  79.     }
  80.     public function configureDashboard(): Dashboard
  81.     {
  82.         return Dashboard::new()
  83.             // the name visible to end users
  84.             ->setTitle('Eyeconweb Manager Quality')
  85.             // the path defined in this method is passed to the Twig asset() function
  86.             ->setFaviconPath('favicon.svg')
  87.             // the domain used by default is 'messages'
  88. //            ->setTranslationDomain('admin')
  89.             // there's no need to define the "text direction" explicitly because
  90.             // its default value is inferred dynamically from the user locale
  91.             ->setTextDirection('ltr')
  92.             // set this option if you prefer the page content to span the entire
  93.             // browser width, instead of the default design which sets a max width
  94.             ->renderContentMaximized()
  95.             // set this option if you prefer the sidebar (which contains the main menu)
  96.             // to be displayed as a narrow column instead of the default expanded design
  97.             ->renderSidebarMinimized()
  98.             // by default, all backend URLs include a signature hash. If a user changes any
  99.             // query parameter (to "hack" the backend) the signature won't match and EasyAdmin
  100.             // triggers an error. If this causes any issue in your backend, call this method
  101.             // to disable this feature and remove all URL signature checks
  102.             ->disableUrlSignatures()
  103.             ->generateRelativeUrls();
  104.     }
  105.     public function configureMenuItems(): iterable
  106.     {
  107.         /** @var User $user */
  108.         $user $this->getUser();
  109.         if (null == $user) {
  110.             throw new AccessDeniedHttpException();
  111.         }
  112.         $countUserNotification $this->userNotificationRepository->count(['recipient' => $user'read' => false]);
  113.         return [
  114.             MenuItem::linkToDashboard('Dashboard''fa fa-home'),
  115.             MenuItem::linkToCrud('user_shift_period.list''fa fa-clock'UserShiftPeriod::class),
  116.             MenuItem::linkToCrud('digest.list''fa fa-feed'Digest::class)->setAction('detail'),
  117.             MenuItem::linkToCrud('invoice.list''fa fa-list'Invoice::class),
  118.             MenuItem::linkToCrud('user_notification.list''fa fa-bell'.($countUserNotification ' text-danger' ''), UserNotification::class),
  119.             MenuItem::linkToCrud('invoice_period.list''fa fa-calendar-week'InvoicePeriod::class)
  120.                 ->setPermission(UserRoles::ROLE_ADMIN),
  121.             MenuItem::linkToCrud('invoice_chat_channel.list''fa fa-network-wired'InvoiceChatChannel::class)
  122.                 ->setPermission(UserRoles::ROLE_SUPER_ADMIN),
  123.             MenuItem::linkToCrud('user.list''fa fa-user'User::class)
  124.                 ->setPermission(UserRoles::ROLE_SUPER_ADMIN),
  125.             MenuItem::linkToCrud('department.list''fa fa-user-group'Department::class)
  126.                 ->setPermission(UserRoles::ROLE_SUPER_ADMIN),
  127.             MenuItem::linkToCrud('country.list''fa fa-globe'Country::class)
  128.                 ->setPermission(UserRoles::ROLE_SUPER_ADMIN),
  129.             MenuItem::linkToCrud('language.list''fa fa-language'Language::class),
  130.             MenuItem::linkToCrud('payment_provider.list''fa fa-credit-card-alt'PaymentProvider::class)
  131.                 ->setPermission(UserRoles::ROLE_ADMIN),
  132.             MenuItem::linkToCrud('game_provider.list''fa fa-gamepad'GameProvider::class)
  133.                 ->setPermission(UserRoles::ROLE_ADMIN),
  134.             MenuItem::linkToCrud('salary_period.list''fa fa-money'SalaryPeriod::class)
  135.                 ->setPermission(UserRoles::ROLE_SUPER_ADMIN),
  136.             MenuItem::linkToCrud('salary_period_exports.list''fa fa-file-excel-o'SalaryPeriodExport::class)
  137.                 ->setPermission(UserRoles::ROLE_SUPER_ADMIN),
  138.             MenuItem::linkToCrud('user.analytics.list''fa fa-address-card-o'UserAnalytics::class),
  139.         ];
  140.     }
  141. }