Create a workspace

@param string $workspaceName
@param Workspace $baseWorkspace
@param string $ownerAccountIdentifier
@return string
765729
public function createAction($workspaceName, Workspace $baseWorkspace, $ownerAccountIdentifier = null)
    {
        $existingWorkspace = $this->workspaceRepository->findByIdentifier($workspaceName);
        if ($existingWorkspace !== null) {
            $this->throwStatus(409, 'Workspace already exists', '');
        }

        if ($ownerAccountIdentifier !== null) {
            $owner = $this->userService->getUser($ownerAccountIdentifier);
            if ($owner === null) {
                $this->throwStatus(422, 'Requested owner account does not exist', '');
            }
        } else {
            $owner = null;
        }

        $workspace = new Workspace($workspaceName, $baseWorkspace, $owner);
        $this->workspaceRepository->add($workspace);
        $this->throwStatus(201, 'Workspace created', '');
    }
1154861
public function teamCreateFormAction(Workspace $workspace, User $user)
    {
        $this->checkWorkspaceManager($workspace, $user);
        $params = $this->teamManager->getParametersByWorkspace($workspace);
        $team = new Team();
        $team->setIsPublic($params->getIsPublic());
        $team->setSelfRegistration($params->getSelfRegistration());
        $team->setSelfUnregistration($params->getSelfUnregistration());

        $form = $this->formFactory->create(new TeamType(), $team);

        return array(
            'form' => $form->createView(),
            'workspace' => $workspace
        );
    }
771233
public function importInExistingWorkspace(Configuration $configuration, Workspace $workspace)
    {
        $root = $this->resourceManager->getResourceFromNode($this->resourceManager->getWorkspaceRoot($workspace));
        $wsRoles = $this->roleManager->getRolesByWorkspace($workspace);
        $entityRoles = [];

        foreach ($wsRoles as $wsRole) {
            $entityRoles[$this->roleManager->getWorkspaceRoleBaseName($wsRole)] = $wsRole;
        }

        $workspace = $this->container->get('claroline.manager.transfert_manager')->importResources(
            $configuration,
            $workspace->getCreator(),
            $root->getResourceNode()
        );

        $this->importRichText();

        return $workspace;
    }
627352
public function setBaseWorkspace(Workspace $workspace)
    {
        $userWorkspace = $this->userService->getPersonalWorkspace();
        $userWorkspace->setBaseWorkspace($workspace);
    }
1069499
protected function collectWorkspaceAndAllBaseWorkspaces(Workspace $workspace)
    {
        $workspaces = [];
        while ($workspace !== null) {
            $workspaces[] = $workspace;
            $workspace = $workspace->getBaseWorkspace();
        }

        return $workspaces;
    }
205750
public function registerAndRedirect(Workspace $workspace, Request $request)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        if ($workspace->getSelfRegistration()) {
            if ($workspace->getRegistrationValidation()) {
                $this->workspaceManager->addUserQueue($workspace, $user);
            } else {
                $this->workspaceManager->addUserAction($workspace, $user);
            }

            return $this->openAction($workspace->getId(), $request);
        } else {
            throw new \Exception('No self registration allowed');
        }
    }
1287490
public function create($containerOrName, array $data = [])
    {
        // Check if parent or name is defined
        if (!(
            $containerOrName instanceof Model\ContainerInterface ||
            (is_string($containerOrName) && 0 < strlen($containerOrName))
        )
        ) {
            throw new InvalidOperationException("Excepted instance of ContainerInterface or string.");
        }

        // New instance
        $row = $this->editor->getRepository()->createRow();

        // Create default block
        $this->editor->getBlockManager()->create($row);

        // Add to row if available
        if ($containerOrName instanceof Model\ContainerInterface) {
            $count = $containerOrName->getRows()->count();
            $row->setPosition($count);
            $containerOrName->addRow($row);
        } else {
            $row->setName($containerOrName);
        }

        return $row;
    }
456551
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', array(), 'platform') . ' - ' . $user->getUsername();

        if (!$model) {
            $config = Configuration::fromTemplate($this->personalWsTemplateFile);
            $config->setWorkspaceName($personalWorkspaceName);
            $config->setWorkspaceCode($code);
            $workspace = $this->transfertManager->createWorkspace($config, $user, true);
        } else {
            $workspace = $this->workspaceManager->createWorkspaceFromModel(
                $model,
                $user,
                $personalWorkspaceName,
                $user->getUsername(),
                '',
                false,
                false,
                false,
                $errors
            );
        }

        //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();
    }
528529
public function createRoom($ownerId, $roomName = null)
    {
        $params['owner_id'] = $ownerId;
        if (!empty($roomName)) {
            $params['room_name'] = $roomName;
        }
        $body = json_encode($params);
        try {
            $ret = $this->_transport->send(HttpRequest::POST, $this->_baseURL, $body);
        } catch (\Exception $e) {
            return $e;
        }
        return $ret;
    }
1094640
public function rebaseAndRedirectAction(NodeInterface $targetNode, Workspace $targetWorkspace)
    {
        $currentAccount = $this->securityContext->getAccount();
        $personalWorkspace = $this->workspaceRepository->findOneByName(UserUtility::getPersonalWorkspaceNameForUsername($currentAccount->getAccountIdentifier()));
        /** @var Workspace $personalWorkspace */

        if ($personalWorkspace !== $targetWorkspace) {
            if ($this->publishingService->getUnpublishedNodesCount($personalWorkspace) > 0) {
                $message = $this->translator->translateById('workspaces.cantEditBecauseWorkspaceContainsChanges', [], null, null, 'Modules', 'Neos.Neos');
                $this->addFlashMessage($message, '', Message::SEVERITY_WARNING, [], 1437833387);
                $this->redirect('show', null, null, ['workspace' => $targetWorkspace]);
            }

            $personalWorkspace->setBaseWorkspace($targetWorkspace);
            $this->workspaceRepository->update($personalWorkspace);
        }

        $contextProperties = $targetNode->getContext()->getProperties();
        $contextProperties['workspaceName'] = $personalWorkspace->getName();
        $context = $this->contextFactory->create($contextProperties);

        $mainRequest = $this->controllerContext->getRequest()->getMainRequest();
        /** @var ActionRequest $mainRequest */
        $this->uriBuilder->setRequest($mainRequest);

        if ($this->packageManager->isPackageAvailable('Neos.Neos.Ui')) {
            $this->redirect('index', 'Backend', 'Neos.Neos.Ui', ['node' => $context->getNode($targetNode->getPath())]);
        }

        $this->redirect('show', 'Frontend\\Node', 'Neos.Neos', ['node' => $context->getNode($targetNode->getPath())]);
    }
723344
public function findWorkspaceRoot(Workspace $workspace)
    {
        $builder = new ResourceQueryBuilder();
        $builder->selectAsEntity()
            ->whereInWorkspace($workspace)
            ->whereParentIsNull();
        $query = $this->_em->createQuery($builder->getDql());
        $query->setParameters($builder->getParameters());

        return $query->getOneOrNullResult();
    }
42901
public function createModelAction(Workspace $workspace)
    {
        $this->checkAccess($workspace);
        $model = new WorkspaceModel();
        $model->setWorkspace($workspace);
        $form = $this->formFactory->create(new ModelType(), $model);
        $form->handleRequest($this->request);

        if ($form->isValid()) {
            $model = $this->modelManager->create($model->getName(), $workspace);

            return new JsonResponse(
                array(
                    'name' => $model->getName(),
                    'id' => $model->getId()
                )
            );
        }

        $action = $this->router->generate('claro_workspace_model_create', array('workspace' => $workspace->getId()));

        return $this->render(
            'ClarolineCoreBundle:Tool\workspace\parameters\model:modelModalForm.html.twig',
            array(
                'form' => $form->createView(),
                'action' => $action,
                'title' => 'create_model'
            )
        );
    }
786050
public function createMultipleTeams(Workspace $workspace, User $user, array $data)
    {
        $this->om->startFlushSuite();
        $teams = [];
        $nodes = [];
        $index = 1;
        $nbTeams = isset($data['nbTeams']) ? $data['nbTeams'] : 0;
        $name = isset($data['name']) ? $data['name'] : '';
        $description = isset($data['description']) ? $data['description'] : null;
        $selfRegistration = isset($data['selfRegistration']) ? $data['selfRegistration'] : false;
        $selfUnregistration = isset($data['selfUnregistration']) ? $data['selfUnregistration'] : false;
        $publicDirectory = isset($data['publicDirectory']) ? $data['publicDirectory'] : false;
        $deletableDirectory = isset($data['deletableDirectory']) ? $data['deletableDirectory'] : false;
        $maxUsers = isset($data['maxUsers']) ? $data['maxUsers'] : null;

        for ($i = 0; $i < $nbTeams; ++$i) {
            $team = new Team();
            $validName = $this->computeValidTeamName($workspace, $name, $index);
            $team->setName($validName['name']);
            $index = $validName['index'] + 1;
            $team->setWorkspace($workspace);
            $team->setDescription($description);
            $team->setMaxUsers($maxUsers);
            $team->setSelfRegistration($selfRegistration);
            $team->setSelfUnregistration($selfUnregistration);
            $team->setIsPublic($publicDirectory);
            $team->setDirDeletable($deletableDirectory);

            // Creates team role
            $teamRole = $this->createTeamRole($team);
            $teamRole->setMaxUsers($maxUsers);
            $team->setRole($teamRole);
            $this->om->persist($teamRole);

            // Creates team manager role
            $teamManagerRole = $this->createTeamRole($team, true);
            $team->setTeamManagerRole($teamManagerRole);

            // Creates team directory
            $defaultResource = isset($data['defaultResource']['id']) ?
                $this->resourceNodeRepo->findOneBy(['uuid' => $data['defaultResource']['id']]) :
                null;
            $creatableResources = isset($data['creatableResources']) ?
                $data['creatableResources'] :
                [];
            $directory = $this->createTeamDirectory(
                $team,
                $user,
                $defaultResource,
                $creatableResources
            );
            $team->setDirectory($directory);
            $this->om->persist($team);

            $node = $team->getDirectory()->getResourceNode();
            $node->setIndex(1);
            $this->om->persist($node);
            $teams[] = $team;
            $nodes[] = $node;
        }
        $this->linkResourceNodesArray($workspace, $nodes);
        $this->om->forceFlush();

        foreach ($teams as $team) {
            $this->initializeTeamRights($team);
        }
        $this->om->endFlushSuite();
    }
493944
public function addWorkspaceName(JoinPointInterface $joinPoint)
    {
        $tags = $joinPoint->getAdviceChain()->proceed($joinPoint);

        $values = $joinPoint->getMethodArgument('routeValues');

        if (isset($values['node']) && strpos($values['node'], '@') !== false) {
            // Build context explicitly without authorization checks because the security context isn't available yet
            // anyway and any Entity Privilege targeted on Workspace would fail at this point:
            $this->securityContext->withoutAuthorizationChecks(function () use ($values, &$tags) {
                $contextPathPieces = NodePaths::explodeContextPath($values['node']);
                $tags[] = $contextPathPieces['workspaceName'];
            });
        }
        return $tags;
    }
1057713
public function findByWorkspaceWithUsersFromGroup(Workspace $workspace, $executeQuery = true)
    {
        $dql = '
            SELECT u
            FROM Claroline\CoreBundle\Entity\User u
            JOIN u.roles ur
            LEFT JOIN u.groups g
            LEFT JOIN g.roles gr
            LEFT JOIN gr.workspace grws
            LEFT JOIN ur.workspace uws
            WHERE (uws.id = :wsId
            OR grws.id = :wsId)
            AND u.isRemoved = false
         ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('wsId', $workspace->getId());

        return $executeQuery ? $query->getResult() : $query;
    }
1035020
public function findUsersByWorkspaces(array $workspaces, $executeQuery = true)
    {
        $dql = '
            SELECT DISTINCT u FROM Claroline\CoreBundle\Entity\User u
            JOIN u.roles wr
            LEFT JOIN u.groups g
            LEFT JOIN g.roles gr
            LEFT JOIN gr.workspace gw
            LEFT JOIN wr.workspace w
            WHERE (
              w IN (:workspaces) OR
              gw IN (:workspaces)
            )
            AND u.isEnabled = true
            ORDER BY u.id
        ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('workspaces', $workspaces);

        return $executeQuery ? $query->getResult() : $query;
    }
1002338
public function findRootJobByOwnerIdAndJobName($ownerId, $jobName)
    {
        return $this->createJobQueryBuilder('job')
            ->where('job.ownerId = :ownerId AND job.name = :jobName')
            ->andWhere('job.rootJob is NULL')
            ->setParameter('ownerId', $ownerId)
            ->setParameter('jobName', $jobName)
            ->getQuery()
            ->getOneOrNullResult();
    }