@param $data
@param array $groups

@return IValidationResult
516037
public function check($data, array $groups = []) {
        $groups = array_extend($this->getConstraintGroups(), $groups);

        return $this->applyConstraints($data, $groups);
    }
236862
public function create(array $data)
    {
        try
        {
            if ($this->validator->with($data)->passes())
            {
                $this->groups->create($data);
                return true;
            }
        }
        catch (GroupExistsException $e)
        {
            $this->validator->add('GroupExistsException', $e->getMessage());
        }
        catch (NameRequiredException $e)
        {
            $this->validator->add('NameRequiredException', $e->getMessage());
        }

        return false;
    }
1096104
public function group(string $group, array $data = [], ?callable $callback = null): self
    {
        $data = new Data($data);

        // No callback, set prepared group
        $this->preparedGroups[$group] = $data;

        $new = $this->cloneInstance();
        $new->setOptions($data);
        $new->package((string) $this->getOption('package'));
        $new->group = $group;
        $new->groups[$group] = $data;

        // Find parents
        if (isset($data['parents'])) {
            $this->parents((array) $data['parents']);
        }

        if ($callback) {
            $this->groups[$group] = $data;

            $callback($this);

            array_pop($this->groups);
        }

        return $new;
    }
769723
public static function update_groups($groups) {
        global $CFG, $DB;
        require_once("$CFG->dirroot/group/lib.php");

        $params = self::validate_parameters(self::update_groups_parameters(), array('groups' => $groups));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['groups'] as $group) {
            $group = (object)$group;

            if (trim($group->name) == '') {
                throw new invalid_parameter_exception('Invalid group name');
            }

            if (! $currentgroup = $DB->get_record('groups', array('id' => $group->id))) {
                throw new invalid_parameter_exception("Group $group->id does not exist");
            }

            // Check if the modified group name already exists in the course.
            if ($group->name != $currentgroup->name and
                    $DB->get_record('groups', array('courseid' => $currentgroup->courseid, 'name' => $group->name))) {
                throw new invalid_parameter_exception('A different group with the same name already exists in the course');
            }

            $group->courseid = $currentgroup->courseid;

            // Now security checks.
            $context = context_course::instance($group->courseid);
            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);

            if (!empty($group->description)) {
                $group->descriptionformat = external_validate_format($group->descriptionformat);
            }

            groups_update_group($group);
        }

        $transaction->allow_commit();

        return null;
    }
619776
public function validate(BaseEntityInterface $entity, array $groups = [])
    {
        if ($this->validator) {
            $violations = $this->validator->validate($entity, null, $groups);

            if ($violations->count()) {
                throw new EntityValidateException('Validation error', $violations, 400);
            }
        }

        return $entity;
    }
1324378
public function set(array $data): CollectionInterface
    {
        foreach ($data as $row) {
            $this->add($row);
        }

        return $this;
    }
1264493
public function static_create(array $values=[], $groups=[]) {
		return $this->getDataMapper()->create($this->entityClass, $values, $groups);
	}
609950
public function normalize($data, $attributes = null, $groups = null, $entityMethods = null)
    {
        $context = $this->getNormalizeContext($this->normalizeContext, $attributes, $groups);

        $dataNormalized = $this->serializer->normalize($data, null, $context);

        if ($entityMethods && count($entityMethods) > 0) {
            $dataNormalized = $this->mergeEntitiesMethods($data, $dataNormalized, $entityMethods);
        }

        return $dataNormalized;
    }
518327
public function errorsI18N(array $locales=[], $groups=[]) {
		if(!$locales)
			$locales = $this->getLocales();
		$data = $this->toArrayRawI18N($locales);
		$validator = $this->getValidator($locales);

		return $validator->errors($data, $groups);
	}
904824
public function validI18N(array $locales=[], $groups=[]) {
		if(!$locales)
			$locales = $this->getLocales();
		$data = $this->toArrayRawI18N($locales);
		$validator = $this->getValidator($locales);
		return $validator->valid($data, $groups);
	}
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');
    }
1194291
public function setEditGroups( $groups )
    {
        $this->editGroups = array_unique(
            is_array( $groups ) ? $groups : preg_split( '/[,\s]+/', $groups )
        );

        return $this;
    }
51689
public static function index(
        array $array,
        ? string $key,
        $groups = []
    ): array {
        $result = [];
        $groups = (array)$groups;
        foreach ($array as $item) {
            $temp = &$result;
            foreach ($groups as $group) {
                $value = static::get($item, $group);
                array_key_exists($value, $temp) || $temp[$value] = [];
                $temp = &$temp[$value];
            }

            if ($key === null) {
                empty($groups) || $temp[] = $item;
            } else {
                $value = static::get($item, $key);
                if ($value !== null) {
                    is_float($value) && $value = str_replace(
                        ',',
                        '.',
                        (string)$value
                    );
                    $temp[$value] = $item;
                }
            }
            unset($temp);
        }
        return $result;
    }
987533
public function deserialize($data, Group $group = null, array $options = [])
    {
        $this->sipe('name', 'setName', $data, $group);

        if (isset($data['organizations'])) {
            $group->setOrganizations(
                array_map(function ($organization) {
                    return $this->om->getObject($organization, Organization::class);
                }, $data['organizations'])
            );
        }

        //only add role here. If we want to remove them, use the crud remove method instead
        //it's usefull if we want to create a user with a list of roles
        if (isset($data['roles'])) {
            foreach ($data['roles'] as $role) {
                $role = $this->om->getObject($role, Role::class);
                if ($role && $role->getId()) {
                    $group->addRole($role);
                }
            }
        }

        return $group;
    }
538914
public function withData(array $data, array $fields = [])
    {
        $clone = clone $this;
        $clone->_fields = !empty($fields) ? \array_intersect_key($data, \array_flip($fields)) : $data;
        $clone->_errors = [];

        return $clone;
    }
1276108
public function getReachableGroups(array $groups)
    {
        $reachableGroups = $groups;
        foreach ($groups as $group) {
            if (!isset($this->map[$group])) {
                continue;
            }

            $reachableGroups = array_merge($reachableGroups, $this->map[$group]);
        }

        return array_unique(
            array_merge($reachableGroups, $this->groupAlwaysPresent)
        );
    }
729349
public function createRequestsForGroups(array $groups) {
        foreach($groups as $group) {
            array_push($this->createdRequests, new Request('GET', $group->types->href));
        }
    }