vendor/bluue/stocks-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\StocksBundle\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__STOCKS__READ_ONLY')) {
  55.             return;
  56.         }
  57.         $pages $event->getPages();
  58.         $pages[] = [
  59.             'id' => 'stocks_bundle__statistics',
  60.             'name' => $this->tr->trans('Stocks', [], 'StocksBundle')
  61.         ];
  62.         $pages[] = [
  63.             'id' => 'stocks_bundle__statistics_rotation_products',
  64.             'name' => $this->tr->trans('Products rotation', [], 'StocksBundle')
  65.         ];
  66.         $event->setPages($pages);
  67.     }
  68. }