@EXT\Route(
"/{workspace}/edit",
name="claro_workspace_edit"
)
@EXT\Method("POST")

@EXT\Template("ClarolineCoreBundle:Tool\workspace\parameters:workspaceEdit.html.twig")

@param Workspace $workspace

@return Response
777228
public function workspaceEditAction(Workspace $workspace)
    {
        if (!$this->authorization->isGranted('parameters', $workspace)) {
            throw new AccessDeniedException();
        }

        $wsRegisteredName = $workspace->getName();
        $wsRegisteredDisplayable = $workspace->isDisplayable();
        $workspaceAdminTool = $this->toolManager->getAdminToolByName('workspace_management');
        $isAdmin = $this->authorization->isGranted('OPEN', $workspaceAdminTool);
        $expDate = is_null($workspace->getCreationDate()) ? null : $this->utilities->intlDateFormat(
            $workspace->getEndDate()
        );
        $form = $this->formFactory->create(
            FormFactory::TYPE_WORKSPACE_EDIT,
            array(null, null, null, null, null, $isAdmin, $expDate),
            $workspace
        );
        $form->handleRequest($this->request);

        if ($form->isValid()) {
            $this->workspaceManager->editWorkspace($workspace);
            $this->workspaceManager->rename($workspace, $workspace->getName());
            $displayable = $workspace->isDisplayable();

            if (!$displayable && $displayable !== $wsRegisteredDisplayable) {
                $this->workspaceTagManager->deleteAllAdminRelationsFromWorkspace($workspace);
            }

            return $this->redirect(
                $this->generateUrl(
                    'claro_workspace_open_tool',
                    array(
                        'workspaceId' => $workspace->getId(),
                        'toolName' => 'parameters'
                    )
                )
            );
        } else {
            $workspace->setName($wsRegisteredName);
        }

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

        if ($workspace->getSelfRegistration()) {
            $url = $this->router->generate(
                'claro_workspace_subscription_url_generate',
                array('workspace' => $workspace->getId()),
                true
            );
        } else {
            $url = '';
        }

        return array(
            'form' => $form->createView(),
            'workspace' => $workspace,
            'url' => $url,
            'user' => $user
        );
    }
750259
private function getWorkspaceUsersIds(Workspace $workspace)
    {
        // Select all user(s) belonging to the target workspace (manager and collaborators)...
        $selectUsersIds = 'SELECT DISTINCT cur.user_id FROM claro_user_role cur JOIN claro_role cr ON cr.id = cur.role_id  WHERE cr.workspace_id = :wid';
        $idStmt = $this->em->getConnection()->prepare($selectUsersIds);
        $idStmt->bindValue('wid', $workspace->getId());
        $idStmt->execute();
        $idResults = $idStmt->fetchAll();
        foreach ($idResults as $result) {
            $ids[] = $result['user_id'];
        }

        return $ids;
    }
415602
public function serialize(Workspace $workspace)
    {
        $serialized = $this->serializer->serialize($workspace, [Options::REFRESH_UUID]);

        //if roles duplicatas, remove them
        $roles = $serialized['roles'];

        foreach ($roles as $role) {
            $uniques[$role['translationKey']] = ['type' => $role['type']];
        }

        $roles = [];
        foreach ($uniques as $key => $val) {
            $val['translationKey'] = $key;
            $roles[] = $val;
        }

        $serialized['roles'] = $roles;

        //we want to load  the ressources first
        $ot = $workspace->getOrderedTools()->toArray();

        $idx = 0;

        foreach ($ot as $key => $tool) {
            if ('resource_manager' === $tool->getName()) {
                $idx = $key;
            }
        }

        $first = $ot[$idx];
        unset($ot[$idx]);
        array_unshift($ot, $first);

        $serialized['orderedTools'] = array_map(function (OrderedTool $tool) {
            $data = $this->ots->serialize($tool, [Options::SERIALIZE_TOOL, Options::REFRESH_UUID]);

            return $data;
        }, $ot);

        return $serialized;
    }
573045
public function workspaceToolsRolesAction(Workspace $workspace)
    {
        $this->checkAccess($workspace);
        $toolsDatas = $this->toolManager->getWorkspaceToolsConfigurationArray($workspace);
        $pwsToolConfigs = $this->toolManager->getPersonalWorkspaceToolConfigForCurrentUser();

        return array(
            'roles' => $this->roleManager->getWorkspaceConfigurableRoles($workspace),
            'workspace' => $workspace,
            'toolPermissions' => $toolsDatas['existingTools'],
            'maskDecoders' => $toolsDatas['maskDecoders'],
            'pwsToolConfigs' => $pwsToolConfigs
        );
    }
598530
public function workspaceDisplayEditAction(Workspace $workspace)
    {
        $this->checkAccess($workspace);
        $workspaceOptions = $this->workspaceManager->getWorkspaceOptions($workspace);
        $details = $workspaceOptions->getDetails();
        $form = $this->formFactory->create(new WorkspaceOptionsType($workspaceOptions));
        $form->handleRequest($this->request);

        if ($form->isValid()) {
            $color = $form->get('backgroundColor')->getData();
            $hideToolsMenu = $form->get('hideToolsMenu')->getData();
            $hideBreadcrumb = $form->get('hideBreadcrumb')->getData();
            $useDefaultResource = $form->get('useWorkspaceOpeningResource')->getData();
            $defaultResource = $form->get('workspaceOpeningResource')->getData();
            $details['background_color'] = $color;
            $details['hide_tools_menu'] = $hideToolsMenu;
            $details['hide_breadcrumb'] = $hideBreadcrumb;
            $details['use_workspace_opening_resource'] = $useDefaultResource;
            $details['workspace_opening_resource'] = empty($defaultResource) ?
                null :
                $defaultResource->getId();
            $workspaceOptions->setDetails($details);
            $this->workspaceManager->persistworkspaceOptions($workspaceOptions);

            return new RedirectResponse(
                $this->router->generate(
                    'claro_workspace_open_tool',
                    array('workspaceId' => $workspace->getId(), 'toolName' => 'parameters')
                )
            );
        } else {

            return array(
                'form' => $form->createView(),
                'workspace' => $workspace
            );
        }
    }
524048
public function findPersonalUser(Workspace $workspace)
    {
        $user = $this->userRepo->findBy(array('personalWorkspace' => $workspace));

        return (count($user) === 1) ? $user[0]: null;
    }
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;
    }
32625
public function renderToolListAction(Workspace $workspace, $_breadcrumbs)
    {
        //first we add check if some tools will be missing from the navbar and we add them if necessary
        //lets be sure we loaded everything properly because the pathbundle broke something
        $workspace = $this->workspaceManager->getWorkspaceByCode($workspace->getCode());
        $this->toolManager->addMissingWorkspaceTools($workspace);

        if ($_breadcrumbs != null) {
            //for manager.js, id = 0 => "no root".
            if ($_breadcrumbs[0] != 0) {
                $rootId = $_breadcrumbs[0];
            } else {
                $rootId = $_breadcrumbs[1];
            }
            $workspace = $this->resourceManager->getNode($rootId)->getWorkspace();
        }

        $currentRoles = $this->utils->getRoles($this->tokenStorage->getToken());
        //do I need to display every tools.
        $hasManagerAccess = false;
        $managerRole = $this->roleManager->getManagerRole($workspace);

        foreach ($currentRoles as $role) {
            if ($managerRole->getName() === $role) {
                $hasManagerAccess = true;
            }
        }

        if ($this->authorization->isGranted('ROLE_ADMIN')) {
            $hasManagerAccess = true;
        }

        //if manager or admin, show every tools
        if ($hasManagerAccess) {
            $orderedTools = $this->toolManager->getOrderedToolsByWorkspace($workspace);
            $hideToolsMenu = false;
        } else {
            //otherwise only shows the relevant tools
            $orderedTools = $this->toolManager->getOrderedToolsByWorkspaceAndRoles($workspace, $currentRoles);
            $hideToolsMenu = $this->workspaceManager->isToolsMenuHidden($workspace);
        }
        $roleHasAccess = array();
        $workspaceRolesWithAccess = $this->roleManager
            ->getWorkspaceRoleWithToolAccess($workspace);

        foreach ($workspaceRolesWithAccess as $workspaceRole) {
            $roleHasAccess[$workspaceRole->getId()] = $workspaceRole;
        }

        return array(
            'hasManagerAccess' => $hasManagerAccess,
            'orderedTools' => $orderedTools,
            'workspace' => $workspace,
            'roleHasAccess' => $roleHasAccess,
            'hideToolsMenu' => $hideToolsMenu
        );
    }
1104678
public function countByWorkspace(Workspace $workspace)
    {
        $query = $this->createQuery();
        $nodesInDatabase = $query->matching($query->equals('workspace', $workspace))->execute()->count();

        $nodesInMemory = 0;
        /** @var $node NodeData */
        foreach ($this->addedNodes as $node) {
            if ($node->getWorkspace()->getName() === $workspace->getName()) {
                $nodesInMemory++;
            }
        }

        return $nodesInDatabase + $nodesInMemory;
    }
1167624
public function getParametersByWorkspace(
        Workspace $workspace,
        $executeQuery = true
    )
    {
        return $this->workspaceTeamParamsRepo->findParametersByWorkspace(
            $workspace,
            $executeQuery
        );
    }
113934
public function adminWorkspaceTagCreateAction()
    {
        if (!$this->authorization->isGranted('ROLE_ADMIN')) {
            throw new AccessDeniedException();
        }
        $workspaceTag = new WorkspaceTag();

        $form = $this->formFactory->create(
            FormFactory::TYPE_ADMIN_WORKSPACE_TAG,
            array(),
            $workspaceTag
        );
        $request = $this->getRequest();
        $form->handleRequest($request);

        if ($form->isValid()) {
            $this->tagManager->insert($workspaceTag);
            $this->tagManager->createTagHierarchy($workspaceTag, $workspaceTag, 0);

            return new Response($workspaceTag->getId(), 201);
        }

        return array('form' => $form->createView());
    }
686366
public function renameModelAction(WorkspaceModel $model)
    {
        $this->checkAccess($model->getWorkspace());
        $oldName = $model->getName();
        $form = $this->formFactory->create(new ModelType(), $model);
        $form->handleRequest($this->request);

        if ($form->isValid()) {
            $model = $this->modelManager->edit($model, $form->get('name')->getData());

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

        $action = $this->router->generate('claro_workspace_model_rename', array('model' => $model->getId()));

        return $this->render(
            'ClarolineCoreBundle:Tool\workspace\parameters\model:modelModalForm.html.twig',
            array('form' => $form->createView(), 'action' => $action, 'title' => 'rename')
        );
    }
1039895
public function findWorkspaceRolesForUser(User $user, Workspace $workspace)
    {
        $dql = "
            SELECT r FROM Claroline\CoreBundle\Entity\Role r
            JOIN r.workspace ws
            JOIN r.users user
            WHERE ws.guid = '{$workspace->getGuid()}'
            AND r.name != 'ROLE_ADMIN'
            AND user.id = {$user->getId()}
        ";

        $query = $this->_em->createQuery($dql);

        return $query->getResult();
    }
859805
public function openDeniedAction(Workspace $workspace, $action)
    {
        $user = $this->tokenStorage->getToken()->getUser();

        //check the expiration date first
        $now = new \DateTime();
        $dateValidity = true;

        if ($workspace->getEndDate()) {
            if ($now->getTimeStamp() > $workspace->getEndDate()->getTimeStamp()) {
                $dateValidity = false;
            }
        }

        if ($workspace->getStartDate()) {
            if ($now->getTimeStamp() < $workspace->getStartDate()->getTimeStamp()) {
                $dateValidity = false;
            }
        }

        return [
          'workspace' => $workspace,
          'action' => $action,
          'dateValidity' => $dateValidity,
          'isInQueue' => $this->workspaceManager->isUserInValidationQueue($workspace, $user),
        ];
    }
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);
    }
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);
    }
820003
public function onWorkspaceToolOpen(DisplayToolEvent $event)
    {
        $workspace = $event->getWorkspace();

        if (!$this->authorization->isGranted(['claroline_planned_notification_tool', 'OPEN'], $workspace)) {
            throw new AccessDeniedException();
        }
        $content = $this->templating->render(
            'ClarolinePlannedNotificationBundle:planned_notification_tool:tool_open.html.twig', [
                'workspace' => $workspace,
                'canEdit' => $this->authorization->isGranted(['claroline_planned_notification_tool', 'EDIT'], $workspace),
            ]
        );
        $event->setContent($content);
        // /    $event->stopPropagation();
    }