Beispiel #1
0
 /**
  * @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;
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 /**
  * @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;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
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;
 }
 /**
  * @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;
 }
Beispiel #7
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;
 }
 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);
 }
 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;
 }
 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;
 }