Esempio n. 1
0
 /**
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $resourceNode
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $copy
  * @param array $workspaceRoles
  */
 private function duplicateRights(ResourceNode $resourceNode, ResourceNode $copy, array $workspaceRoles)
 {
     $rights = $resourceNode->getRights();
     $workspace = $resourceNode->getWorkspace();
     foreach ($rights as $right) {
         $role = $right->getRole();
         $key = $role->getTranslationKey();
         $newRight = new ResourceRights();
         $newRight->setResourceNode($copy);
         $newRight->setMask($right->getMask());
         $newRight->setCreatableResourceTypes($right->getCreatableResourceTypes()->toArray());
         if ($role->getWorkspace() === $workspace && isset($workspaceRoles[$key]) && !empty($workspaceRoles[$key])) {
             $newRight->setRole($workspaceRoles[$key]);
         } else {
             $newRight->setRole($role);
         }
         $this->om->persist($newRight);
     }
     $this->om->flush();
 }
 protected static function createResourceRights(Role $role, AbstractResource $resource, $mask, array $creatableResourceTypes = [])
 {
     $rights = new ResourceRights();
     $rights->setRole($role);
     $rights->setResourceNode($resource->getResourceNode());
     $rights->setMask($mask);
     foreach ($creatableResourceTypes as $type) {
         $rights->addCreatableResourceType($type);
     }
     self::create("resource_right/{$role->getName()}-{$resource->getResourceNode()->getName()}", $rights);
 }