예제 #1
0
 /**
  * @View(serializerGroups={"api"})
  * @ApiDoc(
  *     description="Update a workspace owner",
  *     views = {"workspace"}
  * )
  * @ParamConverter("user", class="ClarolineCoreBundle:User", options={"repository_method" = "findForApi"})
  */
 public function putWorkspaceOwnerAction(Workspace $workspace, User $user)
 {
     $currentCreator = $workspace->getCreator();
     if ($currentCreator->getId() !== $user->getId()) {
         $this->om->startFlushSuite();
         $role = $this->roleManager->getManagerRole($workspace);
         $this->roleManager->associateRole($user, $role);
         $this->roleManager->dissociateRole($currentCreator, $role);
         $workspace->setCreator($user);
         $this->workspaceManager->editWorkspace($workspace);
         $this->om->endFlushSuite();
     }
     return $workspace;
 }
 /**
  * @EXT\Route("/dashboards/preview/{workspaceId}/times", name="get_dashboard_spent_times_by_workspace")
  * @EXT\ParamConverter("user", converter="current_user", options={"allowAnonymous"=false})
  * @EXT\ParamConverter("workspace", class="ClarolineCoreBundle:Workspace\Workspace", options={"mapping": {"workspaceId": "id"}})
  * @EXT\Method("GET")
  */
 public function getDashboardWorkspaceSpentTimesByWorkspace(User $user, Workspace $workspace)
 {
     $all = $user->getId() === $workspace->getCreator()->getId();
     $data = $this->dashboardManager->getDashboardWorkspaceSpentTimes($workspace, $user, $all);
     return new JsonResponse($data);
 }
예제 #3
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;
 }
예제 #4
0
 public function exportWorkspace(Workspace $workspace)
 {
     return ['id' => $workspace->getId(), 'guid' => $workspace->getGuid(), 'name' => $workspace->getName(), 'description' => $workspace->getDescription(), 'code' => $workspace->getCode(), 'maxStorageSize' => $workspace->getMaxStorageSize(), 'maxUploadResources' => $workspace->getMaxUploadResources(), 'maxUsers' => $workspace->getMaxUsers(), 'displayable' => $workspace->isDisplayable(), 'creatorId' => $workspace->getCreator()->getId(), 'selfRegistration' => $workspace->getSelfRegistration(), 'registrationValidation' => $workspace->getRegistrationValidation(), 'selfUnregistration' => $workspace->getSelfUnregistration(), 'creationDate' => $workspace->getCreationDate(), 'isPersonal' => $workspace->isPersonal(), 'startDate' => $workspace->getStartDate(), 'endDate' => $workspace->getEndDate(), 'isAccessDate' => $workspace->getIsAccessDate(), 'type' => $workspace->getWorkspaceType()];
 }