public function getAccesses(
        TokenInterface $token,
        array $workspaces,
        $toolName = null,
        $action = 'open',
        $orderedToolType = 0
    ) {
        $userRoleNames = $this->sut->getRoles($token);
        $accesses = [];

        if (in_array('ROLE_ADMIN', $userRoleNames)) {
            foreach ($workspaces as $workspace) {
                $accesses[$workspace->getId()] = true;
            }

            return $accesses;
        }

        $hasAllAccesses = true;
        $workspacesWithoutManagerRole = [];

        foreach ($workspaces as $workspace) {
            if (in_array('ROLE_WS_MANAGER_'.$workspace->getUuid(), $userRoleNames)) {
                $accesses[$workspace->getId()] = true;
            } else {
                $accesses[$workspace->getId()] = $hasAllAccesses = false;
                $workspacesWithoutManagerRole[] = $workspace;
            }
        }

        if (!$hasAllAccesses) {
            $em = $this->container->get('doctrine.orm.entity_manager');
            $openWsIds = $em->getRepository('ClarolineCoreBundle:Workspace\Workspace')
                ->findOpenWorkspaceIds(
                    $userRoleNames,
                    $workspacesWithoutManagerRole,
                    $toolName,
                    $action,
                    $orderedToolType
                );

            foreach ($openWsIds as $idRow) {
                $accesses[$idRow['id']] = true;
            }
        }

        //remove accesses if workspace is personal and right was not given

        foreach ($workspaces as $workspace) {
            if ($workspace->isPersonal() && $toolName) {
                $pwc = $this->container->get('claroline.manager.tool_manager')
                    ->getPersonalWorkspaceToolConfigs();
                $canOpen = false;

                foreach ($pwc as $conf) {
                    if (!$toolName) {
                        $toolName = 'home';
                    }

                    if ($conf->getTool()->getName() === $toolName &&
                        in_array($conf->getRole()->getName(), $workspace->getCreator()->getRoles()) &&
                        ($conf->getMask() & 1)) {
                        $canOpen = true;
                    }
                }

                if (!$canOpen) {
                    $accesses[$workspace->getId()] = false;
                }
            }
        }

        return $accesses;
    }
public function getAccesses(
        TokenInterface $token,
        array $workspaces,
        $toolName = null,
        $action = 'open',
        $orderedToolType = 0
    ) {
        $userRoleNames = $this->sut->getRoles($token);
        $accesses = [];

        if (in_array('ROLE_ADMIN', $userRoleNames)) {
            foreach ($workspaces as $workspace) {
                $accesses[$workspace->getId()] = true;
            }

            return $accesses;
        }

        $hasAllAccesses = true;
        $workspacesWithoutManagerRole = [];

        foreach ($workspaces as $workspace) {
            if (in_array('ROLE_WS_MANAGER_'.$workspace->getUuid(), $userRoleNames)) {
                $accesses[$workspace->getId()] = true;
            } else {
                $accesses[$workspace->getId()] = $hasAllAccesses = false;
                $workspacesWithoutManagerRole[] = $workspace;
            }
        }

        if (!$hasAllAccesses) {
            $em = $this->container->get('doctrine.orm.entity_manager');
            $openWsIds = $em->getRepository('ClarolineCoreBundle:Workspace\Workspace')
                ->findOpenWorkspaceIds(
                    $userRoleNames,
                    $workspacesWithoutManagerRole,
                    $toolName,
                    $action,
                    $orderedToolType
                );

            foreach ($openWsIds as $idRow) {
                $accesses[$idRow['id']] = true;
            }
        }

        //remove accesses if workspace is personal and right was not given

        foreach ($workspaces as $workspace) {
            if ($workspace->isPersonal() && $toolName) {
                $pwc = $this->container->get('claroline.manager.tool_manager')
                    ->getPersonalWorkspaceToolConfigs();
                $canOpen = false;

                foreach ($pwc as $conf) {
                    if (!$toolName) {
                        $toolName = 'home';
                    }

                    if ($conf->getTool()->getName() === $toolName &&
                        in_array($conf->getRole()->getName(), $workspace->getCreator()->getRoles()) &&
                        ($conf->getMask() & 1)) {
                        $canOpen = true;
                    }
                }

                if (!$canOpen) {
                    $accesses[$workspace->getId()] = false;
                }
            }
        }

        return $accesses;
    }
public function getAccesses ( TokenInterface $ token , array $ workspaces , $ toolName = null , $ action = 'open' , $ orderedToolType = 0 ) { $ userRoleNames = $ this -> sut -> getRoles ( $ token ) ; $ accesses = [ ] ; if ( in_array ( 'ROLE_ADMIN' , $ userRoleNames ) ) { foreach ( $ workspaces as $ workspace ) { $ accesses [ $ workspace -> getId ( ) ] = true ; } return $ accesses ; } $ hasAllAccesses = true ; $ workspacesWithoutManagerRole = [ ] ; foreach ( $ workspaces as $ workspace ) { if ( in_array ( 'ROLE_WS_MANAGER_' . $ workspace -> getUuid ( ) , $ userRoleNames ) ) { $ accesses [ $ workspace -> getId ( ) ] = true ; } else { $ accesses [ $ workspace -> getId ( ) ] = $ hasAllAccesses = false ; $ workspacesWithoutManagerRole [ ] = $ workspace ; } } if ( ! $ hasAllAccesses ) { $ em = $ this -> container -> get ( 'doctrine.orm.entity_manager' ) ; $ openWsIds = $ em -> getRepository ( 'ClarolineCoreBundle:Workspace\Workspace' ) -> findOpenWorkspaceIds ( $ userRoleNames , $ workspacesWithoutManagerRole , $ toolName , $ action , $ orderedToolType ) ; foreach ( $ openWsIds as $ idRow ) { $ accesses [ $ idRow [ 'id' ] ] = true ; } } //remove accesses if workspace is personal and right was not given foreach ( $ workspaces as $ workspace ) { if ( $ workspace -> isPersonal ( ) && $ toolName ) { $ pwc = $ this -> container -> get ( 'claroline.manager.tool_manager' ) -> getPersonalWorkspaceToolConfigs ( ) ; $ canOpen = false ; foreach ( $ pwc as $ conf ) { if ( ! $ toolName ) { $ toolName = 'home' ; } if ( $ conf -> getTool ( ) -> getName ( ) === $ toolName && in_array ( $ conf -> getRole ( ) -> getName ( ) , $ workspace -> getCreator ( ) -> getRoles ( ) ) && ( $ conf -> getMask ( ) & 1 ) ) { $ canOpen = true ; } } if ( ! $ canOpen ) { $ accesses [ $ workspace -> getId ( ) ] = false ; } } } return $ accesses ; }
Returns the accesses rights of a given token for a set of workspaces.
If a tool name is passed in, the check will be limited to that tool,
otherwise workspaces with at least one accessible tool will be
considered open. Access to any tool is always granted to platform
administrators and workspace managers.

The returned value is an associative array in which
keys are workspace ids and values are boolean indicating if the
workspace is open.

@param TokenInterface $token
@param Workspace[]    $workspaces
@param string|null    $toolName
@param string         $action
@param int            $orderedToolType

@return bool[]
Returns the accesses rights of a given token for a set of workspaces . If a tool name is passed in the check will be limited to that tool otherwise workspaces with at least one accessible tool will be considered open . Access to any tool is always granted to platform administrators and workspace managers .