mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
Feature: add cc users in workflow: move isNotificationCc to WorkflowNotificationHandler
This commit is contained in:
@@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Notification\NotificationHandlerInterface;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class WorkflowNotificationHandler implements NotificationHandlerInterface
|
||||
{
|
||||
@@ -23,10 +24,17 @@ class WorkflowNotificationHandler implements NotificationHandlerInterface
|
||||
|
||||
private EntityWorkflowRepository $entityWorkflowRepository;
|
||||
|
||||
public function __construct(EntityWorkflowRepository $entityWorkflowRepository, EntityWorkflowManager $entityWorkflowManager)
|
||||
private Security $security;
|
||||
|
||||
public function __construct(
|
||||
EntityWorkflowRepository $entityWorkflowRepository,
|
||||
EntityWorkflowManager $entityWorkflowManager,
|
||||
Security $security
|
||||
)
|
||||
{
|
||||
$this->entityWorkflowRepository = $entityWorkflowRepository;
|
||||
$this->entityWorkflowManager = $entityWorkflowManager;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function getTemplate(Notification $notification, array $options = []): string
|
||||
@@ -37,13 +45,28 @@ class WorkflowNotificationHandler implements NotificationHandlerInterface
|
||||
public function getTemplateData(Notification $notification, array $options = []): array
|
||||
{
|
||||
$entityWorkflow = $this->entityWorkflowRepository->find($notification->getRelatedEntityId());
|
||||
|
||||
return [
|
||||
'entity_workflow' => $entityWorkflow,
|
||||
'handler' => $this->entityWorkflowManager->getHandler($entityWorkflow),
|
||||
'notificationCc' => $this->isNotificationCc($notification),
|
||||
];
|
||||
}
|
||||
|
||||
private function isNotificationCc(Notification $notification): bool
|
||||
{
|
||||
$notificationCc = false;
|
||||
|
||||
if ($notification->getRelatedEntityClass() === EntityWorkflow::class) {
|
||||
$relatedEntity = $this->entityWorkflowRepository->findOneBy(['id' => $notification->getRelatedEntityId()]);
|
||||
|
||||
if ($relatedEntity->getCurrentStepCreatedBy() !== $this->security->getUser()) {
|
||||
$notificationCc = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $notificationCc;
|
||||
}
|
||||
|
||||
public function supports(Notification $notification, array $options = []): bool
|
||||
{
|
||||
return $notification->getRelatedEntityClass() === EntityWorkflow::class;
|
||||
|
Reference in New Issue
Block a user