vendor/bluue/sales-bundle/src/EventSubscriber/CustomerViewTabsSubscriber.php line 65

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 Bluue\CustomersBundle\Event\CustomerViewTabsEvent;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\Security\Core\Security;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class CustomerViewTabsSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var TranslatorInterface
  18.      */
  19.     private TranslatorInterface $tr;
  20.     /**
  21.      * @var RequestStack
  22.      */
  23.     protected RequestStack $requestStack;
  24.     /**
  25.      * @var Security
  26.      */
  27.     private Security $security;
  28.     /**
  29.      * @param RequestStack $requestStack
  30.      * @param TranslatorInterface $tr
  31.      * @param Security $security
  32.      */
  33.     public function __construct(
  34.         RequestStack $requestStack,
  35.         TranslatorInterface $tr,
  36.         Security $security
  37.     ) {
  38.         $this->requestStack $requestStack;
  39.         $this->tr $tr;
  40.         $this->security $security;
  41.     }
  42.     /**
  43.      * @return string[]
  44.      */
  45.     public static function getSubscribedEvents(): array
  46.     {
  47.         return [
  48.             CustomerViewTabsEvent::NAME => 'viewTabs'
  49.         ];
  50.     }
  51.     /**
  52.      * @param CustomerViewTabsEvent $event
  53.      * @return void
  54.      */
  55.     public function viewTabs(CustomerViewTabsEvent $event): void
  56.     {
  57.         if (!$this->security->isGranted('ROLE__SALES__READ_ONLY')) {
  58.             return;
  59.         }
  60.         $tabs $event->getPages();
  61.         $newTabs = [
  62.             [
  63.                 'path' => 'sales_bundle__customer_payments',
  64.                 'customer_id_required' => true,
  65.                 'name' => $this->tr->trans('Payments', [], 'SalesBundle')
  66.             ],
  67.             [
  68.                 'path' => 'sales_bundle__customer_quotations',
  69.                 'customer_id_required' => true,
  70.                 'name' => $this->tr->trans('Quotations', [], 'SalesBundle')
  71.             ],
  72.             [
  73.                 'path' => 'sales_bundle__customer_orders',
  74.                 'customer_id_required' => true,
  75.                 'name' => $this->tr->trans('Orders', [], 'SalesBundle')
  76.             ],
  77.             [
  78.                 'path' => 'sales_bundle__customer_delivery_notes',
  79.                 'customer_id_required' => true,
  80.                 'name' => $this->tr->trans('Delivery notes', [], 'SalesBundle')
  81.             ],
  82.             [
  83.                 'path' => 'sales_bundle__customer_invoices',
  84.                 'customer_id_required' => true,
  85.                 'name' => $this->tr->trans('Invoices', [], 'SalesBundle')
  86.             ],
  87.             [
  88.                 'path' => 'sales_bundle__customer_credit_notes',
  89.                 'customer_id_required' => true,
  90.                 'name' => $this->tr->trans('Credit notes', [], 'SalesBundle')
  91.             ],
  92.             [
  93.                 'path' => 'sales_bundle__customer_products_purchased',
  94.                 'customer_id_required' => true,
  95.                 'name' => $this->tr->trans('Products purchased', [], 'SalesBundle')
  96.             ]
  97.         ];
  98.         $event->setPages(array_merge($tabs$newTabs));
  99.     }
  100. }