コード例 #1
0
ファイル: Persister.php プロジェクト: claroline/distribution
 public function user($username)
 {
     $user = new User();
     $user->setFirstName($username);
     $user->setLastName($username);
     $user->setUsername($username);
     $user->setPassword($username);
     $user->setMail($username . '@mail.com');
     $user->setGuid($username);
     $this->om->persist($user);
     if (!$this->userRole) {
         $this->userRole = new Role();
         $this->userRole->setName('ROLE_USER');
         $this->userRole->setTranslationKey('user');
         $this->om->persist($this->userRole);
     }
     $user->addRole($this->userRole);
     $workspace = new Workspace();
     $workspace->setName($username);
     $workspace->setCreator($user);
     $workspace->setCode($username);
     $workspace->setGuid($username);
     $this->om->persist($workspace);
     $user->setPersonalWorkspace($workspace);
     $this->om->flush();
     return $user;
 }
コード例 #2
0
ファイル: Persister.php プロジェクト: claroline/distribution
 /**
  * @param string $username
  *
  * @return User
  */
 public function user($username, $withWorkspace = false)
 {
     $user = new User();
     $user->setFirstName($username);
     $user->setLastName($username);
     $user->setUsername($username);
     $user->setPassword($username);
     $user->setMail($username . '@mail.com');
     $user->setGuid($username);
     $this->om->persist($user);
     if (!$this->userRole) {
         $this->userRole = $this->role('ROLE_USER');
         $this->om->persist($this->userRole);
     }
     $user->addRole($this->userRole);
     if ($withWorkspace) {
         $workspace = new Workspace();
         $workspace->setName($username);
         $workspace->setCreator($user);
         $workspace->setCode($username);
         $workspace->setGuid($username);
         $this->om->persist($workspace);
         $user->setPersonalWorkspace($workspace);
     }
     return $user;
 }
コード例 #3
0
ファイル: Persister.php プロジェクト: claroline/distribution
 /**
  * @param string $name
  *
  * @return Workspace
  */
 public function workspace($name, User $creator)
 {
     $workspace = new Workspace();
     $workspace->setName($name);
     $workspace->setCode($name);
     $workspace->setCreator($creator);
     $template = new SfFile($this->container->getParameter('claroline.param.default_template'));
     //optimize this later
     $this->container->get('claroline.manager.workspace_manager')->create($workspace, $template);
     return $workspace;
 }
コード例 #4
0
ファイル: Persister.php プロジェクト: claroline/distribution
 /**
  * @param $username
  *
  * @return User
  */
 public function user($username)
 {
     $user = new User();
     $user->setFirstName($username);
     $user->setLastName($username);
     $user->setUsername($username);
     $user->setPassword($username);
     $user->setMail($username . '@mail.com');
     $user->setGuid($username);
     $this->om->persist($user);
     $user->addRole($this->userRole);
     $workspace = new Workspace();
     $workspace->setName($username);
     $workspace->setCreator($user);
     $workspace->setCode($username);
     $workspace->setGuid($username);
     $this->om->persist($workspace);
     $user->setPersonalWorkspace($workspace);
     return $user;
 }
コード例 #5
0
ファイル: Persister.php プロジェクト: claroline/distribution
 public function user($username)
 {
     $user = new User();
     $user->setFirstName($username);
     $user->setLastName($username);
     $user->setUsername($username);
     $user->setPassword($username);
     $user->setMail($username . '@mail.com');
     $user->setGuid($username);
     $user->setPublicUrl($username);
     $this->om->persist($user);
     if (!$this->userRole) {
         $this->userRole = $this->om->getRepository('ClarolineCoreBundle:Role')->findOneByName('ROLE_USER');
     }
     $user->addRole($this->userRole);
     $workspace = new Workspace();
     $workspace->setName($username);
     $workspace->setCreator($user);
     $workspace->setCode($username);
     $workspace->setGuid($username);
     $this->om->persist($workspace);
     $user->setPersonalWorkspace($workspace);
     return $user;
 }
コード例 #6
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;
 }
コード例 #7
0
 /**
  * @param File $template
  * @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(Workspace $workspace, File $template, $isValidated = false)
 {
     $data = $this->container->get('claroline.manager.workspace_manager')->getTemplateData($template, true);
     if ($workspace->getCode() === null) {
         $workspace->setCode($data['parameters']['code']);
     }
     if ($workspace->getName() === null) {
         $workspace->setName($data['parameters']['name']);
     }
     //just to be sure doctrine is ok before doing all the workspace
     $this->om->startFlushSuite();
     $this->setImporters($template, $workspace->getCreator());
     if (!$isValidated) {
         $this->validate($data, false);
         $isValidated = true;
     }
     $workspace->setGuid($this->container->get('claroline.utilities.misc')->generateGuid());
     $date = new \Datetime(date('d-m-Y H:i'));
     $workspace->setCreationDate($date->getTimestamp());
     $this->om->persist($workspace);
     $this->om->flush();
     $this->log("Base {$workspace->getCode()} 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);
     //batch import with default template shouldn't be flushed
     if (strpos($template->getPathname(), 'default.zip') === false && strpos($template->getPathname(), 'personal.zip') === false) {
         $this->om->forceFlush();
     }
     $owner = $workspace->getCreator();
     $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, []);
     $this->log('Populating the workspace...');
     $this->populateWorkspace($workspace, $template, $root, $entityRoles, true, false);
     $this->container->get('claroline.manager.workspace_manager')->createWorkspace($workspace);
     $this->om->endFlushSuite();
     return $workspace;
 }
コード例 #8
0
ファイル: WorkspaceManager.php プロジェクト: ChMat/CoreBundle
 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;
 }
コード例 #9
0
 /**
  * Import a workspace list from a csv data.
  *
  * @param array $workspaces
  */
 public function importWorkspaces(array $workspaces, $logger = null, $update = false)
 {
     $i = 0;
     $workspaceModelManager = $this->container->get('claroline.manager.workspace_model_manager');
     foreach ($workspaces as $workspace) {
         ++$i;
         $this->om->startFlushSuite();
         $endDate = null;
         $model = null;
         $name = $workspace[0];
         $code = $workspace[1];
         $isVisible = $workspace[2];
         $selfRegistration = $workspace[3];
         $registrationValidation = $workspace[4];
         $selfUnregistration = $workspace[5];
         if (isset($workspace[6]) && trim($workspace[6]) !== '') {
             $user = $this->om->getRepository('ClarolineCoreBundle:User')->findOneByUsername($workspace[6]);
         } else {
             $user = $this->container->get('security.context')->getToken()->getUser();
         }
         if (isset($workspace[7])) {
             $model = $this->om->getRepository('ClarolineCoreBundle:Model\\WorkspaceModel')->findOneByName($workspace[7]);
         }
         if (isset($workspace[8])) {
             $endDate = new \DateTime();
             $endDate->setTimestamp($workspace[8]);
         }
         if ($update) {
             $workspace = $this->getOneByCode($code);
             if (!$workspace) {
                 //if the workspace doesn't exists, just keep going...
                 continue;
             }
             if ($logger) {
                 $logger('Updating ' . $code . ' (' . $i . '/' . count($workspaces) . ') ...');
             }
         } else {
             $workspace = new Workspace();
         }
         $workspace->setName($name);
         $workspace->setCode($code);
         $workspace->setDisplayable($isVisible);
         $workspace->setSelfRegistration($selfRegistration);
         $workspace->setSelfUnregistration($selfUnregistration);
         $workspace->setRegistrationValidation($registrationValidation);
         $workspace->setCreator($user);
         if ($endDate) {
             $workspace->setEndDate($endDate);
         }
         if (!$update) {
             if ($logger) {
                 $logger('Creating ' . $code . ' (' . $i . '/' . count($workspaces) . ') ...');
             }
             if ($model) {
                 $guid = $this->ut->generateGuid();
                 $this->createWorkspace($workspace);
                 $workspace->setGuid($guid);
                 $date = new \Datetime(date('d-m-Y H:i'));
                 $workspace->setCreationDate($date->getTimestamp());
                 $workspaceModelManager->addDataFromModel($model, $workspace, $user);
             } else {
                 $template = new File($this->container->getParameter('claroline.param.default_template'));
                 $this->container->get('claroline.manager.transfer_manager')->createWorkspace($workspace, $template, true);
             }
         } else {
             if ($model) {
                 $workspaceModelManager->updateDataFromModel($model, $workspace);
             }
         }
         $this->om->persist($workspace);
         $logger('UOW: ' . $this->om->getUnitOfWork()->size());
         if ($i % 100 === 0) {
             $this->om->forceFlush();
             $user = $this->om->getRepository('ClarolineCoreBundle:User')->find($user->getId());
             $this->om->merge($user);
             $this->om->refresh($user);
         }
     }
     $logger('Final flush...');
     $this->om->endFlushSuite();
 }
コード例 #10
0
 protected static function createDisplayableWorkspace($name, $selfRegistration)
 {
     $workspace = new Workspace();
     $workspace->setName($name);
     $workspace->setCode($name . 'Code');
     $workspace->setDisplayable(true);
     $workspace->setSelfRegistration($selfRegistration);
     $workspace->setGuid(self::$client->getContainer()->get('claroline.utilities.misc')->generateGuid());
     self::create($name, $workspace);
 }
コード例 #11
0
 protected function persistActivity($name)
 {
     if (!isset($this->defaults['user'])) {
         $this->defaults['user'] = $this->persistUser('default_user');
     }
     if (!isset($this->defaults['workspace'])) {
         $workspace = new Workspace();
         $workspace->setName('ws-jdoe');
         $workspace->setCreator($this->defaults['user']);
         $workspace->setCode('jdoe-123');
         $workspace->setGuid('123');
         $this->om->persist($workspace);
         $this->defaults['workspace'] = $workspace;
     }
     if (!isset($this->defaults['activity_type'])) {
         $type = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('activity');
         $this->defaults['activity_type'] = $type;
     }
     $node = new ResourceNode();
     $node->setName($name);
     $node->setCreator($this->defaults['user']);
     $node->setResourceType($this->defaults['activity_type']);
     $node->setWorkspace($this->defaults['workspace']);
     $node->setGuid($name);
     $node->setClass('foo');
     $activity = new Activity();
     $activity->setName($name);
     $activity->setDescription('desc');
     $activity->setResourceNode($node);
     $this->om->persist($node);
     $this->om->persist($activity);
     return $activity;
 }
コード例 #12
0
 /**
  * Creates the personal workspace of a user.
  *
  * @param \Claroline\CoreBundle\Entity\User $user
  * @param Model                             $model
  */
 public function setPersonalWorkspace(User $user, $model = null)
 {
     $locale = $this->platformConfigHandler->getParameter('locale_language');
     $this->translator->setLocale($locale);
     $created = $this->workspaceManager->getWorkspaceByCode($user->getUsername());
     if (count($created) > 0) {
         $code = $user->getUsername() . '~' . uniqid();
     } else {
         $code = $user->getUsername();
     }
     $personalWorkspaceName = $this->translator->trans('personal_workspace', [], 'platform') . ' - ' . $user->getUsername();
     if (!$model) {
         $workspace = new Workspace();
         $workspace->setName($personalWorkspaceName);
         $workspace->setCode($code);
         $workspace->setCreator($user);
         $template = new File($this->personalWsTemplateFile);
         $workspace = $this->transferManager->createWorkspace($workspace, $template, true);
     } else {
         $workspace = $this->workspaceManager->createWorkspaceFromModel($model, $user, $personalWorkspaceName, $user->getUsername(), '', false, false, false);
     }
     //add "my public documents" folder
     $resourceManager = $this->container->get('claroline.manager.resource_manager');
     $resourceManager->addPublicFileDirectory($workspace);
     $workspace->setIsPersonal(true);
     $user->setPersonalWorkspace($workspace);
     $this->objectManager->persist($user);
     $this->objectManager->flush();
 }
コード例 #13
0
 private function createActivity($name)
 {
     $user = new User();
     $user->setFirstName('John');
     $user->setLastName('Doe');
     $user->setUsername('jdoe');
     $user->setMail('*****@*****.**');
     $user->setPassword('123');
     $workspace = new Workspace();
     $workspace->setName('w1');
     $workspace->setCode('abc');
     $workspace->setGuid('abc123');
     $workspace->setCreator($user);
     $type = new ResourceType();
     $type->setName('activity');
     $node = new ResourceNode();
     $node->setName($name);
     $node->setClass('FooClass');
     $node->setCreator($user);
     $node->setResourceType($type);
     $node->setWorkspace($workspace);
     $activity = new Activity();
     $activity->setResourceNode($node);
     $activity->setDescription('activity...');
     $this->om->persist($user);
     $this->om->persist($workspace);
     $this->om->persist($type);
     $this->om->persist($node);
     $this->om->persist($activity);
     return $activity;
 }
コード例 #14
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;
 }