<?php
namespace App\Menu;
use App\Entity\Partner\Partner;
use App\Entity\User\AdminUser;
use App\RBAC\PermissionsInterface;
use App\Service\SystemService;
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class AdminMenuListener
{
protected $container;
const ROLE_PARTNER = 'ROLE_PARTNER';
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function addAdminMenuItems(MenuBuilderEvent $event): void
{
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$partner = $partnerRole = null;
$role = null;
$rolesArray = null;
if ($user instanceof AdminUser) {
$isPartner = SystemService::isUserPartner($user);
$hasCustomRoles = SystemService::isUserCustomRoles($user);
if ($isPartner) {
$role = self::ROLE_PARTNER;
if ($partner = $user->getPartner()) {
$partnerRole = $partner->getRole();
}
} elseif ($hasCustomRoles) {
$rolesArray = $user->getCustomRoleRule()->getCustomRoleRule();
}
}
$menu = $event->getMenu();
switch (true) {
case $user->hasPermission(PermissionsInterface::TYPE_RCA_PARTNER):
$newSubmenu = $menu->addChild('reports')->setLabel('Rapoarte');
$newSubmenu->addChild('admin_report_products', ['route' => 'admin_report_products'])->setLabel('Raport produse')->setLabelAttribute('icon', 'list');
$newSubmenu->addChild('admin_report_order_products', ['route' => 'admin_report_order_products'])->setLabel('Raport comenzi produse')->setLabelAttribute('icon', 'list');
$menu->removeChild('bitbag_cms');
break;
case $user->hasPermission(PermissionsInterface::TYPE_OBSIDIAN_PARTNER):
$newSubmenu = $menu->addChild('reports')->setLabel('Rapoarte');
$newSubmenu->addChild('admin_report_products', ['route' => 'admin_report_products'])->setLabel('Raport produse')->setLabelAttribute('icon', 'list');
$newSubmenu->addChild('admin_report_order_products', ['route' => 'admin_report_order_products'])->setLabel('Raport comenzi produse')->setLabelAttribute('icon', 'list');
$newSubmenu = $menu->addChild('death_insurance')->setLabel('Asigurare de deces');
$newSubmenu->addChild('death_insurance', ['route' => 'app_admin_cms_death_insurance_index'])->setLabel('Asigurare de deces NN')->setLabelAttribute('icon', 'user');
$menu->removeChild('bitbag_cms');
break;
case $role === 'ROLE_PARTNER':
if ($partnerRole->getCanIssueRoVignette()) {
$newSubmenu = $menu->addChild('ro_vignette')->setLabel('RO-viniete');
$newSubmenu->addChild('app_admin_ro_vignette_partner_index', ['route' => 'app_admin_ro_vignette_partner_index'])->setLabel('RO-viniete')->setLabelAttribute('icon', 'star');
}
if ($partnerRole->getCanIssueHuVignette()) {
$newSubmenu = $menu->addChild('hu_vignette')->setLabel('Hu-viniete');
$newSubmenu->addChild('hu_vignette', ['route' => 'app_admin_hu_vignette_index'])->setLabel('Hu-viniete')->setLabelAttribute('icon', 'taxi');
}
if ($partnerRole->getCanIssueRca()) {
$newSubmenu = $menu->addChild('rca')->setLabel('RCA');
$newSubmenu->addChild('rca', ['route' => 'app_admin_cms_rca_index'])->setLabel('Comenzi RCA')->setLabelAttribute('icon', 'car');
$newSubmenu->addChild('rca_emise', ['route' => 'app_admin_cms_issued_rca_index'])->setLabel('RCA Emise')->setLabelAttribute('icon', 'star');
$newSubmenu->addChild('broker-rca-commissions', ['route' => 'app_admin_broker_rca_commissions', 'routeParameters' => ['type' => 'rcaCommissions']])->setLabel('Comisioane Asiguratori RCA')->setLabelAttribute('icon', 'file outline alternate');
if ($partner->hasFlag(Partner::FLAG_HAS_EVIGNETTE_ACCOUNT)) {
$newSubmenu->addChild(
'app_admin_partner_qr_rca',
[
'route' => 'app_admin_partner_qr',
'routeParameters' => [
'type' => 'rca',
'id' => $user->getPartner()->getId()
]
]
)->setLabel('Cod QR RCA')->setLabelAttribute('icon', 'qrcode');
} else {
$newSubmenu->addChild('iframe-documentation', ['route' => 'app_admin_iframe_documentation', 'routeParameters' => ['type' => 'iframe']])->setLabel('Documentatie IFRAME')->setLabelAttribute('icon', 'file outline alternate');
if ($partner->getRole()->getCanIssueRca()) {
$newSubmenu->addChild(
'app_admin_partner_qr_rca',
[
'route' => 'app_admin_partner_qr',
'routeParameters' => [
'type' => 'rca',
'id' => $user->getPartner()->getId()
]
]
)->setLabel('Cod QR RCA')->setLabelAttribute('icon', 'qrcode');
}
if ($partner->getRole()->getCanIssueRoVignette()) {
$newSubmenu->addChild(
'app_admin_partner_qr_roviniete',
[
'route' => 'app_admin_partner_qr',
'routeParameters' => [
'type' => 'roviniete',
'id' => $user->getPartner()->getId()
]
]
)->setLabel('Cod QR RoViniete')->setLabelAttribute('icon', 'qrcode');
}
if ($partner->getRole()->getCanIssueHuVignette()) {
$newSubmenu->addChild(
'app_admin_partner_qr_huviniete',
[
'route' => 'app_admin_partner_qr',
'routeParameters' => [
'type' => 'huviniete',
'id' => $user->getPartner()->getId()
]
]
)->setLabel('Cod QR HuViniete')->setLabelAttribute('icon', 'qrcode');
}
}
}
if ($partnerRole->getCanIssueRoadAssistance()) {
$newSubmenu = $menu->addChild('road_assistance')->setLabel('Asistenta Rutiera');
$newSubmenu->addChild('app_admin_cms_road_assistance_index', ['route' => 'app_admin_cms_road_assistance_index'])->setLabel('Asistenta Rutiera')->setLabelAttribute('icon', 'star');
}
if ($partnerRole->getCanIssueDeathInsurance()) {
$newSubmenu = $menu->addChild('death_insurance')->setLabel('Asigurare sofer NN');
$newSubmenu->addChild('death_insurance', ['route' => 'app_admin_cms_death_insurance_index'])->setLabel('Asigurare sofer NN')->setLabelAttribute('icon', 'user');
}
if ($partnerRole->getCanIssueLicenseRecovery()) {
$newSubmenu = $menu->addChild('license_recovery')->setLabel('Recuperare Permis');
$newSubmenu->addChild('license_recovery', ['route' => 'app_admin_license_recovery_index'])->setLabel('Recuperare Permis')->setLabelAttribute('icon', 'cart');
}
if ($partnerRole->getCanIssueTelemedicine()) {
$newSubmenu = $menu->addChild('telemedicine')->setLabel('Telemedicină');
$newSubmenu->addChild('telemedicine', ['route' => 'app_admin_cms_telemedicine_index'])->setLabel('Comenzi Telemedicină')->setLabelAttribute('icon', 'user');
}
$newSubmenu = $menu->addChild('reports')->setLabel('Rapoarte');
$newSubmenu->addChild('admin_report_products', ['route' => 'admin_report_products'])->setLabel('Raport produse')->setLabelAttribute('icon', 'list');
$newSubmenu->addChild('admin_report_order_products', ['route' => 'admin_report_order_products'])->setLabel('Raport comenzi produse')->setLabelAttribute('icon', 'list');
$newSubmenu = $menu->addChild('administration')->setLabel('Administrare');
$newSubmenu->addChild('app_admin_order_partner_index', ['route' => 'app_admin_order_partner_index'])
->setLabel('Comenzi')->setLabelAttribute('icon', 'star');
$menu->removeChild('bitbag_cms');
break;
default:
$newSubmenu = $menu->addChild('ro_vignette')->setLabel('RO-viniete');
$newSubmenu->addChild('vignette', ['route' => 'app_admin_vignette_index'])->setLabel('RO-viniete')->setLabelAttribute('icon', 'star');
$newSubmenu->addChild('vignette_alerts', ['route' => 'app_admin_vignette_alerts_index'])->setLabel('Vignette Alerts')->setLabelAttribute('icon', 'envelope');
$newSubmenu->addChild('failed_vignettes', ['route' => 'app_admin_failed_vignette_index'])->setLabel('CRON - Viniete esuate')->setLabelAttribute('icon', 'car');
$newSubmenu = $menu->addChild('hu_vignette')->setLabel('Hu-viniete');
$newSubmenu->addChild('hu_vignette', ['route' => 'app_admin_hu_vignette_index'])->setLabel('Hu-viniete')->setLabelAttribute('icon', 'taxi');
$newSubmenu->addChild('failed_hu_vignettes', ['route' => 'app_admin_failed_hu_vignette_index'])->setLabel('CRON - Hu-Viniete esuate')->setLabelAttribute('icon', 'taxi');
$newSubmenu = $menu->addChild('rca')->setLabel('RCA');
$newSubmenu->addChild('rca', ['route' => 'app_admin_cms_rca_index'])->setLabel('Comenzi RCA')->setLabelAttribute('icon', 'car');
$newSubmenu->addChild('rca_emise', ['route' => 'app_admin_cms_issued_rca_index'])->setLabel('RCA Emise')->setLabelAttribute('icon', 'star');
$newSubmenu->addChild('rca_alerts', ['route' => 'app_admin_rca_alerts_index'])->setLabel('RCA Alerts')->setLabelAttribute('icon', 'envelope');
$newSubmenu->addChild('rca_api', ['route' => 'app_admin_rca_api_index'])->setLabel('API RCA 24 BROKER')->setLabelAttribute('icon', 'car');
$newSubmenu->addChild('rca_expirari_manuale', ['route' => 'app_admin_rca_manual_expire_notification_index'])->setLabel('RCA Expirari Manuale')->setLabelAttribute('icon', 'star');
$newSubmenu->addChild('log_rca_erori_oferte', ['route' => 'app_admin_log_rca_offer_index'])->setLabel('Log RCA Erori oferte')->setLabelAttribute('icon', 'warning');
$newSubmenu->addChild('log_rca_erori_oferte_prelucrat', ['route' => 'app_admin_log_processed_offer_index'])->setLabel('Log oferte RCA (prelucrat)')->setLabelAttribute('icon', 'warning');
$newSubmenu->addChild('failed_rca_show', ['route' => 'app_admin_failed_rca_show'])->setLabel('RCA Esuat')->setLabelAttribute('icon', 'sync');
$newSubmenu->addChild('failed_cms_rca', ['route' => 'app_admin_failed_rca_index'])->setLabel('CRON - RCA esuate')->setLabelAttribute('icon', 'car');
$newSubmenu->addChild('status_companii_asigurari', ['route' => 'app_admin_insurance_companies'])->setLabel('Status Companii Asigurari')->setLabelAttribute('icon', 'star');
$newSubmenu->addChild('statistica_ocr', ['route' => 'app_admin_identity_card_show'])->setLabel('Statistica OCR')->setLabelAttribute('icon', 'chart line');
$newSubmenu->addChild('app_admin_failed_road_assistance_index', ['route' => 'app_admin_failed_road_assistance_index'])->setLabel('CRON - Asisenta Ruitera esuat')->setLabelAttribute('icon', 'taxi');
$newSubmenu->addChild('broker-rca-commissions', ['route' => 'app_admin_broker_rca_commissions', 'routeParameters' => ['type' => 'rcaCommissions']])->setLabel('Comisioane Asiguratori RCA')->setLabelAttribute('icon', 'file outline alternate');
$newSubmenu->addChild('iframe-documentation', ['route' => 'app_admin_iframe_documentation', 'routeParameters' => ['type' => 'iframe']])->setLabel('Documentatie IFRAME')->setLabelAttribute('icon', 'file outline alternate');
$newSubmenu = $menu->addChild('road_assistance')->setLabel('Asistenta Rutiera');
$newSubmenu->addChild('road_assistance', ['route' => 'app_admin_cms_road_assistance_index'])->setLabel('Asistenta Rutiera')->setLabelAttribute('icon', 'star');
$newSubmenu->addChild('cron_asistenta_rutiera_esuat', ['route' => 'app_admin_failed_road_assistance_index'])->setLabel('CRON - Asisenta Ruitera esuat')->setLabelAttribute('icon', 'taxi');
$newSubmenu = $menu->addChild('license_recovery')->setLabel('Recuperare Permis');
$newSubmenu->addChild('license_recovery', ['route' => 'app_admin_license_recovery_index'])->setLabel('Comenzi Recuperare Permis')->setLabelAttribute('icon', 'cart');
$newSubmenu = $menu->addChild('telemedicine')->setLabel('Telemedicină');
$newSubmenu->addChild('telemedicine', ['route' => 'app_admin_cms_telemedicine_index'])->setLabel('Comenzi Telemedicină')->setLabelAttribute('icon', 'cart');
$newSubmenu->addChild('tele_doc', ['route' => 'app_admin_tele_doc_list'])->setLabel('Coduri TeleDoc')->setLabelAttribute('icon', 'archive');
$newSubmenu = $menu->addChild('death_insurance')->setLabel('Asigurare de deces');
$newSubmenu->addChild('death_insurance', ['route' => 'app_admin_cms_death_insurance_index'])->setLabel('Asigurare de deces NN')->setLabelAttribute('icon', 'user');
$newSubmenu->addChild('death_insurance_issue_data', ['route' => 'app_admin_cms_death_insurance_issue_data'])->setLabel('Date emitere asigurare NN')->setLabelAttribute('icon', 'file alternate');
$newSubmenu = $menu->addChild('administration')->setLabel('Administrare');
$newSubmenu->addChild('vignette_invoices', ['route' => 'app_admin_vignette_invoice_index'])->setLabel('Facturi Fiscale')->setLabelAttribute('icon', 'file outline alternate');
$newSubmenu->addChild('proforma_invoices', ['route' => 'app_admin_proforma_invoice_index'])->setLabel('Facturi Proforme')->setLabelAttribute('icon', 'file alternate');
$newSubmenu->addChild('invoice_classification', ['route' => 'app_admin_invoice_classification_index'])->setLabel('Facturi API KEYS')->setLabelAttribute('icon', 'archive');
$newSubmenu->addChild('sms', ['route' => 'app_admin_sms_index'])->setLabel('SMS')->setLabelAttribute('icon', 'envelope outline');
$newSubmenu->addChild('app_admin_short_url_index', ['route' => 'app_admin_short_url_index'])->setLabel('Short URLs')->setLabelAttribute('icon', 'star');
$newSubmenu->addChild('app_admin_view_exports', ['route' => 'app_admin_view_exports'])->setLabel('Vizualizare Exporturi')->setLabelAttribute('icon', 'download');
$newSubmenu->addChild('users_roles', ['route' => 'app_admin_view_exports'])->setLabel('Roluri Useri')->setLabelAttribute('icon', 'users');
$newSubmenu = $menu->addChild('options')->setLabel('Options');
$newSubmenu->addChild('vignette_general_options', ['route' => 'app_admin_vignette_general_option_index'])->setLabel('General options')->setLabelAttribute('icon', 'options');
$newSubmenu->addChild('vignette_alert_templates', ['route' => 'app_admin_vignette_alert_template_index'])->setLabel('Alert templates')->setLabelAttribute('icon', 'bell');
$newSubmenu->addChild('vignette_maintenances', ['route' => 'app_admin_vignette_maintenance_index'])->setLabel('Maintenance')->setLabelAttribute('icon', 'cog');
$newSubmenu->addChild('onesignal', ['route' => 'app_admin_onesignal_index'])->setLabel('Onesignal')->setLabelAttribute('icon', 'signal');
$newSubmenu->addChild('alert_classification', ['route' => 'app_admin_alert_classification_index'])->setLabel('Alert Classification')->setLabelAttribute('icon', 'envelope');
$newSubmenu->addChild('templates', ['route' => 'app_admin_template_index'])->setLabel('Templates')->setLabelAttribute('icon', 'edit');
$subMenu = $menu->getChild('catalog')->setLabel('Sylius Administration');
$subMenu->removeChild('inventory');
$subMenu = $menu->getChild('sales');
$subMenu->removeChild('payments');
$subMenu = $menu->getChild('configuration');
$subMenu->addChild('app_admin_product_status', ['route' => 'app_admin_product_status'])->setLabel('Status Produse')->setLabelAttribute('icon', 'star');
$subMenu->addChild('app_admin_template_status', ['route' => 'app_admin_template_status'])->setLabel('Status Template')->setLabelAttribute('icon', 'handshake');
$subMenu->addChild('app_admin_campaign_status', ['route' => 'app_admin_campaign_status'])->setLabel('Status Campanii')->setLabelAttribute('icon', 'handshake');
$subMenu->addChild('app_admin_payment_status', ['route' => 'app_admin_payment_status'])->setLabel('Status Metode de plata')->setLabelAttribute('icon', 'cart');
$subMenu->addChild('app_admin_messages_translate_index', ['route' => 'app_admin_messages_translate_index'])->setLabel('Messages Translate')->setLabelAttribute('icon', 'language');
$subMenu->removeChild('channels');
$subMenu->removeChild('zones');
$subMenu->removeChild('currencies');
$subMenu->removeChild('exchange_rates');
$subMenu->removeChild('payment_methods');
$subMenu->removeChild('tax_categories');
$subMenu->removeChild('tax_rates');
$subMenu->removeChild('shipping_categories');
$subMenu = $menu->getChild('customers');
$subMenu->addChild('customer_list', ['route' => 'app_admin_customer_list_index'])->setLabel('Lista Clienti')->setLabelAttribute('icon', 'list');
$subMenu->addChild('app_admin_customer_commercial_template_index', ['route' => 'app_admin_customer_commercial_template_index'])->setLabel('Template-uri Commerciale')->setLabelAttribute('icon', 'star');
$subMenu->addChild('app_admin_customer_log_customer_notification_index', ['route' => 'app_admin_customer_log_customer_notification_index'])->setLabel('Istoric Notificari Clienti')->setLabelAttribute('icon', 'history');
$subMenu->addChild('app_admin_customer_commercial_notification', ['route' => 'app_admin_customer_commercial_notification'])->setLabel('Acord Comercial')->setLabelAttribute('icon', 'handshake');
$subMenu->addChild('app_admin_customer_tracker_activity', ['route' => 'app_admin_customer_tracker_activity'])->setLabel('Tracker Clienti')->setLabelAttribute('icon', 'eye');
$subMenu->removeChild('groups');
$subMenu = $menu->getChild('sales');
$subMenu->addChild('custom_orders', ['route' => 'app_admin_export_order_by_sms_view'])->setLabel('Export Comenzi SMS')->setLabelAttribute('icon', 'download');
$subMenu->addChild('admin_report_products', ['route' => 'admin_report_products'])->setLabel('Raport produse')->setLabelAttribute('icon', 'list');
$subMenu->addChild('admin_report_order_products', ['route' => 'admin_report_order_products'])->setLabel('Raport comenzi produse')->setLabelAttribute('icon', 'list');
$subMenu->addChild('admin_report_order_products_logs', ['route' => 'admin_report_order_products_logs'])->setLabel('Loguri import confirmare incasare')->setLabelAttribute('icon', 'list');
$menu->removeChild('marketing');
$newSubmenu = $menu->addChild('vehicles')->setLabel('Vehicule');
$newSubmenu->addChild('app_admin_export_vehicles', ['route' => 'app_admin_export_vehicles'])->setLabel('Export Vehicule')->setLabelAttribute('icon', 'download');
$newSubmenu = $menu->addChild('partner')->setLabel('Parteneri');
$newSubmenu->addChild('partners', ['route' => 'app_admin_partner_index'])->setLabel('Parteneri')->setLabelAttribute('icon', 'handshake');
$newSubmenu->addChild('partners_roles', ['route' => 'app_admin_partner_role_index'])->setLabel('Roluri')->setLabelAttribute('icon', 'user');
$menu->reorderChildren(array(
1 => 'ro_vignette',
2 => 'hu_vignette',
3 => 'rca',
4 => 'road_assistance',
5 => 'license_recovery',
6 => 'telemedicine',
7 => 'death_insurance',
8 => 'partner',
9 => 'administration',
10 => 'sales',
11 => 'vehicles',
12 => 'customers',
13 => 'options',
14 => 'configuration',
15 => 'bitbag_cms',
16 => 'catalog'
));
break;
}
if ($rolesArray) {
foreach ($menu as $subMenu) {
if (!in_array($subMenu->getName(), $rolesArray)) {
$menu->removeChild($subMenu->getName());
}
foreach ($subMenu as $child) {
if (!in_array($child->getName(), $rolesArray)) {
$subMenu->removeChild($child->getName());
}
}
}
}
}
}