src/Menu/AdminMenuListener.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Menu;
  3. use App\Entity\Partner\Partner;
  4. use App\Entity\User\AdminUser;
  5. use App\RBAC\PermissionsInterface;
  6. use App\Service\SystemService;
  7. use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
  8. use Symfony\Component\DependencyInjection\ContainerInterface;
  9. final class AdminMenuListener
  10. {
  11.     protected $container;
  12.     const ROLE_PARTNER 'ROLE_PARTNER';
  13.     public function __construct(ContainerInterface $container)
  14.     {
  15.         $this->container $container;
  16.     }
  17.     public function addAdminMenuItems(MenuBuilderEvent $event): void
  18.     {
  19.         $user $this->container->get('security.token_storage')->getToken()->getUser();
  20.         $partner $partnerRole null;
  21.         $role null;
  22.         $rolesArray null;
  23.         if ($user instanceof AdminUser) {
  24.             $isPartner SystemService::isUserPartner($user);
  25.             $hasCustomRoles SystemService::isUserCustomRoles($user);
  26.             if ($isPartner) {
  27.                 $role self::ROLE_PARTNER;
  28.                 if ($partner $user->getPartner()) {
  29.                     $partnerRole $partner->getRole();
  30.                 }
  31.             } elseif ($hasCustomRoles) {
  32.                 $rolesArray $user->getCustomRoleRule()->getCustomRoleRule();
  33.             }
  34.         }
  35.         $menu $event->getMenu();
  36.         switch (true) {
  37.             case $user->hasPermission(PermissionsInterface::TYPE_RCA_PARTNER):
  38.                 $newSubmenu $menu->addChild('reports')->setLabel('Rapoarte');
  39.                 $newSubmenu->addChild('admin_report_products', ['route' => 'admin_report_products'])->setLabel('Raport produse')->setLabelAttribute('icon''list');
  40.                 $newSubmenu->addChild('admin_report_order_products', ['route' => 'admin_report_order_products'])->setLabel('Raport comenzi produse')->setLabelAttribute('icon''list');
  41.                 $menu->removeChild('bitbag_cms');
  42.                 break;
  43.             case $user->hasPermission(PermissionsInterface::TYPE_OBSIDIAN_PARTNER):
  44.                 $newSubmenu $menu->addChild('reports')->setLabel('Rapoarte');
  45.                 $newSubmenu->addChild('admin_report_products', ['route' => 'admin_report_products'])->setLabel('Raport produse')->setLabelAttribute('icon''list');
  46.                 $newSubmenu->addChild('admin_report_order_products', ['route' => 'admin_report_order_products'])->setLabel('Raport comenzi produse')->setLabelAttribute('icon''list');
  47.                 $newSubmenu $menu->addChild('death_insurance')->setLabel('Asigurare de deces');
  48.                 $newSubmenu->addChild('death_insurance', ['route' => 'app_admin_cms_death_insurance_index'])->setLabel('Asigurare de deces NN')->setLabelAttribute('icon''user');
  49.                 $menu->removeChild('bitbag_cms');
  50.                 break;
  51.             case $role === 'ROLE_PARTNER':
  52.                 if ($partnerRole->getCanIssueRoVignette()) {
  53.                     $newSubmenu $menu->addChild('ro_vignette')->setLabel('RO-viniete');
  54.                     $newSubmenu->addChild('app_admin_ro_vignette_partner_index', ['route' => 'app_admin_ro_vignette_partner_index'])->setLabel('RO-viniete')->setLabelAttribute('icon''star');
  55.                 }
  56.                 if ($partnerRole->getCanIssueHuVignette()) {
  57.                     $newSubmenu $menu->addChild('hu_vignette')->setLabel('Hu-viniete');
  58.                     $newSubmenu->addChild('hu_vignette', ['route' => 'app_admin_hu_vignette_index'])->setLabel('Hu-viniete')->setLabelAttribute('icon''taxi');
  59.                 }
  60.                 if ($partnerRole->getCanIssueRca()) {
  61.                     $newSubmenu $menu->addChild('rca')->setLabel('RCA');
  62.                     $newSubmenu->addChild('rca', ['route' => 'app_admin_cms_rca_index'])->setLabel('Comenzi RCA')->setLabelAttribute('icon''car');
  63.                     $newSubmenu->addChild('rca_emise', ['route' => 'app_admin_cms_issued_rca_index'])->setLabel('RCA Emise')->setLabelAttribute('icon''star');
  64.                     $newSubmenu->addChild('broker-rca-commissions', ['route' => 'app_admin_broker_rca_commissions''routeParameters' => ['type' => 'rcaCommissions']])->setLabel('Comisioane Asiguratori RCA')->setLabelAttribute('icon''file outline alternate');
  65.                     if ($partner->hasFlag(Partner::FLAG_HAS_EVIGNETTE_ACCOUNT)) {
  66.                         $newSubmenu->addChild(
  67.                             'app_admin_partner_qr_rca',
  68.                             [
  69.                                 'route' => 'app_admin_partner_qr',
  70.                                 'routeParameters' => [
  71.                                     'type' => 'rca',
  72.                                     'id' => $user->getPartner()->getId()
  73.                                 ]
  74.                             ]
  75.                         )->setLabel('Cod QR RCA')->setLabelAttribute('icon''qrcode');
  76.                     } else {
  77.                         $newSubmenu->addChild('iframe-documentation', ['route' => 'app_admin_iframe_documentation''routeParameters' => ['type' => 'iframe']])->setLabel('Documentatie IFRAME')->setLabelAttribute('icon''file outline alternate');
  78.                         if ($partner->getRole()->getCanIssueRca()) {
  79.                             $newSubmenu->addChild(
  80.                                 'app_admin_partner_qr_rca',
  81.                                 [
  82.                                     'route' => 'app_admin_partner_qr',
  83.                                     'routeParameters' => [
  84.                                         'type' => 'rca',
  85.                                         'id' => $user->getPartner()->getId()
  86.                                     ]
  87.                                 ]
  88.                             )->setLabel('Cod QR RCA')->setLabelAttribute('icon''qrcode');
  89.                         }
  90.                         if ($partner->getRole()->getCanIssueRoVignette()) {
  91.                             $newSubmenu->addChild(
  92.                                 'app_admin_partner_qr_roviniete',
  93.                                 [
  94.                                     'route' => 'app_admin_partner_qr',
  95.                                     'routeParameters' => [
  96.                                         'type' => 'roviniete',
  97.                                         'id' => $user->getPartner()->getId()
  98.                                     ]
  99.                                 ]
  100.                             )->setLabel('Cod QR RoViniete')->setLabelAttribute('icon''qrcode');
  101.                         }
  102.                         if ($partner->getRole()->getCanIssueHuVignette()) {
  103.                             $newSubmenu->addChild(
  104.                                 'app_admin_partner_qr_huviniete',
  105.                                 [
  106.                                     'route' => 'app_admin_partner_qr',
  107.                                     'routeParameters' => [
  108.                                         'type' => 'huviniete',
  109.                                         'id' => $user->getPartner()->getId()
  110.                                     ]
  111.                                 ]
  112.                             )->setLabel('Cod QR HuViniete')->setLabelAttribute('icon''qrcode');
  113.                         }
  114.                     }
  115.                 }
  116.                 if ($partnerRole->getCanIssueRoadAssistance()) {
  117.                     $newSubmenu $menu->addChild('road_assistance')->setLabel('Asistenta Rutiera');
  118.                     $newSubmenu->addChild('app_admin_cms_road_assistance_index', ['route' => 'app_admin_cms_road_assistance_index'])->setLabel('Asistenta Rutiera')->setLabelAttribute('icon''star');
  119.                 }
  120.                 if ($partnerRole->getCanIssueDeathInsurance()) {
  121.                     $newSubmenu $menu->addChild('death_insurance')->setLabel('Asigurare sofer NN');
  122.                     $newSubmenu->addChild('death_insurance', ['route' => 'app_admin_cms_death_insurance_index'])->setLabel('Asigurare sofer NN')->setLabelAttribute('icon''user');
  123.                 }
  124.                 if ($partnerRole->getCanIssueLicenseRecovery()) {
  125.                     $newSubmenu $menu->addChild('license_recovery')->setLabel('Recuperare Permis');
  126.                     $newSubmenu->addChild('license_recovery', ['route' => 'app_admin_license_recovery_index'])->setLabel('Recuperare Permis')->setLabelAttribute('icon''cart');
  127.                 }
  128.                 if ($partnerRole->getCanIssueTelemedicine()) {
  129.                     $newSubmenu $menu->addChild('telemedicine')->setLabel('Telemedicină');
  130.                     $newSubmenu->addChild('telemedicine', ['route' => 'app_admin_cms_telemedicine_index'])->setLabel('Comenzi Telemedicină')->setLabelAttribute('icon''user');
  131.                 }
  132.                 if ($partnerRole->getCanIssuePeaj()) {
  133.                     $newSubmenu $menu->addChild('peaj')->setLabel('PEAJ');
  134.                     $newSubmenu->addChild('peaj', ['route' => 'app_admin_peaj_index'])->setLabel('PEAJ')->setLabelAttribute('icon''taxi');
  135.                 }
  136.                 $newSubmenu $menu->addChild('reports')->setLabel('Rapoarte');
  137.                 $newSubmenu->addChild('admin_report_products', ['route' => 'admin_report_products'])->setLabel('Raport produse')->setLabelAttribute('icon''list');
  138.                 $newSubmenu->addChild('admin_report_order_products', ['route' => 'admin_report_order_products'])->setLabel('Raport comenzi produse')->setLabelAttribute('icon''list');
  139.                 $newSubmenu $menu->addChild('administration')->setLabel('Administrare');
  140.                 $newSubmenu->addChild('app_admin_order_partner_index', ['route' => 'app_admin_order_partner_index'])
  141.                     ->setLabel('Comenzi')->setLabelAttribute('icon''star');
  142.                 $menu->removeChild('bitbag_cms');
  143.                 break;
  144.             default:
  145.                 $newSubmenu $menu->addChild('ro_vignette')->setLabel('RO-viniete');
  146.                 $newSubmenu->addChild('vignette', ['route' => 'app_admin_vignette_index'])->setLabel('RO-viniete')->setLabelAttribute('icon''star');
  147.                 $newSubmenu->addChild('vignette_alerts', ['route' => 'app_admin_vignette_alerts_index'])->setLabel('Vignette Alerts')->setLabelAttribute('icon''envelope');
  148.                 $newSubmenu->addChild('failed_vignettes', ['route' => 'app_admin_failed_vignette_index'])->setLabel('CRON - Viniete esuate')->setLabelAttribute('icon''car');
  149.                 $newSubmenu $menu->addChild('hu_vignette')->setLabel('Hu-viniete');
  150.                 $newSubmenu->addChild('hu_vignette', ['route' => 'app_admin_hu_vignette_index'])->setLabel('Hu-viniete')->setLabelAttribute('icon''taxi');
  151.                 $newSubmenu->addChild('failed_hu_vignettes', ['route' => 'app_admin_failed_hu_vignette_index'])->setLabel('CRON - Hu-Viniete esuate')->setLabelAttribute('icon''taxi');
  152.                 $newSubmenu $menu->addChild('rca')->setLabel('RCA');
  153.                 $newSubmenu->addChild('rca', ['route' => 'app_admin_cms_rca_index'])->setLabel('Comenzi RCA')->setLabelAttribute('icon''car');
  154.                 $newSubmenu->addChild('rca_emise', ['route' => 'app_admin_cms_issued_rca_index'])->setLabel('RCA Emise')->setLabelAttribute('icon''star');
  155.                 $newSubmenu->addChild('rca_alerts', ['route' => 'app_admin_rca_alerts_index'])->setLabel('RCA Alerts')->setLabelAttribute('icon''envelope');
  156.                 $newSubmenu->addChild('rca_api', ['route' => 'app_admin_rca_api_index'])->setLabel('API RCA 24 BROKER')->setLabelAttribute('icon''car');
  157.                 $newSubmenu->addChild('rca_expirari_manuale', ['route' => 'app_admin_rca_manual_expire_notification_index'])->setLabel('RCA Expirari Manuale')->setLabelAttribute('icon''star');
  158.                 $newSubmenu->addChild('log_rca_erori_oferte', ['route' => 'app_admin_log_rca_offer_index'])->setLabel('Log RCA Erori oferte')->setLabelAttribute('icon''warning');
  159.                 $newSubmenu->addChild('log_rca_erori_oferte_prelucrat', ['route' => 'app_admin_log_processed_offer_index'])->setLabel('Log oferte RCA (prelucrat)')->setLabelAttribute('icon''warning');
  160.                 $newSubmenu->addChild('failed_rca_show', ['route' => 'app_admin_failed_rca_show'])->setLabel('RCA Esuat')->setLabelAttribute('icon''sync');
  161.                 $newSubmenu->addChild('failed_cms_rca', ['route' => 'app_admin_failed_rca_index'])->setLabel('CRON - RCA esuate')->setLabelAttribute('icon''car');
  162.                 $newSubmenu->addChild('status_companii_asigurari', ['route' => 'app_admin_insurance_companies'])->setLabel('Status Companii Asigurari')->setLabelAttribute('icon''star');
  163.                 $newSubmenu->addChild('statistica_ocr', ['route' => 'app_admin_identity_card_show'])->setLabel('Statistica OCR')->setLabelAttribute('icon''chart line');
  164.                 $newSubmenu->addChild('app_admin_failed_road_assistance_index', ['route' => 'app_admin_failed_road_assistance_index'])->setLabel('CRON - Asisenta Ruitera esuat')->setLabelAttribute('icon''taxi');
  165.                 $newSubmenu->addChild('broker-rca-commissions', ['route' => 'app_admin_broker_rca_commissions''routeParameters' => ['type' => 'rcaCommissions']])->setLabel('Comisioane Asiguratori RCA')->setLabelAttribute('icon''file outline alternate');
  166.                 $newSubmenu->addChild('iframe-documentation', ['route' => 'app_admin_iframe_documentation''routeParameters' => ['type' => 'iframe']])->setLabel('Documentatie IFRAME')->setLabelAttribute('icon''file outline alternate');
  167.                 $newSubmenu $menu->addChild('road_assistance')->setLabel('Asistenta Rutiera');
  168.                 $newSubmenu->addChild('road_assistance', ['route' => 'app_admin_cms_road_assistance_index'])->setLabel('Asistenta Rutiera')->setLabelAttribute('icon''star');
  169.                 $newSubmenu->addChild('cron_asistenta_rutiera_esuat', ['route' => 'app_admin_failed_road_assistance_index'])->setLabel('CRON - Asisenta Ruitera esuat')->setLabelAttribute('icon''taxi');
  170.                 $newSubmenu $menu->addChild('license_recovery')->setLabel('Recuperare Permis');
  171.                 $newSubmenu->addChild('license_recovery', ['route' => 'app_admin_license_recovery_index'])->setLabel('Comenzi Recuperare Permis')->setLabelAttribute('icon''cart');
  172.                 $newSubmenu $menu->addChild('telemedicine')->setLabel('Telemedicină');
  173.                 $newSubmenu->addChild('telemedicine', ['route' => 'app_admin_cms_telemedicine_index'])->setLabel('Comenzi Telemedicină')->setLabelAttribute('icon''cart');
  174.                 $newSubmenu->addChild('tele_doc', ['route' => 'app_admin_tele_doc_list'])->setLabel('Coduri TeleDoc')->setLabelAttribute('icon''archive');
  175.                 $newSubmenu $menu->addChild('death_insurance')->setLabel('Asigurare de deces');
  176.                 $newSubmenu->addChild('death_insurance', ['route' => 'app_admin_cms_death_insurance_index'])->setLabel('Asigurare de deces NN')->setLabelAttribute('icon''user');
  177.                 $newSubmenu->addChild('death_insurance_issue_data', ['route' => 'app_admin_cms_death_insurance_issue_data'])->setLabel('Date emitere asigurare NN')->setLabelAttribute('icon''file alternate');
  178.                 $newSubmenu $menu->addChild('donation')->setLabel('Doneaza');
  179.                 $newSubmenu->addChild('donation', ['route' => 'app_admin_cms_donation_index'])->setLabel('Comenzi doneaza')->setLabelAttribute('icon''handshake');
  180.                 $newSubmenu $menu->addChild('peaj')->setLabel('PEAJ');
  181.                 $newSubmenu->addChild('peaj', ['route' => 'app_admin_peaj_index'])->setLabel('PEAJ')->setLabelAttribute('icon''taxi');
  182.                 $newSubmenu->addChild('failed_peaj', ['route' => 'app_admin_failed_peaj_index'])->setLabel('CRON - PEAJ esuate')->setLabelAttribute('icon''taxi');
  183.                 $newSubmenu $menu->addChild('administration')->setLabel('Administrare');
  184.                 $newSubmenu->addChild('vignette_invoices', ['route' => 'app_admin_vignette_invoice_index'])->setLabel('Facturi Fiscale')->setLabelAttribute('icon''file outline alternate');
  185.                 $newSubmenu->addChild('proforma_invoices', ['route' => 'app_admin_proforma_invoice_index'])->setLabel('Facturi Proforme')->setLabelAttribute('icon''file alternate');
  186.                 $newSubmenu->addChild('invoice_classification', ['route' => 'app_admin_invoice_classification_index'])->setLabel('Facturi API KEYS')->setLabelAttribute('icon''archive');
  187.                 $newSubmenu->addChild('sms', ['route' => 'app_admin_sms_index'])->setLabel('SMS')->setLabelAttribute('icon''envelope outline');
  188.                 $newSubmenu->addChild('app_admin_short_url_index', ['route' => 'app_admin_short_url_index'])->setLabel('Short URLs')->setLabelAttribute('icon''star');
  189.                 $newSubmenu->addChild('app_admin_view_exports', ['route' => 'app_admin_view_exports'])->setLabel('Vizualizare Exporturi')->setLabelAttribute('icon''download');
  190.                 $newSubmenu->addChild('users_roles', ['route' => 'app_admin_view_exports'])->setLabel('Roluri Useri')->setLabelAttribute('icon''users');
  191.                 $newSubmenu $menu->addChild('options')->setLabel('Options');
  192.                 $newSubmenu->addChild('vignette_general_options', ['route' => 'app_admin_vignette_general_option_index'])->setLabel('General options')->setLabelAttribute('icon''options');
  193.                 $newSubmenu->addChild('vignette_alert_templates', ['route' => 'app_admin_vignette_alert_template_index'])->setLabel('Alert templates')->setLabelAttribute('icon''bell');
  194.                 $newSubmenu->addChild('vignette_maintenances', ['route' => 'app_admin_vignette_maintenance_index'])->setLabel('Maintenance')->setLabelAttribute('icon''cog');
  195.                 $newSubmenu->addChild('onesignal', ['route' => 'app_admin_onesignal_index'])->setLabel('Onesignal')->setLabelAttribute('icon''signal');
  196.                 $newSubmenu->addChild('alert_classification', ['route' => 'app_admin_alert_classification_index'])->setLabel('Alert Classification')->setLabelAttribute('icon''envelope');
  197.                 $newSubmenu->addChild('templates', ['route' => 'app_admin_template_index'])->setLabel('Templates')->setLabelAttribute('icon''edit');
  198.                 $subMenu $menu->getChild('catalog')->setLabel('Sylius Administration');
  199.                 $subMenu->removeChild('inventory');
  200.                 $subMenu $menu->getChild('sales');
  201.                 $subMenu->removeChild('payments');
  202.                 $subMenu $menu->getChild('configuration');
  203.                 $subMenu->addChild('app_admin_product_status', ['route' => 'app_admin_product_status'])->setLabel('Status Produse')->setLabelAttribute('icon''star');
  204.                 $subMenu->addChild('app_admin_template_status', ['route' => 'app_admin_template_status'])->setLabel('Status Template')->setLabelAttribute('icon''handshake');
  205.                 $subMenu->addChild('app_admin_campaign_status', ['route' => 'app_admin_campaign_status'])->setLabel('Status Campanii')->setLabelAttribute('icon''handshake');
  206.                 $subMenu->addChild('app_admin_payment_status', ['route' => 'app_admin_payment_status'])->setLabel('Status Metode de plata')->setLabelAttribute('icon''cart');
  207.                 $subMenu->addChild('app_admin_messages_translate_index', ['route' => 'app_admin_messages_translate_index'])->setLabel('Messages Translate')->setLabelAttribute('icon''language');
  208.                 $subMenu->removeChild('channels');
  209.                 $subMenu->removeChild('zones');
  210.                 $subMenu->removeChild('currencies');
  211.                 $subMenu->removeChild('exchange_rates');
  212.                 $subMenu->removeChild('payment_methods');
  213.                 $subMenu->removeChild('tax_categories');
  214.                 $subMenu->removeChild('tax_rates');
  215.                 $subMenu->removeChild('shipping_categories');
  216.                 $subMenu $menu->getChild('customers');
  217.                 $subMenu->addChild('customer_list', ['route' => 'app_admin_customer_list_index'])->setLabel('Lista Clienti')->setLabelAttribute('icon''list');
  218.                 $subMenu->addChild('app_admin_customer_commercial_template_index', ['route' => 'app_admin_customer_commercial_template_index'])->setLabel('Template-uri Commerciale')->setLabelAttribute('icon''star');
  219.                 $subMenu->addChild('app_admin_customer_log_customer_notification_index', ['route' => 'app_admin_customer_log_customer_notification_index'])->setLabel('Istoric Notificari Clienti')->setLabelAttribute('icon''history');
  220.                 $subMenu->addChild('app_admin_customer_commercial_notification', ['route' => 'app_admin_customer_commercial_notification'])->setLabel('Acord Comercial')->setLabelAttribute('icon''handshake');
  221.                 $subMenu->addChild('app_admin_customer_tracker_activity', ['route' => 'app_admin_customer_tracker_activity'])->setLabel('Tracker Clienti')->setLabelAttribute('icon''eye');
  222.                 $subMenu->removeChild('groups');
  223.                 $subMenu $menu->getChild('sales');
  224.                 $subMenu->addChild('custom_orders', ['route' => 'app_admin_export_order_by_sms_view'])->setLabel('Export Comenzi SMS')->setLabelAttribute('icon''download');
  225.                 $subMenu->addChild('admin_report_products', ['route' => 'admin_report_products'])->setLabel('Raport produse')->setLabelAttribute('icon''list');
  226.                 $subMenu->addChild('admin_report_order_products', ['route' => 'admin_report_order_products'])->setLabel('Raport comenzi produse')->setLabelAttribute('icon''list');
  227.                 $subMenu->addChild('admin_report_order_products_logs', ['route' => 'admin_report_order_products_logs'])->setLabel('Loguri import confirmare incasare')->setLabelAttribute('icon''list');
  228.                 $menu->removeChild('marketing');
  229.                 $newSubmenu $menu->addChild('vehicles')->setLabel('Vehicule');
  230.                 $newSubmenu->addChild('app_admin_export_vehicles', ['route' => 'app_admin_export_vehicles'])->setLabel('Export Vehicule')->setLabelAttribute('icon''download');
  231.                 $newSubmenu $menu->addChild('partner')->setLabel('Parteneri');
  232.                 $newSubmenu->addChild('partners', ['route' => 'app_admin_partner_index'])->setLabel('Parteneri')->setLabelAttribute('icon''handshake');
  233.                 $newSubmenu->addChild('partners_roles', ['route' => 'app_admin_partner_role_index'])->setLabel('Roluri')->setLabelAttribute('icon''user');
  234.                 $menu->reorderChildren(array(
  235.                     => 'ro_vignette',
  236.                     => 'hu_vignette',
  237.                     => 'rca',
  238.                     => 'road_assistance',
  239.                     => 'license_recovery',
  240.                     => 'telemedicine',
  241.                     => 'death_insurance',
  242.                     => 'donation',
  243.                     => 'peaj',
  244.                     10 => 'partner',
  245.                     11 => 'administration',
  246.                     12 => 'sales',
  247.                     13 => 'vehicles',
  248.                     14 => 'customers',
  249.                     15 => 'options',
  250.                     16 => 'configuration',
  251.                     17 => 'bitbag_cms',
  252.                     18 => 'catalog',
  253.                 ));
  254.                 break;
  255.         }
  256.         if ($rolesArray) {
  257.             foreach ($menu as $subMenu) {
  258.                 if (!in_array($subMenu->getName(), $rolesArray)) {
  259.                     $menu->removeChild($subMenu->getName());
  260.                 }
  261.                 foreach ($subMenu as $child) {
  262.                     if (!in_array($child->getName(), $rolesArray)) {
  263.                         $subMenu->removeChild($child->getName());
  264.                     }
  265.                 }
  266.             }
  267.         }
  268.     }
  269. }