예제 #1
0
 public function createWorkspaceFromModel(WorkspaceModel $model, User $user, $name, $code, $description, $displayable, $selfRegistration, $selfUnregistration, &$errors = array())
 {
     $workspaceModelManager = $this->container->get('claroline.manager.workspace_model_manager');
     $workspace = new Workspace();
     $workspace->setName($name);
     $workspace->setCode($code);
     $workspace->setDescription($description);
     $workspace->setDisplayable($displayable);
     $workspace->setSelfRegistration($selfRegistration);
     $workspace->setSelfUnregistration($selfUnregistration);
     $guid = $this->ut->generateGuid();
     $workspace->setGuid($guid);
     $date = new \Datetime(date('d-m-Y H:i'));
     $workspace->setCreationDate($date->getTimestamp());
     $workspace->setCreator($user);
     $errors = [];
     $this->createWorkspace($workspace);
     $workspaceModelManager->addDataFromModel($model, $workspace, $user, $errors);
     return $workspace;
 }
예제 #2
0
 /**
  * @param Configuration $configuration
  * @param User $owner
  * @param bool $isValidated
  *
  * @throws InvalidConfigurationException
  * @return SimpleWorkbolspace
  *
  * The template doesn't need to be validated anymore if
  *  - it comes from the self::import() function
  *  - we want to create a user from the default template (it should work no matter what)
  */
 public function createWorkspace(Configuration $configuration, User $owner, $isValidated = false)
 {
     $configuration->setOwner($owner);
     $data = $configuration->getData();
     $this->data = $data;
     $this->om->startFlushSuite();
     $this->setImporters($configuration, $data);
     if (!$isValidated) {
         $this->validate($data, false);
         $isValidated = true;
     }
     $workspace = new Workspace();
     $workspace->setName($configuration->getWorkspaceName());
     $workspace->setCode($configuration->getWorkspaceCode());
     $workspace->setDescription($configuration->getWorkspaceDescription());
     $workspace->setGuid($this->container->get('claroline.utilities.misc')->generateGuid());
     $workspace->setDisplayable($configuration->isDisplayable());
     $workspace->setSelfRegistration($configuration->getSelfRegistration());
     $workspace->setRegistrationValidation($configuration->getRegistrationValidation());
     $workspace->setSelfUnregistration($configuration->getSelfUnregistration());
     $date = new \Datetime(date('d-m-Y H:i'));
     $workspace->setCreationDate($date->getTimestamp());
     $this->om->persist($workspace);
     $this->om->flush();
     $this->log('Base workspace created...');
     //load roles
     $this->log('Importing roles...');
     $entityRoles = $this->getImporterByName('roles')->import($data['roles'], $workspace);
     //The manager role is required for every workspace
     $entityRoles['ROLE_WS_MANAGER'] = $this->container->get('claroline.manager.role_manager')->createWorkspaceRole("ROLE_WS_MANAGER_{$workspace->getGuid()}", 'manager', $workspace, true);
     $defaultZip = $this->container->getParameter('claroline.param.templates_directory') . 'default.zip';
     //batch import with default template shouldn't be flushed
     if ($configuration->getArchive() !== $defaultZip) {
         $this->om->forceFlush();
     }
     $this->log('Roles imported...');
     $owner->addRole($entityRoles['ROLE_WS_MANAGER']);
     $this->om->persist($owner);
     //add base roles to the role array
     $pfRoles = $this->om->getRepository('ClarolineCoreBundle:Role')->findAllPlatformRoles();
     foreach ($pfRoles as $pfRole) {
         $entityRoles[$pfRole->getName()] = $pfRole;
     }
     $entityRoles['ROLE_ANONYMOUS'] = $this->om->getRepository('ClarolineCoreBundle:Role')->findOneByName('ROLE_ANONYMOUS');
     $entityRoles['ROLE_USER'] = $this->om->getRepository('ClarolineCoreBundle:Role')->findOneByName('ROLE_USER');
     $dir = new Directory();
     $dir->setName($workspace->getName());
     $dir->setIsUploadDestination(true);
     $root = $this->container->get('claroline.manager.resource_manager')->create($dir, $this->om->getRepository('Claroline\\CoreBundle\\Entity\\Resource\\ResourceType')->findOneByName('directory'), $owner, $workspace, null, null, array());
     $this->log('Populating the workspace...');
     $this->populateWorkspace($workspace, $configuration, $root, $entityRoles, true, false);
     $this->container->get('claroline.manager.workspace_manager')->createWorkspace($workspace);
     if ($owner) {
         $this->log('Set the owner...');
         $workspace->setCreator($owner);
     }
     $this->om->endFlushSuite();
     $fs = new FileSystem();
     return $workspace;
 }
예제 #3
0
 public function generateWorkspace(Course $course, CourseSession $session)
 {
     $user = $this->tokenStorage->getToken()->getUser();
     $model = $course->getWorkspaceModel();
     $description = $course->getDescription();
     $displayable = false;
     $selfRegistration = false;
     $selfUnregistration = false;
     $registrationValidation = false;
     $name = $course->getTitle() . ' [' . $session->getName() . ']';
     $code = $this->generateWorkspaceCode($course->getCode());
     if (is_null($model)) {
         $template = new File($this->defaultTemplate);
         $workspace = new Workspace();
         $workspace->setCreator($user);
         $workspace->setName($name);
         $workspace->setCode($code);
         $workspace->setDisplayable($displayable);
         $workspace->setSelfRegistration($selfRegistration);
         $workspace->setSelfUnregistration($selfUnregistration);
         $workspace->setRegistrationValidation($registrationValidation);
         $workspace->setDescription($description);
         $workspace = $this->workspaceManager->create($workspace, $template);
     } else {
         $workspace = $this->workspaceManager->createWorkspaceFromModel($model, $user, $name, $code, $description, $displayable, $selfRegistration, $selfUnregistration);
     }
     $workspace->setWorkspaceType(0);
     $startDate = $session->getStartDate();
     $endDate = $session->getEndDate();
     if (!is_null($startDate)) {
         $workspace->setStartDate($startDate);
     }
     if (!is_null($endDate)) {
         $workspace->setEndDate($endDate);
     }
     $this->workspaceManager->editWorkspace($workspace);
     return $workspace;
 }