<?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;
use App\Event\DashboardWidgetsEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
class DashboardSubscriber implements EventSubscriberInterface
{
/**
* @var Security
*/
private Security $security;
/**
* @param Security $security
*/
public function __construct(
Security $security
) {
$this->security = $security;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
DashboardWidgetsEvent::NAME => 'onLoad'
];
}
/**
* @param DashboardWidgetsEvent $event
* @return void
*/
public function onLoad(DashboardWidgetsEvent $event): void
{
if ($this->security->isGranted('ROLE__PROJECTS__ADMIN')) {
$event->addWidget('projects_bundle__dashboard_number_projects_by_step');
}
if ($this->security->isGranted('ROLE__PROJECTS__READ_ONLY')) {
$event->addWidget('projects_bundle__dashboard_tasks_iframe');
}
}
}