<?php
namespace Aqarmap\Bundle\CreditBundle\EventListener;
use Aqarmap\Bundle\FeatureToggleBundle\Service\FeatureToggleManager;
use Aqarmap\Bundle\MainBundle\Event\ConfigureMenuEvent;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ConfigureMenuEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
/**
* Container instance.
*/
protected $container;
/**
* Translator instance.
*/
protected $translator;
/**
* @var FeatureToggleManager
*/
private $featureToggleManager;
/**
* @var AuthorizationCheckerInterface
*/
private $authorizationChecker;
public function __construct(TranslatorInterface $translator, FeatureToggleManager $featureToggleManager, AuthorizationCheckerInterface $authorizationChecker)
{
$this->translator = $translator;
$this->featureToggleManager = $featureToggleManager;
$this->authorizationChecker = $authorizationChecker;
}
/**
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function onAdminSidebarMenuConfigure(ConfigureMenuEvent $event): void
{
$menu = $event->getMenu();
if ($this->authorizationChecker->isGranted('ROLE_ANALYSIS')) {
$menu['analysis']
->addChild('credit_analysis', ['route' => 'aqarmap_admin_analysis_credit'])
->setLabel('Credit Analysis')
->setExtra('icon', 'chart-line')
->setExtra('position', 82);
}
if ($this->authorizationChecker->isGranted('ROLE_ANALYSIS')) {
$menu['analysis']
->addChild('impressions_analysis', ['route' => 'aqarmap_admin_analysis_impressions'])
->setLabel('Impressions Analysis')
->setExtra('icon', 'chart-line')
->setExtra('position', 83);
}
if ($this->authorizationChecker->isGranted('ROLE_CHURN_EXPIRY')) {
$menu['analysis']
->addChild('churn_expiry', ['route' => 'aqarmap_admin_analysis_churn_expiry'])
->setLabel('Churn VS Expiry')
->setExtra('icon', 'users')
->setExtra('position', 85);
}
if ($this->featureToggleManager->isEnabled('web.sales.analysis')) {
if ($this->authorizationChecker->isGranted('ROLE_SALES_ANALYSIS')) {
$menu['analysis']
->addChild('sales_analysis', ['route' => 'aqarmap_admin_sales_analysis'])
->setLabel(' Sales Report')
->setExtra('icon', 'chart-line')
->setExtra('position', 84);
}
}
if ($this->authorizationChecker->isGranted('ROLE_MARKETING')) {
$menu['settings']
->addChild('FAQs', ['route' => 'aqarmap_admin_credit_faq'])
->setLabel($this->translator->trans('layout.admin.faqs'))
->setExtra('icon', 'exclamation-triangle')
->setExtra('position', 107);
}
if ($this->authorizationChecker->isGranted('ROLE_MARKETING')) {
$menu['settings']
->addChild('testimonials', ['route' => 'aqarmap_admin_testimonials'])
->setLabel($this->translator->trans('layout.admin.testimonials'))
->setExtra('icon', 'user-circle')
->setExtra('position', 108);
}
if ($this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
$menu['settings']
->addChild('settings', ['route' => 'aqarmap_admin_settings_index'])
->setLabel('settings')
->setExtra('icon', 'user-circle')
->setExtra('position', 109);
}
}
/**
* @return array<string, mixed>
*/
public static function getSubscribedEvents(): array
{
return ['aqarmap.main.admin_sidebar_menu_configure' => 'onAdminSidebarMenuConfigure'];
}
}