<?php
/**
* @author Quentin CHATELAIN (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\CrmBundle\EventSubscriber;
use Bluue\SalesBundle\Event\DocumentTabsEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
class DocumentTabsEventSubscriber 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 string[]
*/
public static function getSubscribedEvents(): array
{
return [
DocumentTabsEvent::QUOTATION_TABS => 'quotationTabs',
DocumentTabsEvent::ORDER_TABS => 'orderTabs',
DocumentTabsEvent::INVOICE_TABS => 'invoiceTabs',
DocumentTabsEvent::CREDIT_NOTE_TABS => 'creditNoteTabs'
];
}
/**
* @param DocumentTabsEvent $event
* @return void
*/
public function quotationTabs(DocumentTabsEvent $event): void
{
if ($this->security->isGranted('ROLE__CRM__READ_ONLY')) {
$event->addTab([
'key' => 'crm_bundle__opportunity',
'name' => $this->tr->trans('Opportunity', [], 'CrmBundle'),
'icon' => 'fas fa-handshake',
'idRequired' => true,
'path' => 'crm_bundle__opportunity_quotation'
]);
}
}
/**
* @param DocumentTabsEvent $event
* @return void
*/
public function orderTabs(DocumentTabsEvent $event): void
{
if ($this->security->isGranted('ROLE__CRM__READ_ONLY')) {
$event->addTab([
'key' => 'crm_bundle__opportunity',
'name' => $this->tr->trans('Opportunity', [], 'CrmBundle'),
'icon' => 'fas fa-handshake',
'idRequired' => true,
'path' => 'crm_bundle__opportunity_order'
]);
}
}
/**
* @param DocumentTabsEvent $event
* @return void
*/
public function invoiceTabs(DocumentTabsEvent $event): void
{
if ($this->security->isGranted('ROLE__CRM__READ_ONLY')) {
$event->addTab([
'key' => 'crm_bundle__opportunity',
'name' => $this->tr->trans('Opportunity', [], 'CrmBundle'),
'icon' => 'fas fa-handshake',
'idRequired' => true,
'path' => 'crm_bundle__opportunity_invoice'
]);
}
}
/**
* @param DocumentTabsEvent $event
* @return void
*/
public function creditNoteTabs(DocumentTabsEvent $event): void
{
if ($this->security->isGranted('ROLE__CRM__READ_ONLY')) {
$event->addTab([
'key' => 'crm_bundle__opportunity',
'name' => $this->tr->trans('Opportunity', [], 'CrmBundle'),
'icon' => 'fas fa-handshake',
'idRequired' => true,
'path' => 'crm_bundle__opportunity_credit_note'
]);
}
}
}