src/Listener/MenuBuilderListener.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Listener;
  3. use App\Service\Admin\WarehouseManager;
  4. use App\Service\SupportChat;
  5. use Sonata\AdminBundle\Event\ConfigureMenuEvent;
  6. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  7. final class MenuBuilderListener
  8. {
  9.     private SupportChat $supportChat;
  10.     private AuthorizationCheckerInterface $securityChecker;
  11.     private WarehouseManager $warehouseManager;
  12.     public function __construct(
  13.         SupportChat $supportChat,
  14.         AuthorizationCheckerInterface $securityChecker,
  15.         WarehouseManager $warehouseManager
  16.     ) {
  17.         $this->supportChat $supportChat;
  18.         $this->securityChecker $securityChecker;
  19.         $this->warehouseManager $warehouseManager;
  20.     }
  21.     public function addMenuItems(ConfigureMenuEvent $event): void
  22.     {
  23.         $menu $event->getMenu();
  24.         $menu $menu->addChild('reports', [
  25.             'label' => 'Statistics',
  26.             'on_top' => true,
  27.         ])->setExtras([
  28.             'icon' => 'bi bi-bar-chart'// html is also supported
  29.         ]);
  30.         $menu->addChild('dashboard', [
  31.             'route' => 'admin_app_statistics_dashboard',
  32.             'label' => 'Dashboard',
  33.         ]);
  34.         if ($this->securityChecker->isGranted('ROLE_ADMIN')
  35.             || $this->securityChecker->isGranted('ROLE_CUSTOMER')
  36.         ) {
  37.             $menu->addChild('marketing_cost', [
  38.                 'route' => 'admin_app_marketingcost_list',
  39.                 'label' => 'Add Cost Page',
  40.                 'on_top' => true,
  41.             ]);
  42.         }
  43.         $ticketCount sprintf(' (%s)'$this->supportChat->ticketCount());
  44.         if ($this->securityChecker->isGranted('ROLE_ADMIN')) {
  45.             $menu $event->getMenu();
  46.             $menu->addChild('Customer care', [
  47.                 'label' => 'Customer care' $ticketCount,
  48.                 'roles' => ['ROLE_ADMIN'],
  49.                 'on_top' => true,
  50.             ])->setExtras([
  51.                 'icon' => 'bi bi-envelope',
  52.             ])->addChild('Tickets', [
  53.                 'route' => 'admin_app_support_chat_list',
  54.                 'label' => 'Tickets',
  55.                 'icon' => 'bi bi-envelope',
  56.             ]);
  57.         }
  58.         $warehouses $this->warehouseManager->getList();
  59.         if ($this->securityChecker->isGranted('ROLE_ADMIN') && !empty($warehouses)) {
  60.             $menu $event->getMenu();
  61.             $warehouseMenuItem $menu->addChild('Warehouse', [
  62.                 'label' => 'Warehouse',
  63.                 'roles' => ['ROLE_ADMIN'],
  64.                 'on_top' => true,
  65.             ])->setExtras([
  66.                 'icon' => 'bi bi-house',
  67.             ]);
  68.             foreach ($warehouses as $warehouse) {
  69.                 $currentRow $warehouseMenuItem->addChild($warehouse->getName(), [
  70.                     'label' => $warehouse->getName(),
  71.                     'on_top' => true,
  72.                 ])->setExtras([
  73.                     'icon' => '',
  74.                 ]);
  75.                 $currentRow->addChild('Fulfillment Settings', [
  76.                         'route' => 'admin_app_fulfillmentsettings_list',
  77.                         'routeParameters' => ['warehouse_id' => $warehouse->getId()],
  78.                         'label' => 'Fulfillment Settings',
  79.                     ]);
  80.                 $currentRow->addChild('Pick&Pack Settings', [
  81.                         'route' => 'admin_app_pickandpacksettings_list',
  82.                         'routeParameters' => ['warehouse_id' => $warehouse->getId()],
  83.                         'label' => 'Pick&Pack Settings',
  84.                     ]);
  85.                 $currentRow->addChild('Shipping Providers', [
  86.                         'route' => 'admin_app_shippingprovider_list',
  87.                         'routeParameters' => ['warehouse_id' => $warehouse->getId()],
  88.                         'label' => 'Shipping Providers',
  89.                     ]);
  90.             }
  91.         }
  92.         if ($this->securityChecker->isGranted('ROLE_ADMIN')) {
  93.             $menu $event->getMenu();
  94.             $trackingMenuItem $menu->addChild('Tracking', [
  95.                 'label' => 'Tracking',
  96.                 'roles' => ['ROLE_ADMIN'],
  97.                 'on_top' => true,
  98.             ])->setExtras([
  99.                 'icon' => 'bi bi-share-fill',
  100.             ]);
  101.             $trackingMenuItem->addChild('Source', [
  102.                     'label' => 'Source',
  103.                     'route' => 'admin_app_tracker_list',
  104.                 ])->setExtras([
  105.                     'icon' => '',
  106.                 ]);
  107.             $trackingMenuItem->addChild('Funnel', [
  108.                 'label' => 'Funnel',
  109.                 'route' => 'admin_app_funnel_list',
  110.             ])->setExtras([
  111.                 'icon' => '',
  112.             ]);
  113.             $trackingMenuItem->addChild('Funnel Step', [
  114.                 'label' => 'Funnel Steps',
  115.                 'route' => 'admin_app_funnelstep_list',
  116.             ])->setExtras([
  117.                 'icon' => '',
  118.             ]);
  119.             $trackingMenuItem->addChild('Dashboard', [
  120.                 'label' => 'Dashboard',
  121.                 'route' => 'admin_app_funnel_statistics_dashboard',
  122.             ])->setExtras([
  123.                 'icon' => '',
  124.             ]);
  125.             $productGroup $menu->getChild('Product');
  126.             if ($productGroup) {
  127.                 $productGroup->addChild('Stock History', [
  128.                     'label' => 'Stock History',
  129.                     'route' => 'admin_app_productstocktransaction_list',
  130.                 ])->setExtras([
  131.                     'icon' => '',
  132.                     'routes' => [
  133.                         ['route' => 'admin_app_productstocktransaction_list'],
  134.                     ],
  135.                 ]);
  136.                 $productGroup->addChild('Inventory', [
  137.                     'label' => 'Inventory',
  138.                     'route' => 'admin_app_productstocktransaction_inventory',
  139.                 ])->setExtras([
  140.                     'icon' => '',
  141.                     'routes' => [
  142.                         ['route' => 'admin_app_productstocktransaction_inventory'],
  143.                     ],
  144.                 ]);
  145.             }
  146.         }
  147.     }
  148. }