<?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\StocksBundle\EventSubscriber\SalesBundle;
use App\Services\CheckBundleInstall;
use Bluue\StocksBundle\Event\AccessStockOrderReservedEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class DocumentTabsEventSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var Security
*/
private Security $security;
/**
* @var EventDispatcherInterface
*/
private EventDispatcherInterface $eventDispatcher;
/**
* @param TranslatorInterface $tr
* @param Security $security
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
TranslatorInterface $tr,
Security $security,
EventDispatcherInterface $eventDispatcher
) {
$this->tr = $tr;
$this->security = $security;
$this->eventDispatcher = $eventDispatcher;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
if (CheckBundleInstall::exist('sales-bundle')) {
$reflectionClass = new \ReflectionClass('Bluue\SalesBundle\Event\DocumentTabsEvent');
return [
$reflectionClass->getConstant('ORDER_TABS') => 'orderTabs'
];
}
return [];
}
/**
* @param object $event
* @return void
*/
public function orderTabs(object $event)
{
$accessStockOrderEvent = new AccessStockOrderReservedEvent(false);
$this->eventDispatcher->dispatch(
$accessStockOrderEvent,
AccessStockOrderReservedEvent::NAME
);
if ($accessStockOrderEvent->isAccess() && $this->security->isGranted('ROLE__STOCKS__READ_ONLY')) {
$event->addTab([
'key' => 'stocks_bundle__stock_order_lines_reserved',
'name' => $this->tr->trans('Reserved stocks', [], 'StocksBundle'),
'icon' => 'fas fa-box-open',
'idRequired' => true,
'path' => 'stocks_bundle__stock_order_lines_reserved',
'layout' => 'view'
]);
}
}
}