<?php
/**
* @author Thomas HERISSON (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\ProjectsBundle\EventSubscriber\SalesBundle;
use App\Services\CheckBundleInstall;
use ReflectionClass;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class QuotationTabsSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var RequestStack
*/
protected RequestStack $requestStack;
/**
* @var Security
*/
private Security $security;
/**
* @param RequestStack $requestStack
* @param TranslatorInterface $tr
* @param Security $security
*/
public function __construct(
RequestStack $requestStack,
TranslatorInterface $tr,
Security $security
) {
$this->requestStack = $requestStack;
$this->tr = $tr;
$this->security = $security;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
if (CheckBundleInstall::exist('sales-bundle')) {
$reflectionClass = new ReflectionClass('Bluue\SalesBundle\Event\DocumentTabsEvent');
return [
$reflectionClass->getConstant('QUOTATION_TABS') => 'quotationTabs'
];
}
return [];
}
/**
* @param object $event
* @return void
*/
public function quotationTabs(object $event)
{
if ($this->security->isGranted('ROLE__PROJECTS__READ_ONLY')) {
$event->addTab([
'key' => 'projects_bundle__project',
'name' => $this->tr->trans('Project', [], 'ProjectsBundle'),
'icon' => 'fas fa-project-diagram',
'idRequired' => true,
'path' => 'projects_bundle__project_quotation',
'layout' => 'view'
]);
}
}
}