Adldap\Models\Group::getPaginatedMembers PHP Method

getPaginatedMembers() protected method

Retrieves members that are contained in a member range.
protected getPaginatedMembers ( ) : array
return array
    protected function getPaginatedMembers()
    {
        $members = [];
        $keys = array_keys($this->attributes);
        // We need to filter out the model attributes so
        // we only retrieve the member range.
        $attributes = array_values(array_filter($keys, function ($key) {
            return strpos($key, 'member;range') !== false;
        }));
        // We'll grab the member range key so we can run a
        // regex on it to determine the range.
        $key = reset($attributes);
        preg_match_all('/member;range\\=([0-9]{1,4})-([0-9*]{1,4})/', $key, $matches);
        if ($key && count($matches) == 3) {
            $to = $matches[2][0];
            $members = $this->getMembersFromAttribute($key);
            // If the query already included all member results (indicated
            // by the '*'), then we can return here. Otherwise we need
            // to continue on and retrieve the rest.
            if ($to === '*') {
                return $members;
            }
            $from = $to + 1;
            // We'll determine the member range simply
            // by doubling the selected from value.
            $to = $from * 2;
            // We'll need to query for the current model again but with
            // a new range to retrieve the other members.
            $group = $this->query->newInstance()->findByDn($this->getDn(), [$this->query->getSchema()->memberRange($from, $to)]);
            $members = array_merge($members, $group->getMembers()->toArray());
        }
        return $members;
    }