Returns the workspaces accessible by one of the given roles.

@param array[string] $roleNames

@return array[Workspace]
347794
public function findMyWorkspacesByRoleNames(array $roleNames)
    {
        $dql = '
            SELECT DISTINCT w
            FROM Claroline\CoreBundle\Entity\Workspace\Workspace w
            WHERE w IN (
                SELECT rw.id
                FROM Claroline\CoreBundle\Entity\Role r
                JOIN Claroline\CoreBundle\Entity\Workspace\Workspace rw
                WHERE r.name IN (:roleNames)
            )
            ORDER BY w.name ASC
        ';

        $query = $this->_em->createQuery($dql);
        $query->setParameter('roleNames', $roleNames);

        return $query->getResult();
    }
1145507
public function findOutsidersByWorkspaceRolesAndName(
        array $roles,
        $name,
        Workspace $workspace,
        $getQuery = false
    )
    {
        //feel free to make this request easier if you can
        $search = strtoupper($name);

        $dql = "
            SELECT u FROM Claroline\CoreBundle\Entity\Group u
            WHERE u NOT IN (
                SELECT u2 FROM Claroline\CoreBundle\Entity\Group u2
                JOIN u2.roles r WHERE r IN (:roles) AND
                u2 NOT IN (
                    SELECT u3 FROM Claroline\CoreBundle\Entity\Group u3
                    JOIN u3.roles r2
                    JOIN r2.workspace ws
                    WHERE r2 NOT IN (:roles)
                    AND ws = :wsId
                )
            )
            AND UPPER(u.name) LIKE :search
            ";

        $query = $this->_em->createQuery($dql);
        $query->setParameter('roles', $roles);
        $query->setParameter('wsId', $workspace);
        $query->setParameter('search', "%{$search}%");

        return $getQuery ? $query : $query->getResult();
    }
1282436
private static function buildOrganizationRoles(array $roles, OrganizationInterface $org)
    {
        $orgName = $org->getName();

        if ($org instanceof RoleableInterface) {
            $existingRoles = [];

            foreach ($roles as $role) {
                $existingRoles[] = $role;
            }

            foreach ($org->getRoles() as $orgRole) {
                $roleName = RoleUtil::formatName($orgRole);

                if (!\in_array($roleName, $existingRoles, true)) {
                    $roles[] = $roleName.'__'.$orgName;
                    $existingRoles[] = $roleName;
                }
            }
        }

        return $roles;
    }
1163280
public function getRoleBaseName($roleName)
    {
        if ($roleName === 'ROLE_ANONYMOUS') {
            return $roleName;
        }

        $substr = explode('_', $roleName);
        $roleName = array_shift($substr);

        for ($i = 0, $countSubstr = count($substr) - 1; $i < $countSubstr; $i++) {
            $roleName .= '_' . $substr[$i];
        }

        return $roleName;
    }
1070571
public function findWorkspaceByWorkspaceAndRoles(
        Workspace $workspace,
        array $roles,
        $orderedToolType = 0
    ) {
        if (count($roles) > 0) {
            $dql = '
                SELECT DISTINCT w
                FROM Claroline\\CoreBundle\\Entity\\Workspace\\Workspace w
                JOIN w.orderedTools ot
                JOIN ot.rights otr
                JOIN otr.role r
                WHERE w = :workspace
                AND ot.type = :type
                AND r.name IN (:roles)
                AND BIT_AND(otr.mask, :openValue) = :openValue
            ';

            $query = $this->_em->createQuery($dql);
            $query->setParameter('workspace', $workspace);
            $query->setParameter('roles', $roles);
            $query->setParameter('openValue', ToolMaskDecoder::$defaultValues['open']);
            $query->setParameter('type', $orderedToolType);

            return $query->getOneOrNullResult();
        }

        return null;
    }
863377
public function getWorkspacesByRoleNamesBySearchPager(
        array $roleNames,
        $search,
        $page,
        $orderedToolType = 0
    )
    {
        if (count($roleNames) > 0) {
            $workspaces = $this->workspaceRepo
                ->findByRoleNamesBySearch($roleNames, $search, $orderedToolType);
        } else {
            $workspaces = array();
        }

        return $this->pagerFactory->createPagerFromArray($workspaces, $page);
    }
1285749
public function findAccessesByRoles(array $roles)
    {
        $dql = '
            SELECT pp.property as property, MAX(pp.isEditable) as isEditable
            FROM Claroline\CoreBundle\Entity\ProfileProperty pp
            JOIN pp.role role
            WHERE role.name in (:roleNames)
            GROUP BY pp.property
        ';

        $query = $this->_em->createQuery($dql);
        $query->setParameter('roleNames', $roles);

        $results = $query->getResult();
        $properties = array();

        foreach ($results as $result) {
            $properties[$result['property']] = (boolean) $result['isEditable'];
        }

        return $properties;
    }
211558
public function getRolesByWorkspace(
        Workspace $workspace,
        $search = '',
        $orderedBy = 'id',
        $order = 'ASC'
    ) {
        if (empty($search)) {
            return $this->roleRepo->findByWorkspace($workspace, $orderedBy, $order);
        } else {
            return $this->roleRepo->findByWorkspaceAndSearch(
                $workspace,
                $search,
                $orderedBy,
                $order
            );
        }
    }
790478
public function getAdminToolsByRoles(array $roles)
    {
        $disabled = $this->container->get('claroline.config.platform_config_handler')->getParameter('security.disabled_admin_tools');
        $tools = $this->om->getRepository('Claroline\CoreBundle\Entity\Tool\AdminTool')->findByRoles($roles);
        $allowed = [];

        foreach ($tools as $tool) {
            if (!in_array($tool->getName(), $disabled)) {
                $allowed[] = $tool;
            }
        }

        return $allowed;
    }
284671
public function findUsersByWorkspaces(array $workspaces, $executeQuery = true)
    {
        // First find user ids, then retrieve users it's much faster this way, with UNION select in SQL
        $sql = 'SELECT DISTINCT u.id AS id FROM (
                  SELECT u1.id AS id FROM claro_user u1
                  INNER JOIN claro_user_role ur1 ON u1.id = ur1.user_id
                  INNER JOIN claro_role r1 ON r1.id = ur1.role_id
                  WHERE r1.workspace_id IN (:workspaces) AND u1.is_removed = :removed
                  UNION
                  SELECT u2.id AS id FROM claro_user u2
                  INNER JOIN claro_user_group ug2 ON u2.id = ug2.user_id
                  INNER JOIN claro_group g2 ON g2.id = ug2.group_id
                  INNER JOIN claro_group_role gr2 ON g2.id = gr2.group_id
                  INNER JOIN claro_role r2 ON r2.id = gr2.role_id
                  WHERE r2.workspace_id IN (:workspaces) AND u2.is_removed = :removed
                  ) u
                ';
        $rsm = new Query\ResultSetMapping();
        $rsm->addScalarResult('id', 'id', 'integer');
        $userIds = array_column($this->_em->createNativeQuery($sql, $rsm)
            ->setParameter('workspaces', $workspaces)
            ->setParameter('removed', false)
            ->getScalarResult(), 'id');

        $dql = '
            SELECT DISTINCT u FROM Claroline\CoreBundle\Entity\User u
            WHERE u.id IN (:ids)
            ORDER BY u.id
        ';

        $query = $this->_em
            ->createQuery($dql)
            ->setParameter('ids', $userIds)
            ->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);

        return $executeQuery ? $query->getResult() : $query;
    }
1005473
public function getDefinitionRoleDimensions( $roleRefsKey )
	{
		$roles = $this->getAllDefinitionRoles();
		if ( ! isset( $roles[ $roleRefsKey ] ) )
		{
			return array();
		}

		$taxonomy = $this->getTaxonomyForXSD( $roles[ $roleRefsKey ] );

		$role = $taxonomy->getDefinitionRoleRef( $roleRefsKey );

		if ( ! isset( $role['dimensions'] ) )
		{
			return array();
		}

		$result = array();

		foreach ( $role['dimensions'] as $dimensionKey => $href )
		{
			if ( ! isset( $result[ $dimensionKey ] ) )
			{
				$result[ $dimensionKey ] = array( 'href' => $href, 'roles' => array( $roleRefsKey ) );
				continue;
			}

			// Add unique roleRefsKey
			if ( in_array( $roleRefsKey, $result[ $dimensionKey ]['roles'] ) ) continue;
			$result[ $dimensionKey ]['roles'][] = $roleRefsKey;
		}

		return $result;

		/*
		if ( ! isset( $this->definitionRoleRefs[ $roleRefsKey ] ) ) return array();
		$role = $this->definitionRoleRefs[ $roleRefsKey ];

		// If there are no dimensions in this role, maybe the role exists in another taxonomy
		if ( ! isset( $role['dimensions'] ) )
		{
			if ( strpos( $role['href'], $this->getTaxonomyXSD() ) === false )
			{
				return $this->getTaxonomyForXSD( $role['href'] )->getDefinitionRoleDimensions( $roleRefsKey );
			}
		}
		else
		{
			$result = array();

			foreach ( $role['dimensions'] as $dimensionKey => $href )
			{
				if ( ! isset( $result[ $dimensionKey ] ) )
				{
					$result[ $dimensionKey ] = array( 'href' => $href, 'roles' => array( $roleRefsKey ) );
					continue;
				}

				// Add unique roleRefsKey
				if ( in_array( $roleRefsKey, $result[ $dimensionKey ]['roles'] ) ) continue;
				$result[ $dimensionKey ]['roles'][] = $roleRefsKey;
			}

			return $result;
		}

		return array();
		*/
	}
1027408
public function getRoles()
    {
        $roleModel = new \erdiko\users\models\Role;
        $roleEntity = $roleModel->findById($this->_user->getRole());
		return array( $roleEntity->getName());
	}
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;
    }
1358641
public function getPersonalWorkspace()
    {
        $workspaceName = $this->getPersonalWorkspaceName();
        if ($workspaceName !== null) {
            return $this->workspaceRepository->findOneByName($this->getPersonalWorkspaceName());
        }
    }
566541
public function getWorkspacesByRoleNamesPager(array $roleNames, $page)
    {
        if (count($roleNames) > 0) {
            $workspaces = $this->workspaceRepo->findMyWorkspacesByRoleNames($roleNames);
        } else {
            $workspaces = array();
        }

        return $this->pagerFactory->createPagerFromArray($workspaces, $page);
    }
1319589
protected function getPermissionsByNames(array $permissionNames)
    {
        $permissions = [];

        foreach ($permissionNames as $permissionName) {
            if (isset($permissions[$permissionName])) {
                continue;
            }

            $permission = $this->permissionStorage->getPermission($permissionName);

            if ($permission === null) {
                throw new PermissionNotFound($permissionName);
            }

            $permissions[$permissionName] = $permission;
        }

        return $permissions;
    }
752122
public function getArrayRolesByWorkspace(Workspace $workspace)
    {
        $workspaceRoles = [];
        $uow = $this->om->getUnitOfWork();
        $wRoles = $this->roleManager->getRolesByWorkspace($workspace);
        $scheduledForInsert = $uow->getScheduledEntityInsertions();

        foreach ($scheduledForInsert as $entity) {
            if ('Claroline\CoreBundle\Entity\Role' === get_class($entity)) {
                if ($entity->getWorkspace()) {
                    if ($entity->getWorkspace()->getGuid() === $workspace->getGuid()) {
                        $wRoles[] = $entity;
                    }
                }
            }
        }
        //now we build the array
        foreach ($wRoles as $wRole) {
            $workspaceRoles[$wRole->getTranslationKey()] = $wRole;
        }

        return $workspaceRoles;
    }