<?php
/**
* @author Thomas HERISSON (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\SalesBundle\EventSubscriber;
use ReflectionClass;
use App\Services\CheckBundleInstall;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigureStatisticsMenuConfigurationSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var Security
*/
private Security $security;
/**
* @param TranslatorInterface $tr
* @param Security $security
*/
public function __construct(
TranslatorInterface $tr,
Security $security
) {
$this->tr = $tr;
$this->security = $security;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
if (CheckBundleInstall::exist('statistics-bundle')) {
$reflectionClass = new ReflectionClass('Bluue\StatisticsBundle\Event\MenuStatisticPageEvent');
return [
$reflectionClass->getConstant('NAME') => 'onLoad'
];
}
return [];
}
/**
* @param object $event
* @return void
*/
public function onLoad(object $event): void
{
if (!$this->security->isGranted('ROLE__SALES__READ_ONLY')) {
return;
}
$pages = $event->getPages();
$pages[] = [
'id' => 'sales_bundle__statistics',
'name' => $this->tr->trans('Sales', [], 'SalesBundle')
];
$pages[] = [
'id' => 'sales_bundle__statistics_customers',
'name' => $this->tr->trans('Customer sales', [], 'SalesBundle')
];
$pages[] = [
'id' => 'sales_bundle__statistics_taxes',
'name' => $this->tr->trans('Taxe sales', [], 'SalesBundle')
];
$pages[] = [
'id' => 'sales_bundle__statistics_products',
'name' => $this->tr->trans('Product sales', [], 'SalesBundle'),
'subpages' => [
['id' => 'sales_bundle__statistics_products'],
['id' => 'sales_bundle__statistics_declinations'],
]
];
$event->setPages($pages);
}
}