src/EventSubscriber/KnpMenuBuilderSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. // src/EventSubscriber/KnpMenuBuilderSubscriber.php
  3. namespace App\EventSubscriber;
  4. use App\Entity\ClientsChantiers;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use KevinPapst\AdminLTEBundle\Event\KnpMenuEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  9. use Symfony\Component\Security\Core\Security;
  10. class KnpMenuBuilderSubscriber implements EventSubscriberInterface
  11. {
  12.     public $checker;
  13.     public $security;
  14.     public $em;
  15.     public function __construct(AuthorizationCheckerInterface $authorizationChecker,Security $security,EntityManagerInterface $em)
  16.     {
  17.         $this->checker $authorizationChecker;
  18.         $this->security $security;
  19.         $this->em $em;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             KnpMenuEvent::class => ['onSetupMenu'100],
  25.         ];
  26.     }
  27.     public function onSetupMenu(KnpMenuEvent $event)
  28.     {
  29.         $user $this->security->getUser();
  30.         $menu $event->getMenu();
  31.         $menu->addChild(
  32.             'accueil',
  33.             ['route' => 'publicPages','label' => 'Retour au site''childOptions' => $event->getChildOptions()]
  34.         )->setLabelAttribute('icon''fas fa-home');
  35.         // Mes outils
  36.         $menu->addChild(
  37.             'menu-label-01',
  38.             ['label' => 'Mes outils''childOptions' => $event->getChildOptions()]
  39.         )->setAttribute('class''header');
  40.         $menu->addChild(
  41.             'homepage',
  42.             ['route' => 'admin''label' => 'Dashboard''childOptions' => $event->getChildOptions()]
  43.         )->setLabelAttribute('icon''fas fa-tachometer-alt');
  44.         // --------------------------------------------
  45.         // ----------------- MENU USER ---------------
  46.         // --------------------------------------------
  47.         if ($this->checker->isGranted('ROLE_USER')) {
  48.             if(!empty($user->getAcls())) {
  49.                 // Mes chantiers
  50.                 $menu->addChild(
  51.                     'menu-admin-102',
  52.                     ['label' => 'Mes adresses''childOptions' => $event->getChildOptions()]
  53.                 )->setAttribute('class''header');
  54.                 $loop 1;
  55.                 foreach ($user->getAcls()->getListacces() as $actList) {
  56.                     $EntityClientsChantiers $this->em->getRepository(ClientsChantiers::class)->findOneBy(array('id'=>$actList));
  57.                     if($EntityClientsChantiers) {
  58.                         $menu->addChild(
  59.                             'menu-admin-102-child0'.$loop,
  60.                             [
  61.                                 'route' => 'admin_fiche_chantier',
  62.                                 'routeParameters' => array('id' => $EntityClientsChantiers->getId()),
  63.                                 'label' => $EntityClientsChantiers->getNom(),
  64.                                 'childOptions' => $event->getChildOptions(),
  65.                             ]
  66.                         )->setLabelAttribute('icon''fas fa-angle-right');
  67.                         $loop++;
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.         // --------------------------------------------
  73.         // -------------- MENU ADMIN ------------
  74.         // --------------------------------------------
  75.         if ($this->checker->isGranted('ROLE_ADMIN')) {
  76.             // Clients
  77.             $menu->addChild(
  78.                 'menu-admin-02',
  79.                 ['label' => 'Codial''childOptions' => $event->getChildOptions()]
  80.             )->setAttribute('class''header');
  81.             $menu->addChild(
  82.                 'menu-admin-02-child01',
  83.                 [
  84.                     'route' => 'admin_clients',
  85.                     'label' => 'Liste DO',
  86.                     'childOptions' => $event->getChildOptions(),
  87.                     /*'extras' => [
  88.                         'routes' => [
  89.                             'route' => 'admin_clients_detail_chantier'
  90.                         ]
  91.                     ],*/
  92.                 ]
  93.             )->setLabelAttribute('icon''fas fa-angle-right');
  94.             $menu->addChild(
  95.                 'menu-admin-02-child02',
  96.                 [
  97.                     'route' => 'admin_clients_chantiers',
  98.                     'label' => 'Liste Chantiers',
  99.                     'childOptions' => $event->getChildOptions(),
  100.                     'extras' => [
  101.                         'routes' => [
  102.                             'route' => 'admin_clients_detail_chantier'
  103.                         ]
  104.                     ],
  105.                 ]
  106.             )->setLabelAttribute('icon''fas fa-angle-right');
  107.             $menu->addChild(
  108.                 'menu-admin-02-child03',
  109.                 [
  110.                     'route' => 'admin_clients_interventions',
  111.                     'label' => 'Liste Interventions',
  112.                     'childOptions' => $event->getChildOptions(),
  113.                     'extras' => [
  114.                         'routes' => [
  115.                             'route' => 'admin_clients_detail_intervention'
  116.                         ]
  117.                     ],
  118.                 ]
  119.             )->setLabelAttribute('icon''fas fa-angle-right');
  120.         }
  121.         // --------------------------------------------
  122.         // -------------- MENU SUPER ADMIN ------------
  123.         // --------------------------------------------
  124.         if ($this->checker->isGranted('ROLE_SUPER_ADMIN')) {
  125.             // Mes pages
  126.             $menu->addChild(
  127.                 'menu-pages',
  128.                 ['label' => 'Front office''childOptions' => $event->getChildOptions()]
  129.             )->setAttribute('class''header');
  130.             $menu->addChild(
  131.                 'menu-pages-list',
  132.                 [
  133.                     'route' => 'listePages',
  134.                     'label' => 'Liste des pages',
  135.                     'childOptions' => $event->getChildOptions(),
  136.                     'extras' => [
  137.                         'routes' => [
  138.                             'route' => 'addPages'
  139.                         ],
  140.                     ],
  141.                 ]
  142.             )->setLabelAttribute('icon''fas fa-sitemap');
  143.             $menu->addChild(
  144.                 'menu-pages-list-sections',
  145.                 [
  146.                     'route' => 'listSectionAccueil',
  147.                     'label' => 'Sections accueil',
  148.                     'childOptions' => $event->getChildOptions(),
  149.                     'extras' => [
  150.                         'routes' => [
  151.                             'route' => 'addSectionAccueil'
  152.                         ],
  153.                     ],
  154.                 ]
  155.             )->setLabelAttribute('icon''fas fa-ellipsis-h');
  156.             $menu->addChild(
  157.                 'menu-pages-list-sectionsFooter',
  158.                 [
  159.                     'route' => 'listSectionFooter',
  160.                     'label' => 'Section footer',
  161.                     'childOptions' => $event->getChildOptions(),
  162.                     /*'extras' => [
  163.                         'routes' => [
  164.                             'route' => 'addSectionAccueil'
  165.                         ],
  166.                     ],*/
  167.                 ]
  168.             )->setLabelAttribute('icon''fas fa-ellipsis-h');
  169.             $menu->addChild(
  170.                 'menu-pages-nav-01',
  171.                 [
  172.                     'route' => 'menuList',
  173.                     'label' => 'Menu header',
  174.                     'childOptions' => $event->getChildOptions(),
  175.                     'routeParameters' => ['type' => 'header'],
  176.                 ]
  177.             )->setLabelAttribute('icon''fas fa-ellipsis-h');
  178.             $menu->addChild(
  179.                 'menu-pages-nav-02',
  180.                 [
  181.                     'route' => 'menuList',
  182.                     'label' => 'Menu footer',
  183.                     'childOptions' => $event->getChildOptions(),
  184.                     'routeParameters' => ['type' => 'footer'],
  185.                 ]
  186.             )->setLabelAttribute('icon''fas fa-ellipsis-h');
  187.             // Users
  188.             $menu->addChild(
  189.                 'menu-admin-01',
  190.                 ['label' => 'Utilisateurs''childOptions' => $event->getChildOptions()]
  191.             )->setAttribute('class''header');
  192.             $menu->addChild(
  193.                 'menu-admin-01-child',
  194.                 [
  195.                     'route' => 'adminUsersList',
  196.                     'label' => 'Liste utilisateurs',
  197.                     'childOptions' => $event->getChildOptions(),
  198.                     'extras' => [
  199.                         'routes' => [
  200.                             'route' => 'adminProfilChange'
  201.                         ],
  202.                         /*'badge' => [
  203.                             'color' => 'green',
  204.                             'value' => "ok",
  205.                         ],*/
  206.                     ],
  207.                 ]
  208.             )->setLabelAttribute('icon''fas fa-users');
  209.             // Parametres
  210.             $menu->addChild(
  211.                 'menu-supAdmin-02',
  212.                 ['label' => 'Paramètre''childOptions' => $event->getChildOptions()]
  213.             )->setAttribute('class''header');
  214.             $menu->addChild(
  215.                 'menu-supAdmin-02-child01',
  216.                 [
  217.                     'route' => 'admin_parametres_statuts',
  218.                     'label' => 'Statuts Interventions',
  219.                     'childOptions' => $event->getChildOptions(),
  220.                     'extras' => [
  221.                         'routes' => [
  222.                             'route' => 'admin_parametres_statuts_add'
  223.                         ]
  224.                     ],
  225.                 ]
  226.             )->setLabelAttribute('icon''fas fa-database');
  227.             $menu->addChild(
  228.                 'menu-supAdmin-02-child02',
  229.                 [
  230.                     'route' => 'admin_parametres_mails',
  231.                     'label' => 'Mails',
  232.                     'childOptions' => $event->getChildOptions(),
  233.                     'extras' => [
  234.                         'routes' => [
  235.                             'route' => 'admin_parametres_mails_add'
  236.                         ]
  237.                     ],
  238.                 ]
  239.             )->setLabelAttribute('icon''fa fa-envelope');
  240.             // Maintenance
  241.             $menu->addChild(
  242.                 'menu-supAdmin-01',
  243.                 ['label' => 'Maintenance''childOptions' => $event->getChildOptions()]
  244.             )->setAttribute('class''header');
  245.             $menu->addChild(
  246.                 'menu-supAdmin-01-child',
  247.                 ['route' => 'listDGSTools''label' => 'Liste outils''childOptions' => $event->getChildOptions()]
  248.             )->setLabelAttribute('icon''fas fa-cogs');
  249.             $menu->addChild(
  250.                 'menu-supAdmin-02-child',
  251.                 ['route' => 'listDGSToolsLogsRead''label' => 'Logs''childOptions' => $event->getChildOptions()]
  252.             )->setLabelAttribute('icon''fas fa-cogs');
  253.         }
  254.     }
  255. }