src/EventSubscriber/KnpMenuSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. // src/EventSubscriber/KnpMenuBuilderSubscriber.php
  3. namespace App\EventSubscriber;
  4. use KevinPapst\AdminLTEBundle\Event\KnpMenuEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Security\Core\Security;
  7. class KnpMenuSubscriber implements EventSubscriberInterface
  8. {
  9.     protected $security;
  10.     public function __construct(Security $security)
  11.     {
  12.         $this->security $security;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             KnpMenuEvent::class => ['onSetupMenu'100],
  18.         ];
  19.     }
  20.     
  21.     public function onSetupMenu(KnpMenuEvent $event)
  22.     {
  23.         if (null === $this->security->getUser()) {
  24.             return;
  25.         }
  26.         
  27.         /* @var $myUser User */
  28.         $myUser $this->security->getUser();
  29.         
  30.         $menu $event->getMenu();
  31.         if($this->security->isGranted('ROLE_VENDEUR')== null){
  32.             //Menu Personnel
  33.                 $menu->addChild('personnels', [
  34.                 'route' => 'app_personnel_index',
  35.                 'label' => 'menu.personnel',
  36.                 'childOptions' => $event->getChildOptions(),
  37.             ])->setLabelAttribute('class''icon ti ti-users')
  38.             ->setAttributes(['class' => 'nav-item dropdown show'])
  39.             ->setLinkAttributes(['class' => 'nav-link dropdown-toggle''data-bs-toggle'=>'dropdown''data-bs-auto-close'=>'false''role'=>'button''aria-expanded'=>'true']);
  40.             $menu->getChild('personnels')->addChild('personnel-liste', [
  41.                 'route' => 'app_personnel_index',
  42.                 'label' => 'menu.liste',
  43.                 'childOptions' => $event->getChildOptions()
  44.             ])->setLabelAttribute('class''icon ti ti-list')
  45.                 ->setLinkAttribute('class''dropdown-item');
  46.             $menu->getChild('personnels')->addChild('pointage', [
  47.                 'route' => 'pointage_app',
  48.                 'label' => 'menu.pointageJournee',
  49.                 'childOptions' => $event->getChildOptions()
  50.             ])->setLabelAttribute('class''icon ti ti-calendar-plus')
  51.             ->setLinkAttribute('class''dropdown-item');
  52.             $menu->getChild('personnels')->addChild('mission', [
  53.                 'route' => 'app_tbl_mission_index',
  54.                 'label' => 'menu.pointageMissions',
  55.                 'childOptions' => $event->getChildOptions()
  56.             ])->setLabelAttribute('class''icon ti ti-hourglass-high')
  57.             ->setLinkAttribute('class''dropdown-item');
  58.             //Menu Operations
  59.             $menu->addChild('Opérations', [
  60.             'route' => 'app_tbl_operations_index',
  61.             'label' => 'menu.operations',
  62.             'childOptions' => $event->getChildOptions(),
  63.             ])->setLabelAttribute('class''icon ti ti-clipboard-data')
  64.             ->setAttributes(['class' => 'nav-item dropdown'])
  65.             ->setLinkAttributes(['class' => 'nav-link dropdown-toggle''data-bs-toggle'=>'dropdown''data-bs-auto-close'=>'false''role'=>'button''aria-expanded'=>'false']);
  66.             $menu->getChild('Opérations')->addChild('operations-liste', [
  67.                 'route' => 'app_tbl_operations_index',
  68.                 'label' => 'menu.liste',
  69.                 'extras' => [
  70.                     'routes' => [
  71.                         [
  72.                             'route' => 'operations_edit'
  73.                         ]
  74.                     ]
  75.                 ],
  76.                 'childOptions' => $event->getChildOptions()
  77.             ])->setLabelAttribute('class''icon ti ti-list')->setLinkAttribute('class''dropdown-item');
  78.             $menu->getChild('Opérations')->addChild('operations-Ajouter', [
  79.                 'route' => 'app_tbl_operations_new',
  80.                 'label' => 'menu.ajouter',
  81.                 'childOptions' => $event->getChildOptions()
  82.             ])->setLabelAttribute('class''icon ti ti-plus')->setLinkAttribute('class''dropdown-item');
  83.             //Menu Operation Vente
  84.             $menu->addChild('Opérations Ventes', [
  85.                 'route' => 'app_tbl_operation_vente_index',
  86.                 'label' => 'menu.operationsVentes',
  87.                 'childOptions' => $event->getChildOptions(),
  88.                 ])->setLabelAttribute('class''icon ti ti-shopping-cart')
  89.                 ->setAttributes(['class' => 'nav-item dropdown'])
  90.                 ->setLinkAttributes(['class' => 'nav-link dropdown-toggle''data-bs-toggle'=>'dropdown''data-bs-auto-close'=>'false''role'=>'button''aria-expanded'=>'false']);
  91.             $menu->getChild('Opérations Ventes')->addChild('operations-liste', [
  92.                 'route' => 'app_tbl_operation_vente_index',
  93.                 'label' => 'menu.liste',
  94.                 'extras' => [
  95.                     'routes' => [
  96.                         [
  97.                             'route' => 'app_tbl_operation_vente_edit'
  98.                         ]
  99.                     ]
  100.                 ],
  101.                 'childOptions' => $event->getChildOptions()
  102.             ])->setLabelAttribute('class''icon ti ti-list')->setLinkAttribute('class''dropdown-item');
  103.             $menu->getChild('Opérations Ventes')->addChild('operations-Ajouter', [
  104.                 'route' => 'app_tbl_operation_vente_new',
  105.                 'label' => 'menu.ajouter',
  106.                 'childOptions' => $event->getChildOptions()
  107.             ])->setLabelAttribute('class''icon ti ti-plus')->setLinkAttribute('class''dropdown-item');
  108.             //Menu Gestion Stock
  109.             $menu->addChild('stockCaisse', [
  110.                 'route' => 'app_tbl_mouvement_caisse_index',
  111.                 'label' => 'menu.stockCaisse',
  112.                 'childOptions' => $event->getChildOptions(),
  113.                 'extras' => [
  114.                     'pere' => true
  115.                 ]
  116.             ])->setLabelAttribute('class''icon ti ti-box');
  117.             //Menu Stock
  118.             $menu->addChild('stock', [
  119.                 'route' => 'app_tbl_mouvement_index',
  120.                 'label' => 'menu.stock',
  121.                 'childOptions' => $event->getChildOptions(),
  122.                 'extras' => [
  123.                     'pere' => true
  124.                 ]
  125.             ])->setLabelAttribute('class''icon ti ti-arrows-left-right');
  126.             if(!$this->security->isGranted('ROLE_ADMIN_FERME')){
  127.                 $menu->addChild('lapin', [
  128.                     'route' => 'app_lapin_production',
  129.                     'label' => 'menu.lapin',
  130.                     'childOptions' => $event->getChildOptions(),
  131.                     'extras' => [
  132.                         'pere' => true
  133.                     ]
  134.                 ])->setLabelAttribute('class''icon ti ti-calendar-time');
  135.             }
  136.             if($this->security->isGranted('ROLE_SUPER_ADMIN') || $this->security->isGranted('ROLE_ADMIN') || $this->security->isGranted('ROLE_ADMIN_FERME')){
  137.                 $menu->addChild('admin', [
  138.                     'route' => 'sonata_admin_redirect',
  139.                     'label' => 'menu.administrationDonnees',
  140.                     'childOptions' => $event->getChildOptions(),
  141.                     'extras' => [
  142.                         'pere' => true
  143.                     ]
  144.                 ])->setLabelAttribute('class''icon ti ti-home');
  145.                 $menu->getChild('personnels')->addChild('salaire', [
  146.                     'route' => 'app_tbl_paie_salaire_index',
  147.                     'label' => 'menu.gestionSalaires',
  148.                     'childOptions' => $event->getChildOptions()
  149.                 ])->setLabelAttribute('class''icon ti ti-credit-card')->setLinkAttribute('class''dropdown-item');
  150.             }
  151.             $menu->getChild('personnels')->addChild('paie-avance', [
  152.                 'route' => 'paie_app',
  153.                 'label' => 'menu.paieAvance',
  154.                 'childOptions' => $event->getChildOptions()
  155.             ])->setLabelAttribute('class''icon ti ti-calculator')->setLinkAttribute('class''dropdown-item');
  156.             $menu->getChild('personnels')->addChild('resultats', [
  157.                 'route' => 'paie_resultats',
  158.                 'label' => 'menu.resultats',
  159.                 'childOptions' => $event->getChildOptions()
  160.             ])->setLabelAttribute('class''icon ti ti-plus')->setLinkAttribute('class''dropdown-item');
  161.         }
  162.     
  163.     }
  164. }