Пример #1
0
 /**
  * Merges permissions related to a specific resource type (i.e. "post" in a
  * forum) with a directory mask. This allows directory permissions to be
  * applied recursively without losing particular permissions.
  *
  * @param int $dirMask          A directory mask
  * @param int $resourceMask     A specific resource mask
  * @return int
  */
 private function mergeTypePermissions($dirMask, $resourceMask, ResourceType $resourceType)
 {
     $baseArray = array();
     $defaultActions = $this->maskManager->getDefaultActions();
     foreach ($defaultActions as $action) {
         $baseArray[$action] = true;
     }
     $basePerms = $this->maskManager->encodeMask($baseArray, $resourceType);
     //a little bit of magic goes here.
     $all = $resourceMask | $basePerms;
     //merge
     $typeMask = $all ^ $basePerms;
     //extract perm from type
     $this->log('resource mask is ' . $resourceMask . '  | basePerms is ' . $basePerms . ' | base mask is ' . $typeMask);
     return $dirMask | $typeMask;
     // merge perm from type and new perms
 }
Пример #2
0
 /**
  * Set the permission for a resource right.
  * The array of permissions should be defined that way:
  * array('open' => true, 'edit' => false, ...)
  *
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceRights $rights
  * @param array                                                $permissions
  *
  * @return \Claroline\CoreBundle\Entity\Resource\ResourceRights
  */
 public function setPermissions(ResourceRights $rights, array $permissions)
 {
     $resourceType = $rights->getResourceNode()->getResourceType();
     $rights->setMask($this->maskManager->encodeMask($permissions, $resourceType));
     return $rights;
 }