Get groupings definition specified by ids

@param array $groupingids arrays of grouping ids
@param boolean $returngroups return the associated groups if true. The default is false.
@return array of grouping objects (id, courseid, name)
@since Moodle 2.3
432512
public static function get_groupings($groupingids, $returngroups = false) {
        global $CFG, $DB;
        require_once("$CFG->dirroot/group/lib.php");
        require_once("$CFG->libdir/filelib.php");

        $params = self::validate_parameters(self::get_groupings_parameters(),
                                            array('groupingids' => $groupingids,
                                                  'returngroups' => $returngroups));

        $groupings = array();
        foreach ($params['groupingids'] as $groupingid) {
            // Validate params.
            $grouping = groups_get_grouping($groupingid, '*', MUST_EXIST);

            // Now security checks.
            $context = context_course::instance($grouping->courseid);
            try {
                self::validate_context($context);
            } catch (Exception $e) {
                $exceptionparam = new stdClass();
                $exceptionparam->message = $e->getMessage();
                $exceptionparam->courseid = $grouping->courseid;
                throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
            }
            require_capability('moodle/course:managegroups', $context);

            list($grouping->description, $grouping->descriptionformat) =
                external_format_text($grouping->description, $grouping->descriptionformat,
                        $context->id, 'grouping', 'description', $grouping->id);

            $groupingarray = (array)$grouping;

            if ($params['returngroups']) {
                $grouprecords = $DB->get_records_sql("SELECT * FROM {groups} g INNER JOIN {groupings_groups} gg ".
                                               "ON g.id = gg.groupid WHERE gg.groupingid = ? ".
                                               "ORDER BY groupid", array($groupingid));
                if ($grouprecords) {
                    $groups = array();
                    foreach ($grouprecords as $grouprecord) {
                        list($grouprecord->description, $grouprecord->descriptionformat) =
                        external_format_text($grouprecord->description, $grouprecord->descriptionformat,
                        $context->id, 'group', 'description', $grouprecord->groupid);
                        $groups[] = array('id' => $grouprecord->groupid,
                                          'name' => $grouprecord->name,
                                          'idnumber' => $grouprecord->idnumber,
                                          'description' => $grouprecord->description,
                                          'descriptionformat' => $grouprecord->descriptionformat,
                                          'enrolmentkey' => $grouprecord->enrolmentkey,
                                          'courseid' => $grouprecord->courseid
                                          );
                    }
                    $groupingarray['groups'] = $groups;
                }
            }
            $groupings[] = $groupingarray;
        }

        return $groupings;
    }
819820
public static function update_groupings($groupings) {
        global $CFG, $DB;
        require_once("$CFG->dirroot/group/lib.php");

        $params = self::validate_parameters(self::update_groupings_parameters(), array('groupings'=>$groupings));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['groupings'] as $grouping) {
            $grouping = (object)$grouping;

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

            if (! $currentgrouping = $DB->get_record('groupings', array('id'=>$grouping->id))) {
                throw new invalid_parameter_exception("Grouping $grouping->id does not exist in the course");
            }

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

            $grouping->courseid = $currentgrouping->courseid;

            // Now security checks.
            $context = context_course::instance($grouping->courseid);
            try {
                self::validate_context($context);
            } catch (Exception $e) {
                $exceptionparam = new stdClass();
                $exceptionparam->message = $e->getMessage();
                $exceptionparam->courseid = $grouping->courseid;
                throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
            }
            require_capability('moodle/course:managegroups', $context);

            // We must force allways FORMAT_HTML.
            $grouping->descriptionformat = external_validate_format($grouping->descriptionformat);

            // Finally update the grouping.
            groups_update_grouping($grouping);
        }

        $transaction->allow_commit();

        return null;
    }
1116866
public function getGroupMembers($groupId,  array $filters = [])
	{
		return $this->sendRequest(
			$this->createRequest('GET', sprintf('groups/%d/members', $groupId), [
				'query' => $filters
			])
		);
	}
572415
public function getGroups()
    {
        return $this->apiCall('groups.list')->then(function ($response) {
            $groups = [];
            foreach ($response['groups'] as $group) {
                $groups[] = new Group($this, $group);
            }
            return $groups;
        });
    }
640928
public function setGroups($groups=null) {
		if(!is_array($groups) && $groups !== null)
			$groups = [$groups];
		$this->groups = $groups;
		return $this;
	}
405557
public function inGroup($sGroupID)
    {
        $blResult = false;
        $aGroups = $this->getGroups();
        foreach ($aGroups as $oObject) {
            if ($oObject->_sOXID == $sGroupID) {
                $blResult = true;
                break;
            }
        }

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

        return $this;
    }
1276667
public java.util.List<String> getGroupIds() {
        if (groupIds == null) {
            groupIds = new com.amazonaws.internal.SdkInternalList<String>();
        }
        return groupIds;
    }
859673
public static function get_lessons_by_courses($courseids = array()) {
        global $PAGE;

        $warnings = array();
        $returnedlessons = array();

        $params = array(
            'courseids' => $courseids,
        );
        $params = self::validate_parameters(self::get_lessons_by_courses_parameters(), $params);

        $mycourses = array();
        if (empty($params['courseids'])) {
            $mycourses = enrol_get_my_courses();
            $params['courseids'] = array_keys($mycourses);
        }

        // Ensure there are courseids to loop through.
        if (!empty($params['courseids'])) {

            list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);

            // Get the lessons in this course, this function checks users visibility permissions.
            // We can avoid then additional validate_context calls.
            $lessons = get_all_instances_in_courses("lesson", $courses);
            foreach ($lessons as $lessonrecord) {
                $context = context_module::instance($lessonrecord->coursemodule);

                // Remove fields added by get_all_instances_in_courses.
                unset($lessonrecord->coursemodule, $lessonrecord->section, $lessonrecord->visible, $lessonrecord->groupmode,
                    $lessonrecord->groupingid);

                $lessonrecord = self::get_lesson_summary_for_exporter($lessonrecord);

                $exporter = new lesson_summary_exporter($lessonrecord, array('context' => $context));
                $returnedlessons[] = $exporter->export($PAGE->get_renderer('core'));
            }
        }
        $result = array();
        $result['lessons'] = $returnedlessons;
        $result['warnings'] = $warnings;
        return $result;
    }
224848
public static function fetchByGroup( $groupID, $limit = false, $offset = false )
    {
        return self::fetchByConditions( array( "ezcobj_state_group.id=$groupID" ), $limit, $offset );
    }
314226
public static function get_glossaries_by_courses($courseids = array()) {
        $params = self::validate_parameters(self::get_glossaries_by_courses_parameters(), array('courseids' => $courseids));

        $warnings = array();
        $courses = array();
        $courseids = $params['courseids'];

        if (empty($courseids)) {
            $courses = enrol_get_my_courses();
            $courseids = array_keys($courses);
        }

        // Array to store the glossaries to return.
        $glossaries = array();
        $modes = array();

        // Ensure there are courseids to loop through.
        if (!empty($courseids)) {
            list($courses, $warnings) = external_util::validate_courses($courseids, $courses);

            // Get the glossaries in these courses, this function checks users visibility permissions.
            $glossaries = get_all_instances_in_courses('glossary', $courses);
            foreach ($glossaries as $glossary) {
                $context = context_module::instance($glossary->coursemodule);
                $glossary->name = external_format_string($glossary->name, $context->id);
                list($glossary->intro, $glossary->introformat) = external_format_text($glossary->intro, $glossary->introformat,
                    $context->id, 'mod_glossary', 'intro', null);
                $glossary->introfiles = external_util::get_area_files($context->id, 'mod_glossary', 'intro', false, false);

                // Make sure we have a number of entries per page.
                if (!$glossary->entbypage) {
                    $glossary->entbypage = $CFG->glossary_entbypage;
                }

                // Add the list of browsing modes.
                if (!isset($modes[$glossary->displayformat])) {
                    $modes[$glossary->displayformat] = self::get_browse_modes_from_display_format($glossary->displayformat);
                }
                $glossary->browsemodes = $modes[$glossary->displayformat];
                $glossary->canaddentry = has_capability('mod/glossary:write', $context) ? 1 : 0;
            }
        }

        $result = array();
        $result['glossaries'] = $glossaries;
        $result['warnings'] = $warnings;
        return $result;
    }
1278873
public static function get_groupings_returns() {
        return new external_multiple_structure(
            new external_single_structure(
                array(
                    'id' => new external_value(PARAM_INT, 'grouping record id'),
                    'courseid' => new external_value(PARAM_INT, 'id of course'),
                    'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
                    'description' => new external_value(PARAM_RAW, 'grouping description text'),
                    'descriptionformat' => new external_format_value('description'),
                    'idnumber' => new external_value(PARAM_RAW, 'id number'),
                    'groups' => new external_multiple_structure(
                        new external_single_structure(
                            array(
                                'id' => new external_value(PARAM_INT, 'group record id'),
                                'courseid' => new external_value(PARAM_INT, 'id of course'),
                                'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
                                'description' => new external_value(PARAM_RAW, 'group description text'),
                                'descriptionformat' => new external_format_value('description'),
                                'enrolmentkey' => new external_value(PARAM_RAW, 'group enrol secret phrase'),
                                'idnumber' => new external_value(PARAM_RAW, 'id number')
                            )
                        ),
                    'optional groups', VALUE_OPTIONAL)
                )
            )
        );
    }
56076
public function addGrouping( $grouping )
	{
		if( is_array( $grouping ) )
			return $this->addGroupings( $grouping );
		if( in_array( $grouping, $this->groupings ) )
			return FALSE;
		$this->groupings[] = $grouping;
		return TRUE;
	}
1071297
public function getGroup(string $groupid)
    {
        $cl = $this->getGroupClass();
        $group = new $cl;
        return $group->obtainByGroupID($groupid);
    }
1291861
public static function delete_groups($groupids) {
        global $CFG, $DB;
        require_once("$CFG->dirroot/group/lib.php");

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

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['groupids'] as $groupid) {
            // validate params
            $groupid = validate_param($groupid, PARAM_INT);
            if (!$group = groups_get_group($groupid, '*', IGNORE_MISSING)) {
                // silently ignore attempts to delete nonexisting groups
                continue;
            }

            // 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);

            groups_delete_group($group);
        }

        $transaction->allow_commit();
    }
335866
public function groups()
    {
        $return = ['everyone'];

        $groups = GroupMember::where('user_id', $this->id())
            ->sort('`group` ASC')
            ->all();

        foreach ($groups as $group) {
            $return[] = $group->group;
        }

        return $return;
    }
837138
public function getRawAggregate($returnType)
  {
    if ($returnType == DOC_TYPE_ARRAY) {
      $res = array();
      foreach ($this->_aggregate as $key => $value) {
        if ($value) {
          $tmp = CPS_Response::simpleXmlToArray($value);
          // multiple or one result - returned data format should be the same!
          if (isset($tmp['data'][0])) {
            // multiple results
            $res[$key] = $tmp['data'];
          } else {
            // one result
            $res[$key][] = $tmp['data'];
          }
          unset($tmp);
        } else {
          $res[$key] = array();
        }
      }
      return $res;
    } else if ($returnType == DOC_TYPE_STDCLASS) {
      $res = array();
      foreach ($this->_aggregate as $key => $value) {
        if ($value) {
          $tmp = CPS_Response::simpleXmlToStdClass($value);
          $res[$key] = $tmp->data;
          unset($tmp);
        } else {
          $res[$key] = new stdClass();
        }
      }
      return $res;
    }
    return $this->_aggregate;
  }