@EXT\Route(
"/export/users/{format}/workspace/{workspace}",
name="claro_workspace_export_users"
)

@return Response
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;
    }
661930
public static function routes()
    {
        $middleware = [ CreateDefaultFolder::class, MultiUser::class ];
        $as = 'unisharp.lfm.';
        $namespace = '\\UniSharp\\LaravelFilemanager\\Controllers\\';

        Route::group(compact('middleware', 'as', 'namespace'), function () {

            // display main layout
            Route::get('/', [
                'uses' => 'LfmController@show',
                'as' => 'show',
            ]);

            // display integration error messages
            Route::get('/errors', [
                'uses' => 'LfmController@getErrors',
                'as' => 'getErrors',
            ]);

            // upload
            Route::any('/upload', [
                'uses' => 'UploadController@upload',
                'as' => 'upload',
            ]);

            // list images & files
            Route::get('/jsonitems', [
                'uses' => 'ItemsController@getItems',
                'as' => 'getItems',
            ]);

            Route::get('/move', [
                'uses' => 'ItemsController@move',
                'as' => 'move',
            ]);

            Route::get('/domove', [
                'uses' => 'ItemsController@domove',
                'as' => 'domove'
            ]);

            // folders
            Route::get('/newfolder', [
                'uses' => 'FolderController@getAddfolder',
                'as' => 'getAddfolder',
            ]);

            // list folders
            Route::get('/folders', [
                'uses' => 'FolderController@getFolders',
                'as' => 'getFolders',
            ]);

            // crop
            Route::get('/crop', [
                'uses' => 'CropController@getCrop',
                'as' => 'getCrop',
            ]);
            Route::get('/cropimage', [
                'uses' => 'CropController@getCropimage',
                'as' => 'getCropimage',
            ]);
            Route::get('/cropnewimage', [
                'uses' => 'CropController@getNewCropimage',
                'as' => 'getCropimage',
            ]);

            // rename
            Route::get('/rename', [
                'uses' => 'RenameController@getRename',
                'as' => 'getRename',
            ]);

            // scale/resize
            Route::get('/resize', [
                'uses' => 'ResizeController@getResize',
                'as' => 'getResize',
            ]);
            Route::get('/doresize', [
                'uses' => 'ResizeController@performResize',
                'as' => 'performResize',
            ]);

            // download
            Route::get('/download', [
                'uses' => 'DownloadController@getDownload',
                'as' => 'getDownload',
            ]);

            // delete
            Route::get('/delete', [
                'uses' => 'DeleteController@getDelete',
                'as' => 'getDelete',
            ]);

            Route::get('/demo', 'DemoController@index');
        });
    }
1035137
public function bindWorkspaceToOrganization()
    {
        $limit = 250;
        $offset = 0;
        $organizationManager = $this->container->get('claroline.manager.organization.organization_manager');
        $this->log('Add organizations to workspaces...');
        $this->om->startFlushSuite();
        $countWorkspaces = $this->om->count('ClarolineCoreBundle:Workspace\Workspace');

        while ($offset < $countWorkspaces) {
            //if there is too many workspaces, we retrieve them by small amounts
            $workspaces = $this->workspaceRepo->findBy([], null, $limit, $offset);
            $default = $organizationManager->getDefault();
            $this->om->merge($default);

            foreach ($workspaces as $workspace) {
                if (0 === count($workspace->getOrganizations())) {
                    $this->log('Add default organization for workspace '.$workspace->getCode());
                    $workspace->addOrganization($default);
                    $this->om->persist($workspace);
                } else {
                    $this->log('Organization already exists for workspace '.$workspace->getCode());
                }
            }

            $this->log("Flushing... [UOW = {$this->om->getUnitOfWork()->size()}]");
            $this->om->forceFlush();
            $this->om->clear();

            $offset += $limit;
        }

        $this->om->endFlushSuite();
    }
469712
public function export()
    {
        $this->loadModel('User.Acos');
        $out = [];
        $permissions = $this->Acos->Permissions
            ->find()
            ->contain(['Acos', 'Roles'])
            ->all();

        foreach ($permissions as $permission) {
            if (!isset($out[$permission->role->slug])) {
                $out[$permission->role->slug] = [];
            }
            $out[$permission->role->slug][] = implode(
                '/',
                $this->Acos
                ->find('path', ['for' => $permission->aco->id])
                ->extract('alias')
                ->toArray()
            );
        }

        $this->title(__d('user', 'Export Permissions'));
        $this->response->body(json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
        $this->response->type('json');
        $this->response->download('permissions_' . date('Y-m-d@H:i:s-\U\TC', time()) . '.json');

        return $this->response;
    }
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
            );
        }
    }
1060345
public function menuAction()
    {
        $workspaces = [];
        $personalWs = null;

        $user = null;
        $token = $this->tokenStorage->getToken();
        if ($token) {
            $user = $token->getUser();
        }

        if ($user instanceof User) {
            $personalWs = $user->getPersonalWorkspace();
            $workspaces = $this->workspaceManager->getRecentWorkspaceForUser($user, $this->utils->getRoles($token));
        }

        return new JsonResponse([
            'creatable' => $this->authorization->isGranted('CREATE', new Workspace()),
            'personal' => $personalWs ? $this->serializer->serialize($personalWs, [Options::SERIALIZE_MINIMAL]) : null,
            'history' => array_map(function (Workspace $workspace) {
                return $this->serializer->serialize($workspace, [Options::SERIALIZE_MINIMAL]);
            }, $workspaces),
        ]);
    }
327234
public function listAction()
    {
        $request = $this->getRequest();

        $this->admin->checkAccess('list');

        $preResponse = $this->preList($request);
        if (null !== $preResponse) {
            return $preResponse;
        }

        if ($listMode = $request->get('_list_mode')) {
            $this->admin->setListMode($listMode);
        }

        $datagrid = $this->admin->getDatagrid();
        $formView = $datagrid->getForm()->createView();

        // set the theme for the current Admin Form
        $this->setFormTheme($formView, $this->admin->getFilterTheme());

        // NEXT_MAJOR: Remove this line and use commented line below it instead
        $template = $this->admin->getTemplate('list');
        // $template = $this->templateRegistry->getTemplate('list');

        return $this->renderWithExtraParams($template, [
            'action' => 'list',
            'form' => $formView,
            'datagrid' => $datagrid,
            'csrf_token' => $this->getCsrfToken('sonata.batch'),
            'export_formats' => $this->has('sonata.admin.admin_exporter') ?
                $this->get('sonata.admin.admin_exporter')->getAvailableFormats($this->admin) :
                $this->admin->getExportFormats(),
        ], null);
    }
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;
    }
1296287
public function getWorkspaceRolesForUser(User $user, Workspace $workspace)
    {
        return $this->roleRepo->findWorkspaceRolesForUser($user, $workspace);
    }
57693
public function createWorkspace(Workspace $workspace)
    {
        if (0 === count($workspace->getOrganizations())) {
            if (
                $this->container->get('security.token_storage')->getToken() &&
                $this->container->get('security.token_storage')->getToken()->getUser() instanceof User &&
                $this->container->get('security.token_storage')->getToken()->getUser()->getMainOrganization()
            ) {
                //we want a min organization
                $workspace->addOrganization($this->container->get('security.token_storage')->getToken()->getUser()->getMainOrganization());
                $this->om->persist($workspace);
                $this->om->flush();
            } else {
                $organizationManager = $this->container->get('claroline.manager.organization.organization_manager');
                $default = $organizationManager->getDefault();
                $workspace->addOrganization($default);
            }
        }

        $ch = $this->container->get('claroline.config.platform_config_handler');
        $workspace->setMaxUploadResources($ch->getParameter('max_upload_resources'));
        $workspace->setMaxStorageSize($ch->getParameter('max_storage_size'));
        $workspace->setMaxUsers($ch->getParameter('max_workspace_users'));
        $this->editWorkspace($workspace);

        return $workspace;
    }
1143824
public function serialize(Workspace $workspace, array $options = [])
    {
        $serialized = [
            'name' => $workspace->getName(),
            'code' => $workspace->getCode(),
            'thumbnail' => $workspace->getThumbnail() && $this->om->getRepository(PublicFile::class)->findOneBy([
                  'url' => $workspace->getThumbnail(),
              ]) ? $this->publicFileSerializer->serialize($this->om->getRepository(PublicFile::class)->findOneBy([
                  'url' => $workspace->getThumbnail(),
              ])
            ) : null,
            'poster' => $workspace->getPoster() && $this->om->getRepository(PublicFile::class)->findOneBy([
                  'url' => $workspace->getPoster(),
              ]) ? $this->publicFileSerializer->serialize(
                $this->om->getRepository(PublicFile::class)->findOneBy([
                    'url' => $workspace->getPoster(),
              ])
            ) : null,
            'permissions' => [ // TODO it will decrease perfs, should be tested, but it is required in lists
                'open' => $this->authorization->isGranted('OPEN', $workspace),
                'delete' => $this->authorization->isGranted('DELETE', $workspace),
                'configure' => $this->authorization->isGranted('EDIT', $workspace),
                'administrate' => $this->authorization->isGranted('EDIT', $workspace),
                'export' => $this->authorization->isGranted('EXPORT', $workspace),
            ],
        ];

        if (!in_array(Options::REFRESH_UUID, $options)) {
            $serialized['uuid'] = $workspace->getUuid();
            $serialized['id'] = $workspace->getId(); // TODO : remove me
        } else {
            $serialized['uuid'] = $this->getUuid($workspace, $options);
        }

        if (!in_array(Options::SERIALIZE_MINIMAL, $options)) {
            $serialized = array_merge($serialized, [
                'registered' => $this->isRegistered($workspace),
                'meta' => $this->getMeta($workspace, $options),
                'opening' => $this->getOpening($workspace),
                'display' => $this->getDisplay($workspace),
                'breadcrumb' => $this->getBreadcrumb($workspace),
                'restrictions' => $this->getRestrictions($workspace),
                'registration' => $this->getRegistration($workspace, $options),
                'notifications' => $this->getNotifications($workspace),
            ]);

            if (!in_array(Options::SERIALIZE_LIST, $options)) {
                if (in_array(Options::REFRESH_UUID, $options)) {
                    $serialized['roles'] = array_map(function (Role $role) {
                        return [
                          'translationKey' => $role->getTranslationKey(),
                          'type' => $role->getType(),
                        ];
                    }, array_values(array_unique(array_merge($this->workspaceManager->getRolesWithAccess($workspace), $workspace->getRoles()->toArray()))));
                } else {
                    $serialized['roles'] = array_map(function (Role $role) {
                        return [
                            'id' => $role->getUuid(),
                            'name' => $role->getName(),
                            'type' => $role->getType(), // TODO : should be a string for better data readability
                            'translationKey' => $role->getTranslationKey(),
                        ];
                    }, array_values(array_unique(array_merge($this->workspaceManager->getRolesWithAccess($workspace), $workspace->getRoles()->toArray()))));
                }

                $serialized['managers'] = array_map(function (User $manager) {
                    return $this->userSerializer->serialize($manager, [Options::SERIALIZE_MINIMAL]);
                }, $this->workspaceManager->getManagers($workspace));
                $serialized['organizations'] = array_map(function ($organization) {
                    return $this->orgaSerializer->serialize($organization);
                }, $workspace->getOrganizations()->toArray());
            }
        }

        // maybe do the same for users one day
        if (in_array(Options::WORKSPACE_FETCH_GROUPS, $options)) {
            $groups = $this->om
                ->getRepository(Group::class)
                ->findByWorkspace($workspace);

            $serialized['groups'] = array_map(function (Group $group) {
                return [
                  'id' => $group->getUuid(),
                  'name' => $group->getName(),
                ];
            }, $groups);
        }

        return $serialized;
    }
118064
public function findUsersOwnersOfMostWorkspaces($max, $organizations = null)
    {
        $orgasJoin = '';
        $orgasCondition = '';
        if (null !== $organizations) {
            $orgasJoin = 'JOIN ws.organizations orgas';
            $orgasCondition = 'AND orgas IN (:organizations)';
        }

        $dql = "
            SELECT CONCAT(CONCAT(u.firstName,' '), u.lastName) AS name, u.username, COUNT(DISTINCT ws.id) AS total
            FROM Claroline\CoreBundle\Entity\Workspace\Workspace ws
            JOIN ws.creator u
            ${orgasJoin}
            WHERE u.isRemoved = false
            ${orgasCondition}
            GROUP BY u.id
            ORDER BY total DESC
        ";
        $query = $this->_em->createQuery($dql);

        if (null !== $organizations) {
            $query->setParameter('organizations', $organizations);
        }

        if ($max > 1) {
            $query->setMaxResults($max);
        }

        return $query->getResult();
    }
327608
public function getFavouriteByWorkspaceAndUser(Workspace $workspace, User $user)
    {
        return $this->workspaceFavouriteRepo->findOneBy([
            'workspace' => $workspace,
            'user' => $user,
        ]);
    }
948399
public function getWidgetContent(Workspace $workspace = null, User $user = null)
    {
        $results = [];

        if (!is_null($user)) {
            $results = is_null($workspace) ?
                $this->om->getRepository('ClarolineResultBundle:Result')->findByUser($user) :
                $this->om->getRepository('ClarolineResultBundle:Result')->findByUserAndWorkspace($user, $workspace);
        }

        return $this->templating->render('ClarolineResultBundle:result:widget.html.twig', [
            'results' => $results,
        ]);
    }
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,
            ])
        );
    }
1327961
protected function prepareBaseWorkspaceOptions(Workspace $excludedWorkspace = null)
    {
        $baseWorkspaceOptions = [];
        foreach ($this->workspaceRepository->findAll() as $workspace) {
            /** @var Workspace $workspace */
            if (!$workspace->isPersonalWorkspace() && $workspace !== $excludedWorkspace && ($workspace->isPublicWorkspace() || $workspace->isInternalWorkspace() || $this->userService->currentUserCanManageWorkspace($workspace))) {
                $baseWorkspaceOptions[$workspace->getName()] = $workspace->getTitle();
            }
        }

        return $baseWorkspaceOptions;
    }
1133155
public function getFavouriteWorkspacesByUser(User $user)
    {
        $workspaces = array();
        $favourites = $this->workspaceFavouriteRepo
            ->findFavouriteWorkspacesByUser($user);

        foreach ($favourites as $favourite) {
            $workspace = $favourite->getWorkspace();
            $workspaces[$workspace->getId()] = $workspace;
        }

        return $workspaces;
    }