Feature: add cc users in workflow: move isNotificationCc to WorkflowNotificationHandler

This commit is contained in:
nobohan
2023-03-29 11:18:23 +02:00
parent e45952f28c
commit a8c2750ac8
6 changed files with 28 additions and 28 deletions

View File

@@ -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;