Is the user in the role(s)?
@param  string|array $roles
@param  boolean      $all
@return boolean
970654
public function is($roles, $all = true)
    {
        if (! is_array($roles)) {
            $roles  =   (array) $roles;
        }

        $allRoles   =   $this->roles
            ->toArray();
        $filtered   =   array_where(
            $allRoles,
            function ($key, $role) use ($roles) {
                return in_array($role['key'], $roles);
            }
        );
        
        $filteredCount  =   count($filtered);
        // Are we looking for all the roles here?
        if (true === $all) {
            return count($roles) === $filteredCount;
        }

        // Not at all. Any is good enough
        return 0 < $filteredCount;
    }
1072996
public static function hasRole($role)
    {
        if (!isset($_SESSION['user'])) {
            return false;
        };
        if (!isset($_SESSION['ACL_ROLES'])) {
            return false;
        };
        return in_array($role, $_SESSION['ACL_ROLES']);
    }
22051
protected function getRole($role)
	{
		if (!isset($this->user))
			return false;

		if (isset($this->user->role))
			return $this->user->role->hasPermission($role);

		return false;
	}
1268755
public function assignRole(...$roles)
    {
        $roles = collect($roles)
            ->flatten()
            ->map(function ($role) {
                return $this->getStoredRole($role);
            })
            ->each(function ($role) {
                $this->ensureModelSharesGuard($role);
            })
            ->all();

        $this->roles()->saveMany($roles);

        $this->forgetCachedPermissions();

        return $this;
    }
357217
public function hasRoles($roles): bool
    {
        $userRoles = $this->getRoles()->all();

        // We should ensure that all given roles match the current user,
        // consider it as a AND condition instead of OR.
        foreach ((array) $roles as $role) {
            if (! \in_array($role, $userRoles)) {
                return false;
            }
        }

        return true;
    }
1252024
public function isGranted(string $permission, array $roles): bool
    {
        foreach ($this->flattenRoles($roles) as $role) {
            if ($role->hasPermission($permission)) {
                return true;
            }
        }

        return false;
    }
1190327
public function hasRole($role)
    {
        return is_null($this->roles) || in_array($role, $this->roles, true);
    }
956769
public function hasUserRoles($roles)
	{
		if ($this->session_machine === null) {
			throw new RuntimeException('Session machine not ready ‒ '.__METHOD__.' called too soon.');
		}

		if (is_array($roles)) {
			return count(array_intersect($this->getUserRoles(), $roles)) > 0;
		} else {
			return in_array($roles, $this->getUserRoles());
		}
	}
699582
public function findUsersByRolesIncludingGroups(
        array $roles
    ) {
        //very slow otherwise. If we want to do it properly, the OR clause won't do it.
        //we must use UNION wich is not supported by Doctrine
        $dql = '
            SELECT u, r1, ws
            From Claroline\\CoreBundle\\Entity\\User u
            LEFT JOIN u.roles r1
            LEFT JOIN u.personalWorkspace ws
            WHERE r1 in (:roles)
            AND u.isRemoved = false
            ORDER BY u.lastName, u.firstName ASC
        ';

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

        $resA = $query->getResult();
        $resA = $resA ? $resA : [];

        $dql = '
            SELECT u, g, r2, ws
            From Claroline\\CoreBundle\\Entity\\User u
            LEFT JOIN u.personalWorkspace ws
            LEFT JOIN u.groups g
            LEFT JOIN g.roles r2
            WHERE r2 in (:roles)
            AND u.isRemoved = false
            ORDER BY u.lastName, u.firstName ASC
        ';

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

        $resB = $query->getResult();
        $resB = $resB ? $resB : [];

        return array_unique(array_merge($resA, $resB));
    }
1100152
protected function allows($roles, $resources = null)
    {
        $roles = is_array($roles) ? $roles : [$roles];
        foreach ($roles as $role) {
            if (!$role) {
                continue;
            }
            if (!$this->hasRole($role)) {
                $this->addRole($role, 'LOGGED');
            }
            $this->allow($role, $resources);
        }
        return $this;
    }
1224011
public function is($role, $all = true)
    {
        if (! $this->check()) {
            return false;
        }

        return $this->lockdown
            ->is($this->getUserId(), $role, $all);
    }
437167
public function inRole($role): bool
    {
        $role = Arr::first($this->roles, function ($instance) use ($role) {
            if ($role instanceof RoleInterface) {
                return $instance->getRoleId() === $role->getRoleId();
            }
            if ($instance->getRoleId() === $role || $instance->getRoleSlug() === $role) {
                return true;
            }

            return false;
        });

        return $role !== null;
    }
460109
public static function roleExists($role) : bool {
		if (empty($_SESSION['numbers']['user']['roles'])) return false;
		if (is_array($role)) {
			$temp = array_intersect($role, $_SESSION['numbers']['user']['roles']);
			return !empty($temp);
		} else {
			return in_array($role, $_SESSION['numbers']['user']['roles']);
		}
	}
1067503
public function checkCurrentUserAccess($roles)
    {
        if ($this->getCurrentUser() === null) {
            return;
        }
        if ($roles instanceof core_kernel_classes_Resource) {
            $roles = [$roles->getUri()];
        }

        if (is_array($roles)) {
            $roles = array_map(function($role) {
                return $role instanceof core_kernel_classes_Resource ? $role->getUri() : $role;
            }, $roles);
        }

        if (in_array(TaoRoles::SYSTEM_ADMINISTRATOR, $roles)
            && !$this->userHasRoles($this->getCurrentUser(), TaoRoles::SYSTEM_ADMINISTRATOR)
        ) {
            throw new common_exception_Error('Permission denied');
        }

        if (in_array(TaoRoles::GLOBAL_MANAGER, $roles)
            && !$this->userHasRoles($this->getCurrentUser(), [TaoRoles::SYSTEM_ADMINISTRATOR, TaoRoles::GLOBAL_MANAGER])
        ) {
            throw new common_exception_Error('Permission denied');
        }
    }
377223
public static function hasRole($roles)
    {
        $user = wp_get_current_user();

        if (is_string($roles)) {
            $roles = array($roles);
        }

        if (!array_intersect($roles, $user->roles)) {
            return false;
        }

        return true;
    }
648473
public function not($id, $role, $all = true)
    {
        return false === $this->is($id, $role, $all);
    }
1032317
public function is($id, $role, $all = true)
    {
        if (! $user = $this->findUserById($id)) {
            return false;
        }

        return $user->is($role, $all);
    }