コード例 #1
0
ファイル: ResourceManager.php プロジェクト: ChMat/CoreBundle
 /**
  * Create the rights for a node.
  *
  * array $rights should be defined that way:
  * array('ROLE_WS_XXX' => array('open' => true, 'edit' => false, ...
  * 'create' => array('directory', ...), 'role' => $entity))
  *
  * @param \Claroline\CoreBundle\Entity\Resource\ResourceNode $node
  * @param array                                              $rights
  */
 public function createRights(ResourceNode $node, array $rights = array())
 {
     foreach ($rights as $data) {
         $resourceTypes = $this->checkResourceTypes($data['create']);
         $this->rightsManager->create($data, $data['role'], $node, false, $resourceTypes);
     }
     if (!array_key_exists('ROLE_ANONYMOUS', $rights)) {
         $this->rightsManager->create(0, $this->roleRepo->findOneBy(array('name' => 'ROLE_ANONYMOUS')), $node, false, array());
     }
     if (!array_key_exists('ROLE_USER', $rights)) {
         $this->rightsManager->create(0, $this->roleRepo->findOneBy(array('name' => 'ROLE_USER')), $node, false, array());
     }
 }
コード例 #2
0
ファイル: RoleManager.php プロジェクト: ngydat/CoreBundle
 public function checkIntegrity()
 {
     $this->log('Checking workspace roles integrity.');
     $workspaces = $this->workspaceRepo->findAll();
     $i = 0;
     $this->om->startFlushSuite();
     foreach ($workspaces as $workspace) {
         $this->log('Checking collaborator role for workspace ' . $workspace->getCode() . '...');
         $collaborator = $this->getCollaboratorRole($workspace);
         if (!$collaborator) {
             $this->log('Adding collaborator role for workspace ' . $workspace->getCode() . '...', LogLevel::DEBUG);
             $this->createWorkspaceRole('ROLE_WS_COLLABORATOR_' . $workspace->getGuid(), 'collaborator', $workspace, true);
             $i++;
             if ($i % 300 === 0) {
                 $this->om->forceFlush();
             }
         }
     }
     $this->om->endFlushSuite();
     $this->log('Checking user role integrity.');
     $users = $this->container->get('claroline.manager.user_manager')->getAllEnabledUsers();
     $this->om->startFlushSuite();
     foreach ($users as $user) {
         $this->log('Checking personal role for ' . $user->getUsername());
         $roleName = 'ROLE_USER_' . strtoupper($user->getUsername());
         $role = $this->roleRepo->findOneByName($roleName);
         if (!$role) {
             $this->log('Adding user role for ' . $user->getUsername(), LogLevel::DEBUG);
             $this->createUserRole($user);
             $i++;
             if ($i % 300 === 0) {
                 $this->om->forceFlush();
             }
         }
     }
     $this->om->endFlushSuite();
 }
コード例 #3
0
 public function getUserRole(User $user)
 {
     return $this->roleRepo->findUserRoleByUser($user);
 }