示例#1
0
 public function checkIntegrity()
 {
     $this->log('Checking roles integrity for resources... This may take a while.');
     $workspaceManager = $this->container->get('claroline.manager.workspace_manager');
     $workspaces = $this->om->getRepository('Claroline\\CoreBundle\\Entity\\Workspace\\Workspace')->findAll();
     $this->om->startFlushSuite();
     $i = 0;
     foreach ($workspaces as $workspace) {
         $this->log('Checking ' . $workspace->getCode() . '...');
         $roles = $workspace->getRoles();
         $root = $this->container->get('claroline.manager.resource_manager')->getWorkspaceRoot($workspace);
         $collaboratorRole = $this->roleManager->getCollaboratorRole($workspace);
         if ($root && $collaboratorRole) {
             $collaboratorFound = false;
             foreach ($root->getRights() as $right) {
                 if ($right->getRole()->getName() == $this->roleManager->getCollaboratorRole($workspace)->getName()) {
                     $collaboratorFound = true;
                 }
             }
             if (!$collaboratorFound) {
                 $this->log('Adding missing right on root for ' . $workspace->getCode() . '.', LogLevel::DEBUG);
                 $collaboratorRole = $this->roleManager->getCollaboratorRole($workspace);
                 $this->editPerms(5, $collaboratorRole, $root, true, array(), true);
                 $i++;
                 if ($i % 3 === 0) {
                     $this->log('flushing...');
                     $this->om->forceFlush();
                     $this->om->clear();
                 }
             }
         }
     }
     $this->om->endFlushSuite();
 }
 public function countUsers(Workspace $workspace, $includeGrps = false)
 {
     if ($includeGrps) {
         $wsRoles = $this->roleManager->getRolesByWorkspace($workspace);
         return $this->container->get('claroline.manager.user_manager')->countByRoles($wsRoles, true);
     }
     return $this->workspaceRepo->countUsers($workspace->getId());
 }
示例#3
0
 /**
  * Import the content of an archive in a workspace.
  *
  * @param Configuration $configuration
  * @param Workspace $workspace
  * @return Workspace
  */
 public function importInExistingWorkspace(Configuration $configuration, Workspace $workspace)
 {
     $root = $this->resourceManager->getResourceFromNode($this->resourceManager->getWorkspaceRoot($workspace));
     $wsRoles = $this->roleManager->getRolesByWorkspace($workspace);
     $entityRoles = [];
     foreach ($wsRoles as $wsRole) {
         $entityRoles[$this->roleManager->getWorkspaceRoleBaseName($wsRole)] = $wsRole;
     }
     $workspace = $this->container->get('claroline.manager.transfert_manager')->populateWorkspace($workspace, $configuration, $root, $entityRoles);
     $this->importRichText();
     return $workspace;
 }
示例#4
0
 /**
  * Adds the public file directory in a workspace
  *
  * @param Workspace $workspace
  *
  * @return Directory
  */
 public function addPublicFileDirectory(Workspace $workspace)
 {
     $directory = new Directory();
     $dirName = $this->translator->trans('my_public_documents', array(), 'platform');
     $directory->setName($dirName);
     $directory->setIsUploadDestination(true);
     $parent = $this->getNodeScheduledForInsert($workspace, $workspace->getName());
     if (!$parent) {
         $parent = $this->resourceNodeRepo->findOneBy(array('workspace' => $workspace->getId(), 'parent' => $parent));
     }
     $role = $this->roleManager->getRoleByName('ROLE_ANONYMOUS');
     return $this->create($directory, $this->getResourceTypeByName('directory'), $workspace->getCreator(), $workspace, $parent, null, array('ROLE_ANONYMOUS' => array('open' => true, 'export' => true, 'create' => array(), 'role' => $role)), true);
 }
示例#5
0
 public function getPersonalWorkspaceToolConfigAsArray()
 {
     $roles = $this->roleManager->getAllPlatformRoles();
     $availableTools = $this->getAvailableWorkspaceTools();
     $data = [];
     foreach ($roles as $role) {
         $data[$role->getId()] = array();
         $perms = $this->pwsToolConfigRepo->findByRole($role);
         if ($perms === array() || $perms === null) {
             foreach ($availableTools as $availableTool) {
                 $data[$role->getId()][$availableTool->getId()] = array('toolId' => $availableTool->getId(), 'name' => $availableTool->getName(), 'mask' => 0, 'id' => 0);
             }
         } else {
             $tools = [];
             foreach ($perms as $perm) {
                 $tools[$perm->getTool()->getId()] = array('toolId' => $perm->getTool()->getId(), 'name' => $perm->getTool()->getName(), 'mask' => $perm->getMask(), 'id' => $perm->getId());
             }
             //then we'll have to add the missing roles
             //[ ADD MISSING ROLES HERE]
             foreach ($availableTools as $availableTool) {
                 $found = false;
                 foreach ($tools as $tool) {
                     if ($tool['name'] === $availableTool->getName()) {
                         $found = true;
                     }
                 }
                 if (!$found) {
                     $tools[$availableTool->getId()] = array('toolId' => $availableTool->getId(), 'name' => $availableTool->getName(), 'mask' => 0, 'id' => null);
                 }
             }
             $data[$role->getId()] = $tools;
         }
     }
     //order the array so we can use it easily.
     return $data;
 }