<?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\SalesBundle\EventSubscriber;
use Bluue\CustomersBundle\Event\CustomerViewTabsEvent;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CustomerViewTabsSubscriber 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 string[]
*/
public static function getSubscribedEvents(): array
{
return [
CustomerViewTabsEvent::NAME => 'viewTabs'
];
}
/**
* @param CustomerViewTabsEvent $event
* @return void
*/
public function viewTabs(CustomerViewTabsEvent $event): void
{
if (!$this->security->isGranted('ROLE__SALES__READ_ONLY')) {
return;
}
$tabs = $event->getPages();
$newTabs = [
[
'path' => 'sales_bundle__customer_payments',
'customer_id_required' => true,
'name' => $this->tr->trans('Payments', [], 'SalesBundle')
],
[
'path' => 'sales_bundle__customer_quotations',
'customer_id_required' => true,
'name' => $this->tr->trans('Quotations', [], 'SalesBundle')
],
[
'path' => 'sales_bundle__customer_orders',
'customer_id_required' => true,
'name' => $this->tr->trans('Orders', [], 'SalesBundle')
],
[
'path' => 'sales_bundle__customer_delivery_notes',
'customer_id_required' => true,
'name' => $this->tr->trans('Delivery notes', [], 'SalesBundle')
],
[
'path' => 'sales_bundle__customer_invoices',
'customer_id_required' => true,
'name' => $this->tr->trans('Invoices', [], 'SalesBundle')
],
[
'path' => 'sales_bundle__customer_credit_notes',
'customer_id_required' => true,
'name' => $this->tr->trans('Credit notes', [], 'SalesBundle')
],
[
'path' => 'sales_bundle__customer_products_purchased',
'customer_id_required' => true,
'name' => $this->tr->trans('Products purchased', [], 'SalesBundle')
]
];
$event->setPages(array_merge($tabs, $newTabs));
}
}