@param \Claroline\CoreBundle\Entity\User $user
@param string[]                          $roleNames
@param integer[]                         $restrictionIds

@return \Claroline\CoreBundle\Entity\Workspace\Workspace[]
966787
public function getWorkspacesByUserAndRoleNamesNotIn(
        User $user,
        array $roleNames,
        array $restrictionIds = null
    )
    {
        return $this->workspaceRepo->findByUserAndRoleNamesNotIn($user, $roleNames, $restrictionIds);
    }
1105980
public function getUsersWithRole(Role $role): array
    {
        $query = $this->getRepository()->createQueryBuilder('u')
            ->select('u')
            ->where(':role MEMBER OF u.roles')
            ->setParameter('role', $role)
            ->getQuery();

        return $query->getResult() ?? [];
    }
522214
public function getUserById(string $userName, array $roleMap) : AuthUser
    {
        if ( ! isset ($this->users[$userName]))
            throw new InvalidUserException("Invalid userId: '$userName'");
        $user = $this->users[$userName];

        if (!isset ($roleMap[$user["role"]]))
            throw new \InvalidArgumentException("User role '{$user["role"]}' is not defined in roleMap.");
        return new AuthUser([
            "userName" => $userName,
            "role" => $user["role"],
            "roleMap" => $roleMap,
            "roleId" => $roleMap[$user["role"]],
            "meta" => $user["meta"]
        ]);
    }
1122799
protected function getUserRolesFromEventDispatcher(Authenticatable $user = null, $roles = []): Collection
    {
        $roles = $this->events->until('orchestra.auth: roles', [$user, $roles]);

        // It possible that after event are all propagated we don't have a
        // roles for the user, in this case we should properly append "Guest"
        // user role to the current user.
        if (\is_null($roles)) {
            $roles = ['Guest'];
        }

        return new Collection($roles);
    }
36864
public function findWorkspaceRootsByUser(User $user)
    {
        $builder = new ResourceQueryBuilder();
        $dql = $builder->selectAsArray()
            ->whereParentIsNull()
            ->whereInUserWorkspace($user)
            ->orderByPath()
            ->getDql();
        $query = $this->_em->createQuery($dql);
        $query->setParameters($builder->getParameters());

        return $this->executeQuery($query);
    }
340871
public function getIncludeUserIds()
    {
        $userIds = array();
        $roleUsers = $this->role->getUsers();
        foreach ($roleUsers as $user) {
            array_push($userIds, $user->getId());
        }
        $roleGroups = $this->role->getGroups();
        foreach ($roleGroups as $group) {
            $userIds = array_merge($userIds, $group->getUserIds());
        }
        $userIds = array_unique($userIds);

        return $userIds;
    }
1124236
public function getUserRegistrations(User $user, array $collections)
    {
        $qb = $this->createQueryBuilder('d');
        $qb->where($qb->expr()->eq('d.user', ':user'));
        $qb->setParameter(':user', $user->getId());

        if (count($collections) > 0) {
            $qb->andWhere('d.baseId IN (:bases)');
            $qb->setParameter(':bases', array_map(function (\collection $collection) {
                return $collection->get_base_id();
            }, $collections));
        }

        $qb->orderBy('d.created', 'DESC');

        return $qb->getQuery()->getResult();
    }
1053175
private static function buildOrganizationUserRoles(array $roles, RoleableInterface $user, $orgName)
    {
        foreach ($user->getRoles() as $role) {
            $roles[] = RoleUtil::formatName($role).'__'.$orgName;
        }

        return $roles;
    }
103486
public function findWorkspacesByManager(User $user, $executeQuery = true)
    {
        $roles = $user->getRoles();
        $managerRoles = [];

        foreach ($roles as $role) {
            if (strpos('_'.$role, 'ROLE_WS_MANAGER')) {
                $managerRoles[] = $role;
            }
        }

        $dql = '
            SELECT w
            FROM Claroline\\CoreBundle\\Entity\\Workspace\\Workspace w
            JOIN w.roles r
            WHERE r.name IN (:roleNames)

        ';

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

        return $executeQuery ? $query->getResult() : $query;
    }
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;
    }
1234972
public Set<Role> findRoles(final User user)
    {
        final Set<Role> result = new HashSet<Role>();
        
        for(final RoleMapping mapping : this.getRoleMappings())
        {
            final Object source = mapping.getSource();
            
            if((user != null) && user.equals(source))
            {
                // TODO: Fix this hardcoding when Restlet implements equals for Role objects again
                RestletUtilRole standardRole = this.getRoleByName(mapping.getTarget().getName());
                if(standardRole != null)
                {
                    result.add(standardRole.getRole());
                }
                else
                {
                    result.add(mapping.getTarget());
                }
            }
        }
        
        return result;
    }
1355562
public function loadRoleDraftByRoleId($roleId)
    {
        try {
            return $this->innerGateway->loadRoleDraftByRoleId($roleId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
775699
protected static function getOrganizationUserRoles(OrganizationUserInterface $user, $roleHierarchy = null)
    {
        $roles = [];

        if ($user instanceof RoleableInterface && $user instanceof OrganizationUserInterface) {
            $org = $user->getOrganization();
            $roles = self::buildOrganizationUserRoles($roles, $user, $org->getName());
            $roles = self::buildOrganizationRoles($roles, $org);

            if ($roleHierarchy instanceof RoleHierarchyInterface) {
                $roles = RoleUtil::formatNames($roleHierarchy->getReachableRoles($roles));
            }
        }

        return $roles;
    }
132207
public static function applyAppRoleMapByService($user, $serviceId)
    {
        $maps = AppRoleMap::whereServiceId($serviceId)->get();

        foreach ($maps as $map) {
            UserAppRole::whereUserId($user->id)->whereAppId($map->app_id)->delete();
            $userAppRoleData = [
                'user_id' => $user->id,
                'app_id'  => $map->app_id,
                'role_id' => $map->role_id
            ];

            UserAppRole::create($userAppRoleData);
        }
    }
213066
protected function getRolePermissions($roleName)
    {
        $role = new SimpleRole($roleName);
        $permissions = $this->manager->getDriver()->getRolePermissions($role);
        $collection = new Collection();
        foreach ($permissions as $permission) {
            if ($permission instanceof Restriction) {
                continue;
            }
            $collection->allow($permission->getAction(), $permission->getResourceType(), $permission->getResourceId());
        }
        return $collection;
    }
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);
    }
891222
public function loadRoleAssignmentsByRoleId($roleId)
    {
        $data = $this->roleGateway->loadRoleAssignmentsByRoleId($roleId);

        if (empty($data)) {
            return array();
        }

        return $this->mapper->mapRoleAssignments($data);
    }