function let(User $user, Transition $transition, Workflow $workflow, Step $step, Permission $permission)
 {
     $this->beConstructedWith($user);
     $transition->getWorkflow()->willReturn($workflow);
     $workflow->getStep('step')->willReturn($step);
     $step->getPermission()->willReturn($permission);
 }
 /**
  * Get role of current step.
  *
  * @param Transition $transition The transition being in.
  * @param Item       $item       The entity being transits.
  *
  * @return Permission|null
  */
 protected function getStepPermission(Transition $transition, Item $item)
 {
     $stepName = $item->getCurrentStepName();
     $step = $transition->getWorkflow()->getStep($stepName);
     $permission = $step->getPermission();
     return $permission;
 }
 /**
  * {@inheritdoc}
  */
 public function match(Transition $transition, Item $item, Context $context, ErrorCollection $errorCollection)
 {
     $permission = Permission::forWorkflowName($transition->getWorkflow()->getName(), 'contao-admin');
     if ($this->user->hasPermission($permission)) {
         return true;
     }
     return parent::match($transition, $item, $context, $errorCollection);
 }
 /**
  * {@inheritdoc}
  */
 public function match(Transition $transition, Item $item, Context $context, ErrorCollection $errorCollection)
 {
     $permission = $transition->getPermission();
     if ($this->checkPermission($permission)) {
         return true;
     }
     $errorCollection->addError('transition.condition.transition-permission', array((string) $permission));
     return false;
 }
Example #5
0
 function it_starts_a_new_workflow_state(EntityId $entityId, State $state, EntityId $entityId, Transition $transition, Workflow $workflow, Step $step, Context $context, ErrorCollection $errorCollection)
 {
     $transition->getWorkflow()->willReturn($workflow);
     $transition->getName()->willReturn('transition_name');
     $transition->getStepTo()->willReturn($step);
     $context->getProperties()->willReturn(array());
     $errorCollection->toArray()->willReturn(array());
     $this->beConstructedThrough('initialize', array($entityId, static::$entity));
     $this->start($transition, $context, $errorCollection, true)->shouldHaveType('Netzmacht\\Workflow\\Flow\\State');
 }
Example #6
0
 /**
  * Get a transition icon.
  *
  * Try to get the transition icon from the config. Use the default one if none is defined.
  *
  * @param Transition $transition The workflow transition.
  *
  * @return string
  */
 public static function getTransitionIcon(Transition $transition)
 {
     $icon = $transition->getConfigValue('icon');
     if ($icon) {
         $model = \FilesModel::findByUuid($icon);
         if ($model) {
             return $model->path;
         }
     }
     return 'system/modules/workflow/assets/img/transition.png';
 }
 /**
  * Prepare data for the notification.
  *
  * @param Transition $transition Current transition.
  * @param Item       $item       Workflow item.
  * @param Context    $context    Transition context.
  *
  * @return array
  */
 private function prepareData(Transition $transition, Item $item, Context $context)
 {
     $entity = $this->getEntity($item);
     $step = $transition->getStepTo();
     $tokens = array();
     $tokens['entity'] = $entity->getPropertiesAsArray();
     $tokens['context'] = $context->getProperties();
     $tokens['entityId'] = (string) $item->getEntityId();
     $tokens['transition'] = $transition->getConfig();
     $tokens['transition']['name'] = $transition->getName();
     $tokens['transition']['label'] = $transition->getLabel();
     $tokens['step'] = $step->getConfig();
     $tokens['step']['name'] = $step->getName();
     $tokens['step']['label'] = $step->getLabel();
     $event = new PrepareNotificationTokensEvent(new \ArrayObject($tokens), $transition, $item);
     $this->eventDispatcher->dispatch($event::NAME, $event);
     return $event->getTokens()->getArrayCopy();
 }
 /**
  * Create transitions from database.
  *
  * @param Workflow $workflow The current workflow.
  *
  * @throws DefinitionException If a target step is defined which does not exiss.
  *
  * @return void
  */
 private function createTransitions(Workflow $workflow)
 {
     $collection = TransitionModel::findByWorkflow($workflow->getConfigValue('id'));
     if (!$collection) {
         return;
     }
     while ($collection->next()) {
         /** @var TransitionModel $model */
         $model = $collection->current();
         $transition = new Transition($model->name, $model->label, array_merge($collection->row(), array(Definition::SOURCE => Definition::SOURCE_DATABASE)));
         if (!isset($this->steps[$model->stepTo])) {
             throw new DefinitionException(sprintf('Transition "%s" refers to step "%s" which does not exists.', $transition->getName(), $model->stepTo));
         }
         $transition->setStepTo($this->steps[$model->stepTo]);
         if ($model->limitPermission) {
             $transition->setPermission(Permission::fromString($model->permission));
         }
         $workflow->addTransition($transition);
         $event = new CreateTransitionEvent($transition);
         $this->getServiceContainer()->getEventDispatcher()->dispatch($event::NAME, $event);
         $this->transitions[$model->id] = $transition;
     }
 }
Example #9
0
 /**
  * Add a transition to the workflow.
  *
  * @param Transition $transition      Transition to be added.
  * @param bool       $startTransition True if transition will be the start transition.
  *
  * @return $this
  */
 public function addTransition(Transition $transition, $startTransition = false)
 {
     $transition->setWorkflow($this);
     $this->transitions[] = $transition;
     if ($startTransition) {
         $this->startTransition = $transition;
     }
     return $this;
 }
 function it_checks_if_transition_is_available(Form $form, Transition $transition, Item $item)
 {
     $transition->getName()->willReturn(static::TRANSITION_NAME);
     $transition->isAvailable($item, Argument::type(self::CONTEXT_CLASS), Argument::type(self::ERROR_COLLECTION_CLASS))->willReturn(true);
     $this->isAvailable()->shouldReturn(true);
 }
 function it_does_not_match_if_transition_has_no_permission(Transition $transition, Item $item, Context $context, ErrorCollection $errorCollection)
 {
     $transition->getPermission()->willReturn(null);
     $errorCollection->addError(Argument::cetera())->shouldBeCalled();
     $this->match($transition, $item, $context, $errorCollection)->shouldReturn(false);
 }
Example #12
0
 /**
  * Transit to a new state.
  *
  * @param Transition      $transition      The transition being performed.
  * @param Context         $context         The transition context.
  * @param ErrorCollection $errorCollection The error collection.
  * @param bool            $success         The success state.
  *
  * @return State
  */
 public function transit(Transition $transition, Context $context, ErrorCollection $errorCollection, $success = true)
 {
     $dateTime = new DateTime();
     $stepName = $success ? $transition->getStepTo()->getName() : $this->stepName;
     return new static($this->entityId, $this->workflowName, $transition->getName(), $stepName, $success, $context->getProperties(), $dateTime, $errorCollection->getErrors());
 }
Example #13
0
 function it_knows_if_transition_is_available_for_an_item(Item $item, Step $step, Context $context, Transition $transition, ErrorCollection $errorCollection)
 {
     $item->isWorkflowStarted()->willReturn(true);
     $item->getCurrentStepName()->willReturn('started');
     $transition->getName()->willReturn('next');
     $transition->isAvailable($item, $context, $errorCollection)->shouldBeCalled()->willReturn(true);
     $this->addTransition($transition);
     $step->getName()->willReturn('started');
     $step->isTransitionAllowed('next')->willReturn(true);
     $this->addStep($step);
     $this->isTransitionAvailable($item, $context, $errorCollection, 'next')->shouldReturn(true);
 }