@param Workspace $workspace

@EXT\Route(
"/workspace/{workspace}/model/form",
name="claro_workspace_model_modal_form"
)

@EXT\Template("ClarolineCoreBundle:Tool\workspace\parameters\model:modelModalForm.html.twig")
18660
public function showModelModalFormAction(Workspace $workspace)
    {
        $this->checkAccess($workspace);
        $form = $this->formFactory->create(new ModelType(), new WorkspaceModel());
        $action = $this->router->generate('claro_workspace_model_create', array('workspace' => $workspace->getId()));

        return array(
            'form' => $form->createView(),
            'action' => $action,
            'title' => 'create_model'
        );
    }
619287
public function onDisplayWorkspace(DisplayToolEvent $event)
    {
        $workspace = $event->getWorkspace();

        $content = $this->templating->render(
            'ClarolineCoreBundle:workspace:users.html.twig', [
                'workspace' => $workspace,
                'restrictions' => [
                    'hasUserManagementAccess' => $this->authorization->isGranted('OPEN', $this->om
                        ->getRepository('ClarolineCoreBundle:Tool\AdminTool')
                        ->findOneBy(['name' => 'user_management'])
                    ),
                ],
            ]
        );

        $event->setContent($content);
        $event->stopPropagation();
    }
322434
public function workspaceWidgetHomeTabConfigDeleteAction(
        Workspace $workspace,
        WidgetHomeTabConfig $widgetHomeTabConfig
    )
    {
        $this->checkWorkspaceEditionAccess($workspace);
        $this->checkWorkspaceAccessForWidgetHomeTabConfig(
            $widgetHomeTabConfig,
            $workspace
        );
        $widgetInstance = $widgetHomeTabConfig->getWidgetInstance();
        $this->homeTabManager->deleteWidgetHomeTabConfig($widgetHomeTabConfig);

        if ($this->hasWorkspaceAccessToWidgetInstance($widgetInstance, $workspace)) {
            $this->widgetManager->removeInstance($widgetInstance);
        }

        return new Response('success', 204);
    }
1351688
public function addUserAction(Workspace $workspace, User $user)
    {
        $role = $this->roleManager->getCollaboratorRole($workspace);
        $userRoles = $this->roleManager->getWorkspaceRolesForUser($user, $workspace);

        if (count($userRoles) === 0) {
            $this->roleManager->associateRole($user, $role);
            $this->dispatcher->dispatch(
                'claroline_workspace_register_user',
                'WorkspaceAddUser',
                array($role, $user)
            );
        }

        $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
        $this->container->get('security.context')->setToken($token);

        return $user;
    }
1296790
public function openAction($workspaceId, Request $request)
    {
        /** @var Workspace $workspace */
        $workspace = $this->om->getObject(['id' => $workspaceId], Workspace::class);

        $this->assertIsGranted('OPEN', $workspace);
        $this->forceWorkspaceLang($workspace, $request);

        $options = $workspace->getOptions();
        if (!is_null($options)) {
            $details = $options->getDetails();

            if (isset($details['use_workspace_opening_resource']) &&
                $details['use_workspace_opening_resource'] &&
                isset($details['workspace_opening_resource']) &&
                !empty($details['workspace_opening_resource'])
            ) {
                $resourceNode = $this->resourceManager->getById($details['workspace_opening_resource']);

                if (!is_null($resourceNode)) {
                    $this->session->set('isDesktop', false);

                    return new RedirectResponse(
                        $this->router->generate('claro_resource_show', [
                            'id' => $resourceNode->getUuid(),
                            'type' => $resourceNode->getResourceType()->getName(),
                        ])
                    );
                }
            } elseif (isset($details['opening_type']) && 'tool' === $details['opening_type'] && isset($details['opening_target'])) {
                return new RedirectResponse(
                    $this->router->generate('claro_workspace_open_tool', [
                        'toolName' => $details['opening_target'],
                        'workspaceId' => $workspaceId,
                    ])
                );
            }
        }

        $tool = $this->workspaceManager->getFirstOpenableTool($workspace);
        //small hack for administrators otherwise they can't open it
        $toolName = $tool ? $tool->getName() : 'home';

        return new RedirectResponse(
            $this->router->generate('claro_workspace_open_tool', [
                'workspaceId' => $workspace->getId(),
                'toolName' => $toolName,
            ])
        );
    }
510209
public function shareModelUserListAction(WorkspaceModel $model)
    {
        $this->checkAccess($model->getWorkspace());

        return array(
            'model' => $model,
            'workspace' => $model->getWorkspace()
        );
    }
948551
public function copyFromCode(Workspace $workspace, $code)
    {
        if ($this->logger) {
            $this->container->get('claroline.api.serializer')->setLogger($this->logger);
        }

        $newWorkspace = new Workspace();
        $newWorkspace->setCode($code);
        $newWorkspace->setName($code);
        $this->copy($workspace, $newWorkspace);
        //override code & name

        return $newWorkspace;
    }
176168
public function exportUsers(Workspace $workspace, $format)
    {
        $this->checkEditionAccess($workspace);
        $exporter = $this->container->get('claroline.exporter.' . $format);
        $exporterManager = $this->container->get('claroline.manager.exporter_manager');
        $file = $exporterManager->export(
            'Claroline\CoreBundle\Entity\User',
            $exporter,
            array('workspace' => $workspace)
        );
        $response = new StreamedResponse();

        $response->setCallBack(
            function () use ($file) {
                readfile($file);
            }
        );

        $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
        $response->headers->set('Content-Type', 'application/force-download');
        $response->headers->set('Content-Disposition', 'attachment; filename=users.' . $format);

        switch ($format) {
            case 'csv': $response->headers->set('Content-Type', 'text/csv'); break;
            case 'xls': $response->headers->set('Content-Type', 'application/vnd.ms-excel'); break;
        }

        $response->headers->set('Connection', 'close');

        return $response;
    }
1223835
protected function createContext($workspaceName)
    {
        $contextProperties = [
            'workspaceName' => $workspaceName,
            'invisibleContentShown' => true,
            'inaccessibleContentShown' => true
        ];

        $currentDomain = $this->domainRepository->findOneByActiveRequest();

        if ($currentDomain !== null) {
            $contextProperties['currentSite'] = $currentDomain->getSite();
            $contextProperties['currentDomain'] = $currentDomain;
        } else {
            $contextProperties['currentSite'] = $this->siteRepository->findFirstOnline();
        }

        return $this->contextFactory->create($contextProperties);
    }
731282
public function userSubscriptionAction(Workspace $workspace, Request $request)
    {
        if (!$this->authorization->isGranted('IS_AUTHENTICATED_FULLY')) {
            throw new AccessDeniedException();
        }

        $user = $this->tokenStorage->getToken()->getUser();

        // If user is admin or registration validation is disabled, subscribe user
        if ($this->authorization->isGranted('ROLE_ADMIN') || !$workspace->getRegistrationValidation()) {
            $code = $request->query->get('_code');
            $user->setCode($code);
            $this->workspaceManager->addUserAction($workspace, $user);

            return new RedirectResponse(
                $this->router->generate('claro_workspace_open', [
                    'workspaceId' => $workspace->getId(),
                ])
            );
        }
        // Otherwise add user to validation queue if not already there
        if (!$this->workspaceManager->isUserInValidationQueue($workspace, $user)) {
            $this->workspaceManager->addUserQueue($workspace, $user);
        }

        $flashBag = $request->getSession()->getFlashBag();
        $flashBag->set('warning', $this->translator->trans('workspace_awaiting_validation', [], 'platform'));

        return new RedirectResponse(
            $this->router->generate('claro_desktop_open')
        );
    }
290357
public function setWorkspace(Workspace $workspace = null)
    {
        if ($this->workspace !== $workspace) {
            $this->workspace = $workspace;
            $this->addOrUpdate();
        }
    }
895295
public function updateAction(Workspace $workspace)
    {
        if ($workspace->getTitle() === '') {
            $workspace->setTitle($workspace->getName());
        }

        $this->workspaceRepository->update($workspace);
        $this->addFlashMessage($this->translator->translateById('workspaces.workspaceHasBeenUpdated', [$workspace->getTitle()], null, null, 'Modules', 'Neos.Neos'));
        $this->redirect('index');
    }
1282044
public function deleteWorkspace(Workspace $workspace)
    {
        // Log action
        $this->dispatcher->dispatch('log', 'Log\LogWorkspaceDelete', [$workspace]);

        $this->om->startFlushSuite();
        $roots = $this->om->getRepository(ResourceNode::class)->findBy(['workspace' => $workspace, 'parent' => null]);

        //in case 0 or multiple due to errors
        foreach ($roots as $root) {
            $this->log('Removing root directory '.$root->getName().'[id:'.$root->getId().']');
            $children = $root->getChildren();
            $this->log('Looping through '.count($children).' children...');

            if ($children) {
                foreach ($children as $node) {
                    $this->resourceManager->delete($node);
                }
            }
        }

        $tabs = $this->om->getRepository(HomeTab::class)->findBy(['workspace' => $workspace]);
        $crud = $this->container->get('claroline.api.crud');

        foreach ($tabs as $tab) {
            $crud->delete($tab);
        }

        $this->dispatcher->dispatch(
            'claroline_workspaces_delete',
            'GenericData',
            [[$workspace]]
        );
        $this->om->remove($workspace);
        $this->om->endFlushSuite();
    }
664384
public function indexAction(Workspace $workspace, User $user)
    {
        $isWorkspaceManager = $this->isWorkspaceManager($workspace, $user);
        $params = array();

        if ($isWorkspaceManager) {
            $params['_controller'] = 'ClarolineTeamBundle:Team:managerMenu';
            $params['workspace'] = $workspace->getId();
        } else {
            $params['_controller'] = 'ClarolineTeamBundle:Team:userMenu';
            $params['workspace'] = $workspace->getId();
        }
        $subRequest = $this->request->duplicate(array(), null, $params);
        $response = $this->httpKernel
            ->handle($subRequest, HttpKernelInterface::SUB_REQUEST);

        return $response;
    }
743662
public function deserialize(array $data, Workspace $workspace, array $options = [])
    {
        $this->sipe('code', 'setCode', $data, $workspace);
        $this->sipe('name', 'setName', $data, $workspace);

        if (isset($data['thumbnail']) && isset($data['thumbnail']['id'])) {
            $thumbnail = $this->om->getObject($data['thumbnail'], PublicFile::class);
            $workspace->setThumbnail($data['thumbnail']['url']);
            $this->fileUt->createFileUse($thumbnail, Workspace::class, $workspace->getUuid());
        }

        if (isset($data['poster']) && isset($data['poster']['id'])) {
            $poster = $this->om->getObject($data['thumbnail'], PublicFile::class);
            $workspace->setPoster($data['poster']['url']);
            $this->fileUt->createFileUse($poster, Workspace::class, $workspace->getUuid());
        }

        if (isset($data['extra']) && isset($data['extra']['model'])) {
            $model = $this->om->getRepository(Workspace::class)->findOneByCode($data['extra']['model']);
            $workspace->setWorkspaceModel($model);
        }

        //not sure if keep that. Might be troublesome later for rich texts
        if (!in_array(Options::REFRESH_UUID, $options)) {
            $this->sipe('uuid', 'setUuid', $data, $workspace);
        } else {
            $workspace->refreshUuid();
        }

        $this->sipe('meta.model', 'setModel', $data, $workspace);
        $this->sipe('meta.description', 'setDescription', $data, $workspace);
        $this->sipe('meta.lang', 'setLang', $data, $workspace);

        $this->sipe('notifications.enabled', 'setNotifications', $data, $workspace);

        $this->sipe('restrictions.hidden', 'setHidden', $data, $workspace);
        $this->sipe('restrictions.maxUsers', 'setMaxUsers', $data, $workspace);
        $this->sipe('restrictions.maxResources', 'setMaxUploadResources', $data, $workspace);
        $this->sipe('registration.validation', 'setRegistrationValidation', $data, $workspace);
        $this->sipe('registration.selfRegistration', 'setSelfRegistration', $data, $workspace);
        $this->sipe('registration.selfUnregistration', 'setSelfUnregistration', $data, $workspace);

        if (isset($data['registration']) && isset($data['registration']['defaultRole'])) {
            $defaultRole = $this->om->getObject($data['registration']['defaultRole'], Role::class);
            $workspace->setDefaultRole($defaultRole);
        }

        if (!empty($data['restrictions'])) {
            // TODO : store raw file size to avoid this
            if (isset($data['restrictions']['maxStorage'])) {
                $workspace->setMaxStorageSize(
                    $this->utilities->formatFileSize($data['restrictions']['maxStorage'])
                );
            }

            if (isset($data['restrictions']['dates'])) {
                $dateRange = DateRangeNormalizer::denormalize($data['restrictions']['dates']);

                $workspace->setStartDate($dateRange[0]);
                $workspace->setEndDate($dateRange[1]);
            }
        }

        $workspaceOptions = $workspace->getOptions();

        if (isset($data['display']) || isset($data['opening'])) {
            $details = $workspaceOptions->getDetails();

            if (empty($details)) {
                $details = [];
            }

            if (isset($data['display'])) {
                $details['background_color'] = !empty($data['display']['color']) ? $data['display']['color'] : null;
                $details['hide_tools_menu'] = isset($data['display']['showTools']) ? !$data['display']['showTools'] : true;
                $details['use_workspace_opening_resource'] = !empty($data['display']['openResource']);
                $details['workspace_opening_resource'] = !empty($data['display']['openResource']) && !empty($data['display']['openResource']['autoId']) ?
                    $data['display']['openResource']['autoId'] :
                    null;
            }
            if (isset($data['opening'])) {
                $details['opening_type'] = isset($data['opening']['type']) && isset($data['opening']['target']) && !empty($data['opening']['target']) ?
                    $data['opening']['type'] :
                    'tool';
                $details['opening_target'] = isset($data['opening']['target']) && !empty($data['opening']['target']) ?
                    $data['opening']['target'] :
                    'home';

                if ('resource' === $data['opening']['type'] && isset($data['opening']['target']['autoId'])) {
                    $details['workspace_opening_resource'] = $data['opening']['target']['autoId'];
                    $details['use_workspace_opening_resource'] = true;
                } else {
                    $details['workspace_opening_resource'] = null;
                    $details['use_workspace_opening_resource'] = false;
                }
            }
            $workspaceOptions->setDetails($details);
        }

        if (isset($data['breadcrumb'])) {
            if (isset($data['breadcrumb']['displayed'])) {
                $workspaceOptions->setShowBreadcrumb($data['breadcrumb']['displayed']);
            }

            if (isset($data['breadcrumb']['items'])) {
                $workspaceOptions->setBreadcrumbItems($data['breadcrumb']['items']);
            }
        }

        return $workspace;
    }
606466
private function getLogFile(Workspace $workspace)
    {
        $fs = new Filesystem();
        $fs->mkDir($this->logDir);

        return $this->logDir.DIRECTORY_SEPARATOR.$workspace->getCode().'.json';
    }
644603
public function urlSubscriptionGenerateAction(Workspace $workspace)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        if ( $user === 'anon.') {
            return $this->redirect(
                $this->generateUrl(
                    'claro_workspace_subscription_url_generate_anonymous',
                    array(
                        'workspace' => $workspace->getId(),
                        'toolName' => 'home'
                    )
                )
            );
        }

        $this->workspaceManager->addUserAction($workspace, $user);

        return $this->redirect(
            $this->generateUrl(
                'claro_workspace_open_tool', array('workspaceId' => $workspace->getId(), 'toolName' => 'home')
            )
        );
    }