/**
  * @param Workflow $workflow
  * @param string $attributeName
  * @return \Oro\Bundle\WorkflowBundle\Model\Attribute
  * @throws SerializerException If attribute not found
  */
 protected function getAttribute(Workflow $workflow, $attributeName)
 {
     $attribute = $workflow->getAttributeManager()->getAttribute($attributeName);
     if (!$attribute) {
         throw new SerializerException(sprintf('Workflow "%s" has no attribute "%s"', $workflow->getName(), $attributeName));
     }
     return $attribute;
 }
 /**
  * @param string $workflowName
  * @param array $attributes
  * @param array $steps
  * @return Workflow
  */
 protected function createWorkflow($workflowName, array $attributes = array(), array $steps = array())
 {
     $workflow = new Workflow();
     $workflow->setName($workflowName);
     foreach ($attributes as $name => $attribute) {
         $workflow->getAttributeManager()->getAttributes()->set($name, $attribute);
     }
     $workflow->getStepManager()->setSteps($steps);
     return $workflow;
 }
 /**
  * @param string $workflowName
  * @param array $attributes
  * @param array $steps
  * @param string|null $relatedEntity
  * @return Workflow
  */
 protected function createWorkflow($workflowName, array $attributes = array(), array $steps = array(), $relatedEntity = null)
 {
     $entityConnector = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\EntityConnector')->disableOriginalConstructor()->getMock();
     $aclManager = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Acl\\AclManager')->disableOriginalConstructor()->getMock();
     $workflow = new Workflow($entityConnector, $aclManager);
     $workflow->setName($workflowName);
     foreach ($attributes as $name => $attribute) {
         $workflow->getAttributeManager()->getAttributes()->set($name, $attribute);
     }
     $workflow->getStepManager()->setSteps($steps);
     $definition = new WorkflowDefinition();
     $definition->setRelatedEntity($relatedEntity);
     $workflow->setDefinition($definition);
     return $workflow;
 }
 /**
  * @param WorkflowDefinition $workflowDefinition
  * @param Workflow $workflow
  */
 protected function setEntityAcls(WorkflowDefinition $workflowDefinition, Workflow $workflow)
 {
     $entityAcls = array();
     foreach ($workflow->getAttributeManager()->getEntityAttributes() as $attribute) {
         foreach ($workflow->getStepManager()->getSteps() as $step) {
             $updatable = $attribute->isEntityUpdateAllowed() && $step->isEntityUpdateAllowed($attribute->getName());
             $deletable = $attribute->isEntityDeleteAllowed() && $step->isEntityDeleteAllowed($attribute->getName());
             if (!$updatable || !$deletable) {
                 $entityAcl = new WorkflowEntityAcl();
                 $entityAcl->setAttribute($attribute->getName())->setStep($workflowDefinition->getStepByName($step->getName()))->setEntityClass($attribute->getOption('class'))->setUpdatable($updatable)->setDeletable($deletable);
                 $entityAcls[] = $entityAcl;
             }
         }
     }
     $workflowDefinition->setEntityAcls($entityAcls);
 }
 /**
  * @param Workflow $workflow
  * @param object $entity
  * @return null|Attribute
  */
 protected function getManagedEntityAttributeByEntity(Workflow $workflow, $entity)
 {
     $entityClass = $this->doctrineHelper->getEntityClass($entity);
     /** @var Attribute $attribute */
     foreach ($workflow->getAttributeManager()->getManagedEntityAttributes() as $attribute) {
         if ($attribute->getOption('class') == $entityClass) {
             return $attribute;
         }
     }
     return null;
 }