/** * @param WorkflowItem $workflowItem * @return WorkflowItem * @throws WorkflowException */ public function updateAclIdentities(WorkflowItem $workflowItem) { $workflow = $this->workflowRegistry->getWorkflow($workflowItem->getWorkflowName()); $definition = $workflowItem->getDefinition(); $currentStepName = $workflowItem->getCurrentStep()->getName(); $aclIdentities = array(); foreach ($definition->getEntityAcls() as $entityAcl) { if ($entityAcl->getStep()->getName() == $currentStepName) { $attributeName = $entityAcl->getAttribute(); $attribute = $workflow->getAttributeManager()->getAttribute($attributeName); $entity = $workflowItem->getData()->get($attributeName); if (!$entity) { continue; } if (!is_object($entity)) { throw new WorkflowException(sprintf('Value of attribute "%s" must be an object', $attributeName)); } $aclIdentity = new WorkflowEntityAclIdentity(); $aclIdentity->setAcl($entityAcl)->setEntityClass($attribute->getOption('class'))->setEntityId($this->doctrineHelper->getSingleEntityIdentifier($entity)); $aclIdentities[] = $aclIdentity; } } $workflowItem->setAclIdentities($aclIdentities); return $workflowItem; }
public function testSetGetAclIdentities() { $firstStep = new WorkflowStep(); $firstStep->setName('first_step'); $secondStep = new WorkflowStep(); $secondStep->setName('second_step'); $firstEntityAcl = new WorkflowEntityAcl(); $firstEntityAcl->setStep($firstStep)->setAttribute('first_attribute'); $secondEntityAcl = new WorkflowEntityAcl(); $secondEntityAcl->setStep($secondStep)->setAttribute('second_attribute'); $firstAclIdentity = new WorkflowEntityAclIdentity(); $firstAclIdentity->setAcl($firstEntityAcl); $alternativeFirstAclIdentity = new WorkflowEntityAclIdentity(); $alternativeFirstAclIdentity->setAcl($firstEntityAcl); $secondAclIdentity = new WorkflowEntityAclIdentity(); $secondAclIdentity->setAcl($secondEntityAcl); // default $this->assertEmpty($this->workflowItem->getAclIdentities()->toArray()); // adding $this->workflowItem->setAclIdentities(array($firstAclIdentity)); $this->assertCount(1, $this->workflowItem->getAclIdentities()); $this->assertEquals($firstAclIdentity, $this->workflowItem->getAclIdentities()->first()); // merging $this->workflowItem->setAclIdentities(array($alternativeFirstAclIdentity, $secondAclIdentity)); $this->assertCount(2, $this->workflowItem->getAclIdentities()); $aclIdentities = array_values($this->workflowItem->getAclIdentities()->toArray()); $this->assertEquals($firstAclIdentity, $aclIdentities[0]); $this->assertEquals($secondAclIdentity, $aclIdentities[1]); // removing $this->workflowItem->setAclIdentities(array($secondAclIdentity)); $this->assertCount(1, $this->workflowItem->getAclIdentities()); $this->assertEquals($secondAclIdentity, $this->workflowItem->getAclIdentities()->first()); // resetting $this->workflowItem->setAclIdentities(array()); $this->assertEmpty($this->workflowItem->getAclIdentities()->toArray()); }