diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index 0d7142e9f..c7a322338 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -25,6 +25,7 @@ use Iterator; use RuntimeException; use Symfony\Component\Serializer\Annotation as Serializer; use function count; +use function is_array; /** * @ORM\Entity @@ -51,7 +52,6 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") - * @Serializer\Groups({"read"}) */ private ?int $id = null; @@ -73,6 +73,11 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface */ private Collection $steps; + /** + * @var null|array|EntityWorkflowStep[] + */ + private ?array $stepsChainedCache = null; + /** * @ORM\ManyToMany(targetEntity=User::class) * @ORM\JoinTable(name="chill_main_workflow_entity_subscriber_to_final") @@ -130,10 +135,6 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface if (!$this->steps->contains($step)) { $this->steps[] = $step; $step->setEntityWorkflow($this); - - if ($this->isFinalize()) { - $step->setFinalizeAfter(true); - } } return $this; @@ -254,27 +255,33 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface public function getStepsChained(): array { + if (is_array($this->stepsChainedCache)) { + return $this->stepsChainedCache; + } + $iterator = $this->steps->getIterator(); - $previous = $next = $current = null; + $current = null; $steps = []; $iterator->rewind(); - while ($iterator->valid()) { + do { $previous = $current; - $steps[] = $current = $iterator->current(); + $current = $iterator->current(); + $steps[] = $current; + $current->setPrevious($previous); $iterator->next(); if ($iterator->valid()) { - $next = $iterator->current(); + $current->setNext($iterator->current()); } else { - $next = null; + $current->setNext(null); } + } while ($iterator->valid()); - $current->setNext($next); - } + $this->stepsChainedCache = $steps; return $steps; } @@ -309,7 +316,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface return $this->workflowName; } - public function isFinalize(): bool + public function isFinal(): bool { $steps = $this->getStepsChained(); @@ -321,7 +328,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface /** @var EntityWorkflowStep $last */ $last = end($steps); - return $last->getPrevious()->isFinalizeAfter(); + return $last->isFinal(); } public function isFreeze(): bool diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php index 6bd39ae0c..c68247174 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowStep.php @@ -53,11 +53,6 @@ class EntityWorkflowStep */ private ?EntityWorkflow $entityWorkflow = null; - /** - * @ORM\Column(type="boolean", options={"default": false}) - */ - private bool $finalizeAfter = false; - /** * @ORM\Column(type="boolean", options={"default": false}) */ @@ -70,6 +65,11 @@ class EntityWorkflowStep */ private ?int $id = null; + /** + * @ORM\Column(type="boolean", options={"default": false}) + */ + private bool $isFinal = false; + /** * filled by @see{EntityWorkflow::getStepsChained}. */ @@ -187,9 +187,9 @@ class EntityWorkflowStep return $this->transitionByEmail; } - public function isFinalizeAfter(): bool + public function isFinal(): bool { - return $this->finalizeAfter; + return $this->isFinal; } public function isFreezeAfter(): bool @@ -244,16 +244,16 @@ class EntityWorkflowStep return $this; } - public function setFinalizeAfter(bool $finalizeAfter): EntityWorkflowStep + public function setFreezeAfter(bool $freezeAfter): EntityWorkflowStep { - $this->finalizeAfter = $finalizeAfter; + $this->freezeAfter = $freezeAfter; return $this; } - public function setFreezeAfter(bool $freezeAfter): EntityWorkflowStep + public function setIsFinal(bool $isFinal): EntityWorkflowStep { - $this->freezeAfter = $freezeAfter; + $this->isFinal = $isFinal; return $this; } diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php index 6600e330a..18ac10c47 100644 --- a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php +++ b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep; use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\PickUserDynamicType; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Workflow\EntityWorkflowManager; use LogicException; use Symfony\Component\Form\AbstractType; @@ -24,6 +25,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\Transition; +use function array_key_exists; class WorkflowStepType extends AbstractType { @@ -31,10 +33,13 @@ class WorkflowStepType extends AbstractType private Registry $registry; - public function __construct(EntityWorkflowManager $entityWorkflowManager, Registry $registry) + private TranslatableStringHelperInterface $translatableStringHelper; + + public function __construct(EntityWorkflowManager $entityWorkflowManager, Registry $registry, TranslatableStringHelperInterface $translatableStringHelper) { $this->entityWorkflowManager = $entityWorkflowManager; $this->registry = $registry; + $this->translatableStringHelper = $translatableStringHelper; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -42,6 +47,7 @@ class WorkflowStepType extends AbstractType /** @var \Chill\MainBundle\Entity\Workflow\EntityWorkflow $entityWorkflow */ $entityWorkflow = $options['entity_workflow']; $handler = $this->entityWorkflowManager->getHandler($entityWorkflow); + $workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName()); if (true === $options['transition']) { if (null === $options['entity_workflow']) { @@ -53,20 +59,49 @@ class WorkflowStepType extends AbstractType ->getEnabledTransitions($entityWorkflow); $choices = array_combine( - array_map(static function (Transition $transition) { return $transition->getName(); }, $transitions), + array_map( + static function (Transition $transition) { + return $transition->getName(); + }, + $transitions + ), $transitions ); $builder ->add('transition', ChoiceType::class, [ - 'label' => 'workflow.Transition', + 'label' => 'workflow.Transition to apply', 'mapped' => false, 'multiple' => false, 'expanded' => true, 'choices' => $choices, - 'choice_label' => static function (Transition $transition) { - return implode(', ', $transition->getTos()); - }, + 'choice_label' => function (Transition $transition) use ($workflow) { + $meta = $workflow->getMetadataStore()->getTransitionMetadata($transition); + + if (array_key_exists('label', $meta)) { + return $this->translatableStringHelper->localize($meta['label']); + } + + return $transition->getName(); + }, + 'choice_attr' => static function (Transition $transition) use ($workflow) { + $toFinal = true; + + foreach ($transition->getTos() as $to) { + $meta = $workflow->getMetadataStore()->getPlaceMetadata($to); + + if ( + !array_key_exists('isFinal', $meta) || false === $meta['isFinal'] + ) { + $toFinal = false; + } + } + + return [ + 'data-is-transition' => 'data-is-transition', + 'data-to-final' => $toFinal ? '1' : '0', + ]; + }, ]) ->add('future_dest_users', PickUserDynamicType::class, [ 'label' => 'workflow.dest for next steps', @@ -88,11 +123,6 @@ class WorkflowStepType extends AbstractType } $builder - ->add('finalizeAfter', CheckboxType::class, [ - 'required' => false, - 'label' => 'workflow.Finalize', - 'help' => 'workflow.The workflow will be finalized', - ]) ->add('comment', ChillTextareaType::class, [ 'required' => false, 'label' => 'Comment', diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/ListWorkflow.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/ListWorkflow.vue index 4a3346972..a59d83d79 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/ListWorkflow.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/EntityWorkflow/ListWorkflow.vue @@ -5,6 +5,19 @@