/**
  * {@inheritdoc}
  */
 public function match(Workflow $workflow, EntityId $entityId, $entity)
 {
     if ($this->providerName) {
         return $entityId->getProviderName() == $this->providerName;
     }
     return $entityId->getProviderName() == $workflow->getProviderName();
 }
 function let(Item $item, EntityId $entityId, Workflow $workflow, EntityRepository $entityRepository, StateRepository $stateRepository, TransactionHandler $transactionHandler, Step $step, Transition $transition, State $state, Listener $listener)
 {
     $workflow->getStep(static::STEP_NAME)->willReturn($step);
     $workflow->getStartTransition()->willReturn($transition);
     $workflow->getName()->willReturn(static::WORKFLOW_NAME);
     $step->isTransitionAllowed(static::TRANSITION_NAME)->willReturn(true);
     $workflow->getTransition(static::TRANSITION_NAME)->willReturn($transition);
     $transition->getName()->willReturn(static::TRANSITION_NAME);
     $transition->isInputRequired($item)->willReturn(false);
     $item->transit($transition, Argument::type(static::CONTEXT_CLASS), Argument::type(static::ERROR_COLLECTION_CLASS))->willReturn($state);
     $item->isWorkflowStarted()->willReturn(true);
     $item->getCurrentStepName()->willReturn(static::STEP_NAME);
     $item->getEntity()->willReturn(static::$entity);
     $entityId->__toString()->willReturn('entity::2');
     $this->beConstructedWith($item, $workflow, static::TRANSITION_NAME, $entityRepository, $stateRepository, $transactionHandler, $listener);
 }
Exemple #3
0
 /**
  * Generate the row.
  *
  * @param array $row Row.
  *
  * @return string
  */
 public function generateRow($row)
 {
     try {
         $entityId = EntityId::fromString($row['entityId']);
         $manager = $this->getServiceProvider()->getManager($entityId->getProviderName());
         $entity = $this->getServiceProvider()->getEntityManager()->getRepository($entityId->getProviderName())->find($entityId->getIdentifier());
         $workflow = $manager->getWorkflow($entityId, $entity);
         if ($workflow) {
             $row['workflowName'] = $workflow->getLabel();
             $row['transitionName'] = $workflow->getTransition($row['transitionName'])->getLabel();
             $row['stepName'] = $workflow->getStep($row['stepName'])->getLabel();
         }
     } catch (\Exception $e) {
         // Catch exception here so if the definition has changes no error is thrown.
     }
     $row['success'] = $this->translate($row['success'] ? 'yes' : 'no', array(), 'MSC');
     $template = new \BackendTemplate('be_workflow_state_row');
     $template->setData($row);
     if (is_numeric($row['reachedAt'])) {
         $template->reachedAt = \Date::parse(\Config::get('datimFormat'), $row['reachedAt']);
     }
     return $template->parse();
 }
 /**
  * Create the state object.
  *
  * @param StateModel $model The state model.
  *
  * @return State
  */
 private function createState(StateModel $model)
 {
     $reachedAt = new \DateTime();
     $reachedAt->setTimestamp($model->reachedAt);
     $state = new State(EntityId::fromString($model->entityId), $model->workflowName, $model->transitionName, $model->stepName, (bool) $model->success, (array) json_decode($model->data, true), $reachedAt, (array) json_decode($model->errors, true), $model->id);
     return $state;
 }
 function it_matches_against_workflow_provider_name(Workflow $workflow, EntityId $entityId)
 {
     $workflow->getProviderName()->willReturn('test');
     $entityId->getProviderName()->willReturn('test');
     $this->match($workflow, $entityId, static::$entity)->shouldReturn(true);
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  */
 public function createItem(EntityId $entityId, $entity)
 {
     $key = $entityId->__toString();
     if (!isset($this->items[$key])) {
         $this->items[$key] = $this->manager->createItem($entityId, $entity);
     }
     return $this->items[$key];
 }
 /**
  * Create the item.
  *
  * It also converts the entity to a ModelInterface instance.
  *
  * @param EntityId $entityId The entity id.
  * @param mixed    $model    The data model.
  *
  * @return Item
  */
 public function createItem(EntityId $entityId, $model)
 {
     $event = new CreateEntityEvent($model, $entityId->getProviderName());
     $this->eventDispatcher->dispatch($event::NAME, $event);
     return parent::createItem($entityId, $event->getEntity());
 }
Exemple #8
0
 function it_does_not_equals_to_another_entity_id_with_different_provider_name(EntityId $otherEntitdId)
 {
     $otherEntitdId->__toString()->willReturn(static::PROVIDER_NAME . '_2::' . static::IDENTIFIER);
     $this->equals($otherEntitdId)->shouldReturn(false);
 }