vendor/bluue/crm-bundle/src/EventSubscriber/DocumentTabsEventSubscriber.php line 59

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Quentin CHATELAIN (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\CrmBundle\EventSubscriber;
  9. use Bluue\SalesBundle\Event\DocumentTabsEvent;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Security\Core\Security;
  13. class DocumentTabsEventSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var TranslatorInterface
  17.      */
  18.     private TranslatorInterface $tr;
  19.     /**
  20.      * @var Security
  21.      */
  22.     private Security $security;
  23.     /**
  24.      * @param TranslatorInterface $tr
  25.      * @param Security $security
  26.      */
  27.     public function __construct(
  28.         TranslatorInterface $tr,
  29.         Security $security
  30.     ) {
  31.         $this->tr $tr;
  32.         $this->security $security;
  33.     }
  34.     /**
  35.      * @return string[]
  36.      */
  37.     public static function getSubscribedEvents(): array
  38.     {
  39.         return [
  40.             DocumentTabsEvent::QUOTATION_TABS => 'quotationTabs',
  41.             DocumentTabsEvent::ORDER_TABS => 'orderTabs',
  42.             DocumentTabsEvent::INVOICE_TABS => 'invoiceTabs',
  43.             DocumentTabsEvent::CREDIT_NOTE_TABS => 'creditNoteTabs'
  44.         ];
  45.     }
  46.     /**
  47.      * @param DocumentTabsEvent $event
  48.      * @return void
  49.      */
  50.     public function quotationTabs(DocumentTabsEvent $event): void
  51.     {
  52.         if ($this->security->isGranted('ROLE__CRM__READ_ONLY')) {
  53.             $event->addTab([
  54.                 'key' => 'crm_bundle__opportunity',
  55.                 'name' => $this->tr->trans('Opportunity', [], 'CrmBundle'),
  56.                 'icon' => 'fas fa-handshake',
  57.                 'idRequired' => true,
  58.                 'path' => 'crm_bundle__opportunity_quotation'
  59.             ]);
  60.         }
  61.     }
  62.     /**
  63.      * @param DocumentTabsEvent $event
  64.      * @return void
  65.      */
  66.     public function orderTabs(DocumentTabsEvent $event): void
  67.     {
  68.         if ($this->security->isGranted('ROLE__CRM__READ_ONLY')) {
  69.             $event->addTab([
  70.                 'key' => 'crm_bundle__opportunity',
  71.                 'name' => $this->tr->trans('Opportunity', [], 'CrmBundle'),
  72.                 'icon' => 'fas fa-handshake',
  73.                 'idRequired' => true,
  74.                 'path' => 'crm_bundle__opportunity_order'
  75.             ]);
  76.         }
  77.     }
  78.     /**
  79.      * @param DocumentTabsEvent $event
  80.      * @return void
  81.      */
  82.     public function invoiceTabs(DocumentTabsEvent $event): void
  83.     {
  84.         if ($this->security->isGranted('ROLE__CRM__READ_ONLY')) {
  85.             $event->addTab([
  86.                 'key' => 'crm_bundle__opportunity',
  87.                 'name' => $this->tr->trans('Opportunity', [], 'CrmBundle'),
  88.                 'icon' => 'fas fa-handshake',
  89.                 'idRequired' => true,
  90.                 'path' => 'crm_bundle__opportunity_invoice'
  91.             ]);
  92.         }
  93.     }
  94.     /**
  95.      * @param DocumentTabsEvent $event
  96.      * @return void
  97.      */
  98.     public function creditNoteTabs(DocumentTabsEvent $event): void
  99.     {
  100.         if ($this->security->isGranted('ROLE__CRM__READ_ONLY')) {
  101.             $event->addTab([
  102.                 'key' => 'crm_bundle__opportunity',
  103.                 'name' => $this->tr->trans('Opportunity', [], 'CrmBundle'),
  104.                 'icon' => 'fas fa-handshake',
  105.                 'idRequired' => true,
  106.                 'path' => 'crm_bundle__opportunity_credit_note'
  107.             ]);
  108.         }
  109.     }
  110. }