public function testGetStep() { $step1 = $this->getStepMock('step1'); $step2 = $this->getStepMock('step2'); $steps = new ArrayCollection(array($step1, $step2)); $stepManager = new StepManager($steps); $this->assertEquals($step1, $stepManager->getStep('step1')); $this->assertEquals($step2, $stepManager->getStep('step2')); }
/** * Get passed latest steps from step with minimum order to step with maximum order. * * @param WorkflowItem $workflowItem * @return Collection|Step[] */ public function getPassedStepsByWorkflowItem(WorkflowItem $workflowItem) { $transitionRecords = $workflowItem->getTransitionRecords(); $passedSteps = array(); if ($transitionRecords) { $minStepIdx = count($transitionRecords) - 1; $minStep = $this->stepManager->getStep($transitionRecords[$minStepIdx]->getStepTo()->getName()); $steps = array($minStep); $minStepIdx--; while ($minStepIdx > -1) { $step = $this->stepManager->getStep($transitionRecords[$minStepIdx]->getStepTo()->getName()); if ($step->getOrder() <= $minStep->getOrder() && $step->getName() != $minStep->getName()) { $minStepIdx--; $minStep = $step; $steps[] = $step; } elseif ($step->getName() == $minStep->getName()) { $minStepIdx--; } else { break; } } $passedSteps = array_reverse($steps); } return new ArrayCollection($passedSteps); }
/** * Get transitions for existing workflow item. * * @param WorkflowItem $workflowItem * @return Collection|Transition[] * @throws UnknownStepException */ public function getTransitionsByWorkflowItem(WorkflowItem $workflowItem) { $currentStepName = $workflowItem->getCurrentStepName(); $currentStep = $this->stepManager->getStep($currentStepName); if (!$currentStep) { throw new UnknownStepException($currentStepName); } $transitions = new ArrayCollection(); $transitionNames = $currentStep->getAllowedTransitions(); foreach ($transitionNames as $transitionName) { $transition = $this->transitionManager->extractTransition($transitionName); $transitions->add($transition); } return $transitions; }