fix sending notifications

This commit is contained in:
Julien Fastré 2022-02-16 21:54:06 +01:00
parent aebb21935b
commit 45beb27f83
3 changed files with 23 additions and 4 deletions

View File

@ -197,6 +197,8 @@ class WorkflowController extends AbstractController
);
}
$entityWorkflow->futureDestUsers = $transitionForm['future_dest_users']->getData();
$workflow->apply($entityWorkflow, $transition);
foreach ($transitionForm['future_dest_users']->getData() as $user) {

View File

@ -41,6 +41,17 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
use TrackUpdateTrait;
/**
* a list of future dest users for the next steps.
*
* This is in used in order to let controller inform who will be the future users which will validate
* the next step. This is necessary to perform some computation about the next users, before they are
* associated to the entity EntityWorkflowStep.
*
* @var array|User[]
*/
public array $futureDestUsers = [];
/**
* @ORM\OneToMany(targetEntity=EntityWorkflowComment::class, mappedBy="entityWorkflow", orphanRemoval=true)
*

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Workflow\EventSubscriber;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Workflow\Helper\MetadataExtractor;
use Doctrine\ORM\EntityManagerInterface;
@ -34,8 +35,13 @@ class NotificationOnTransition implements EventSubscriberInterface
private Security $security;
public function __construct(EntityManagerInterface $entityManager, EngineInterface $engine, MetadataExtractor $metadataExtractor, Security $security, Registry $registry)
{
public function __construct(
EntityManagerInterface $entityManager,
EngineInterface $engine,
MetadataExtractor $metadataExtractor,
Security $security,
Registry $registry
) {
$this->entityManager = $entityManager;
$this->engine = $engine;
$this->metadataExtractor = $metadataExtractor;
@ -62,7 +68,7 @@ class NotificationOnTransition implements EventSubscriberInterface
$dests = array_merge(
$entityWorkflow->getSubscriberToStep()->toArray(),
$entityWorkflow->isFinal() ? $entityWorkflow->getSubscriberToFinal()->toArray() : [],
$entityWorkflow->getCurrentStep()->getDestUser()->toArray()
$entityWorkflow->getCurrentStepChained()->getPrevious()->getDestUser()->toArray()
);
$place = $this->metadataExtractor->buildArrayPresentationForPlace($entityWorkflow);
@ -85,7 +91,7 @@ class NotificationOnTransition implements EventSubscriberInterface
'dest' => $subscriber,
'place' => $place,
'workflow' => $workflow,
'is_dest' => $entityWorkflow->getCurrentStep()->getDestUser()->contains($subscriber),
'is_dest' => in_array($subscriber->getId(), array_map(static function (User $u) { return $u->getId(); }, $entityWorkflow->futureDestUsers), true),
];
$notification = new Notification();