예제 #1
0
 /**
  * @param Workspace $workspace
  * @param User      $user
  *
  * @return User
  */
 public function workspaceUser(Workspace $workspace, User $user)
 {
     $role = new Role();
     $role->setName("ROLE_WS_{$workspace->getName()}_{$user->getUsername()}");
     $role->setTranslationKey($role->getName());
     $role->setWorkspace($workspace);
     $user->addRole($role);
     $this->om->persist($role);
     $this->om->persist($user);
     return $user;
 }
예제 #2
0
 /**
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $source
  * @param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
  * @param \Claroline\CoreBundle\Entity\User $user
  */
 private function duplicateRootDirectory(Workspace $source, Workspace $workspace, User $user)
 {
     $rootDirectory = new Directory();
     $rootDirectory->setName($workspace->getName());
     $directoryType = $this->resourceManager->getResourceTypeByName('directory');
     $resource = $this->resourceManager->create($rootDirectory, $directoryType, $user, $workspace, null, null, array());
     $workspaceRoles = $this->getArrayRolesByWorkspace($workspace);
     $root = $this->resourceManager->getWorkspaceRoot($source);
     $rights = $root->getRights();
     foreach ($rights as $right) {
         $role = $right->getRole();
         if ($role->getType() === 1) {
             $newRight = $this->rightsManager->getRightsFromIdentityMapOrScheduledForInsert($role->getName(), $resource->getResourceNode());
         } else {
             $newRight = new ResourceRights();
             $newRight->setResourceNode($resource->getResourceNode());
             if ($role->getWorkspace() === $source) {
                 $key = $role->getTranslationKey();
                 if (isset($workspaceRoles[$key]) && !empty($workspaceRoles[$key])) {
                     $newRight->setRole($workspaceRoles[$key]);
                 }
             } else {
                 $newRight->setRole($role);
             }
         }
         $newRight->setMask($right->getMask());
         $newRight->setCreatableResourceTypes($right->getCreatableResourceTypes()->toArray());
         $this->om->persist($newRight);
     }
     $this->om->flush();
     return $resource;
 }
예제 #3
0
 /**
  * Full workspace export.
  */
 public function export(Workspace $workspace)
 {
     $this->log("Exporting {$workspace->getCode()}...");
     foreach ($this->listImporters as $importer) {
         $importer->setListImporters($this->listImporters);
     }
     $data = [];
     $files = [];
     $data['parameters']['code'] = $workspace->getCode();
     $data['parameters']['name'] = $workspace->getName();
     $data['roles'] = $this->getImporterByName('roles')->export($workspace, $files, null);
     $data['tools'] = $this->getImporterByName('tools')->export($workspace, $files, null);
     $_resManagerData = [];
     foreach ($data['tools'] as &$_tool) {
         if ($_tool['tool']['type'] === 'resource_manager') {
             $_resManagerData =& $_tool['tool'];
         }
     }
     //then we parse and replace the text, we also add missing files in $resManagerData
     $files = $this->container->get('claroline.importer.rich_text_formatter')->setPlaceHolders($files, $_resManagerData);
     //throw new \Exception();
     //generate the archive in a temp dir
     $content = Yaml::dump($data, 10);
     //zip and returns the archive
     $archDir = $this->container->get('claroline.config.platform_config_handler')->getParameter('tmp_dir') . DIRECTORY_SEPARATOR . uniqid();
     $archPath = $archDir . DIRECTORY_SEPARATOR . 'archive.zip';
     mkdir($archDir);
     $manifestPath = $archDir . DIRECTORY_SEPARATOR . 'manifest.yml';
     file_put_contents($manifestPath, $content);
     $archive = new \ZipArchive();
     $success = $archive->open($archPath, \ZipArchive::CREATE);
     if ($success === true) {
         $archive->addFile($manifestPath, 'manifest.yml');
         foreach ($files as $uid => $file) {
             $archive->addFile($file, $uid);
         }
         $archive->close();
     } else {
         throw new \Exception('Unable to create archive . ' . $archPath . ' (error ' . $success . ')');
     }
     $this->container->get('claroline.core_bundle.listener.kernel_terminate_listener')->addElementToRemove($archPath);
     return $archPath;
 }
예제 #4
0
 public function toArray(Workspace $workspace)
 {
     $data = array();
     $data['id'] = $workspace->getId();
     $data['name'] = $workspace->getName();
     $data['code'] = $workspace->getCode();
     $data['expiration_date'] = $workspace->getEndDate()->getTimeStamp();
     return $data;
 }