Checks the groups and returns only the valid ones
@param array $groups
@return array $checkedGroups
323560
protected function checkGroups(array $groups)
    {
        $checkedGroups = array();
        foreach ($groups as $group) {
            if (true === is_string($group) && false === in_array($group, $checkedGroups)) {
                $checkedGroups[] = (string)$group;
            }
        }
        return $checkedGroups;
    }
359993
public function getGroup($groupId)
    {
        static $groups = array();

        if (! isset($groups[$groupId])) {
            $groups[$groupId] = $this->_loadClass('Group', true, array($groupId));
    }

        return $groups[$groupId];
    }
1241054
public function groupBy(...$groups)
    {
        foreach ($groups as $group) {
            $this->groups = array_merge(
                (array) $this->groups,
                array_wrap($group)
            );
        }

        return $this;
    }
754502
public function setGroup(array $group)
    {
        try {

            // need to return << true
            $this->validator->verify($group, [
                'isArray', 'isNotEmpty', 'isExists'
            ], 'group');

        }
        catch(ExceptionFactory $e) {
            echo $e->getMessage();
        }

        return $this;
    }
1194291
public function setEditGroups( $groups )
    {
        $this->editGroups = array_unique(
            is_array( $groups ) ? $groups : preg_split( '/[,\s]+/', $groups )
        );

        return $this;
    }
1095306
protected function getGroups(array $annotations) :? array
    {
        if (empty($annotations)) {
            return [];
        }

        return array_values(array_unique(array_reduce($annotations, function ($carry, $annotation) {
            return array_merge($carry, $annotation->getGroups());
        }, [])));
    }
266017
public function setGroups($groups)
    {
        foreach ($groups as $key => $dtoData) {
            $this->groups[$key] = new GroupDto($dtoData);
        }
    
        return $this;
    }
162489
public function hasGroup($group)
    {
        if ($this->user() === null) {
            return null;
        }

        return in_array($group, $this->groups, true);
    }
1010114
public function useUserAccessGroups(array $groups): QueryBuilder
    {
        $groups = array_map('intval', $groups);
        $groups[] = 0; // always grant access to public documents
        $groups = array_unique($groups);
        sort($groups, SORT_NUMERIC);

        $accessFilter = '{!typo3access}' . implode(',', $groups);
        $this->queryToBuild->removeFilterQuery('access');
        return $this->useFilter($accessFilter, 'access');
    }
524418
public function retrieveGroup($group)
    {
        $result = array();

        foreach (Profiler::$_samples as $record) {
            if ($record[3] == $group) {
                $result[] = $record;
            }
        }

        return $result;
    }
725232
public static function get_group_members($groupids) {
        $members = array();

        $params = self::validate_parameters(self::get_group_members_parameters(), array('groupids'=>$groupids));

        foreach ($params['groupids'] as $groupid) {
            // validate params
            $group = groups_get_group($groupid, 'id, courseid, name, enrolmentkey', MUST_EXIST);
            // now security checks
            $context = context_course::instance($group->courseid, IGNORE_MISSING);
            try {
                self::validate_context($context);
            } catch (Exception $e) {
                $exceptionparam = new stdClass();
                $exceptionparam->message = $e->getMessage();
                $exceptionparam->courseid = $group->courseid;
                throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
            }
            require_capability('moodle/course:managegroups', $context);

            $groupmembers = groups_get_members($group->id, 'u.id', 'lastname ASC, firstname ASC');

            $members[] = array('groupid'=>$groupid, 'userids'=>array_keys($groupmembers));
        }

        return $members;
    }
134778
public function groupBy(...$groups)
    {
        foreach ($groups as $group) {
            $this->groups = array_merge((array) $this->groups, is_array($group) ? $group : [$group]);
        }

        return $this;
    }
349068
public function getGroup ($groupID)
    {
        $groups = $this->getAllGroups();
        
        foreach ($groups as $group) {
            if ($group->getID() == $groupID) {
                return $group;
            }
        }
        
        return null;
    }
1181757
protected function resolveGroup($group)
    {
        if (is_string($group)) {
            $group = Group::whereHandle($group)->firstOrFail();
        }

        return $group;
    }
1199032
protected function isUserAssignedToGroup($groups)
    {
        $isValid = false;

        $user = $this->getUser();
        foreach ($groups as $group) {
            if ($user->inGroup($group->getId())) {
                $isValid = true;
                break;
            }
        }

        return $isValid;
    }
939190
public function hasGroup($group)
    {
        if (is_string($group)) {
            return $this->groups->contains('name', $group);
        }

        return ! ! $group->intersect($this->groups)->count();
    }
1262745
protected function parseFilterGroups(array $filter_groups)
    {
        $return = [];

        foreach($filter_groups as $group) {
            if (!array_key_exists('filters', $group)) {
                throw new InvalidArgumentException('Filter group does not have the \'filters\' key.');
            }

            $filters = array_map(function($filter){
                if (!isset($filter['not'])) {
                    $filter['not'] = false;
                }

                return $filter;
            }, $group['filters']);

            $return[] = [
                'filters' => $filters,
                'or' => isset($group['or']) ? $group['or'] : false
            ];
        }

        return $return;
    }