vendor/bluue/sales-bundle/src/EventSubscriber/ConfigureStatisticsMenuConfigurationSubscriber.php line 61

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\SalesBundle\EventSubscriber;
  9. use ReflectionClass;
  10. use App\Services\CheckBundleInstall;
  11. use Symfony\Component\Security\Core\Security;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class ConfigureStatisticsMenuConfigurationSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var TranslatorInterface
  18.      */
  19.     private TranslatorInterface $tr;
  20.     /**
  21.      * @var Security
  22.      */
  23.     private Security $security;
  24.     /**
  25.      * @param TranslatorInterface $tr
  26.      * @param Security $security
  27.      */
  28.     public function __construct(
  29.         TranslatorInterface $tr,
  30.         Security $security
  31.     ) {
  32.         $this->tr $tr;
  33.         $this->security $security;
  34.     }
  35.     /**
  36.      * @return array
  37.      */
  38.     public static function getSubscribedEvents(): array
  39.     {
  40.         if (CheckBundleInstall::exist('statistics-bundle')) {
  41.             $reflectionClass = new ReflectionClass('Bluue\StatisticsBundle\Event\MenuStatisticPageEvent');
  42.             return [
  43.                 $reflectionClass->getConstant('NAME') => 'onLoad'
  44.             ];
  45.         }
  46.         return [];
  47.     }
  48.     /**
  49.      * @param object $event
  50.      * @return void
  51.      */
  52.     public function onLoad(object $event): void
  53.     {
  54.         if (!$this->security->isGranted('ROLE__SALES__READ_ONLY')) {
  55.             return;
  56.         }
  57.         $pages $event->getPages();
  58.         $pages[] = [
  59.             'id' => 'sales_bundle__statistics',
  60.             'name' => $this->tr->trans('Sales', [], 'SalesBundle')
  61.         ];
  62.         $pages[] = [
  63.             'id' => 'sales_bundle__statistics_customers',
  64.             'name' => $this->tr->trans('Customer sales', [], 'SalesBundle')
  65.         ];
  66.         $pages[] = [
  67.             'id' => 'sales_bundle__statistics_taxes',
  68.             'name' => $this->tr->trans('Taxe sales', [], 'SalesBundle')
  69.         ];
  70.         $pages[] = [
  71.             'id' => 'sales_bundle__statistics_products',
  72.             'name' => $this->tr->trans('Product sales', [], 'SalesBundle'),
  73.             'subpages' => [
  74.                 ['id' => 'sales_bundle__statistics_products'],
  75.                 ['id' => 'sales_bundle__statistics_declinations'],
  76.             ]
  77.         ];
  78.         $event->setPages($pages);
  79.     }
  80. }