Example #1
0
 /**
  * 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;
 }
Example #3
0
 public function testStartStep()
 {
     $testStartStep = 'start_step';
     $startStep = new Step();
     $startStep->setName($testStartStep);
     $stepManager = new StepManager(array($startStep));
     $this->assertNull($stepManager->getStartStep());
     $this->assertFalse($stepManager->hasStartStep());
     $stepManager->setStartStepName($testStartStep);
     $this->assertEquals($startStep, $stepManager->getStartStep());
     $this->assertTrue($stepManager->hasStartStep());
 }