Return an array of valid options for the groups.

@param context $coursecontext
@return array
541158
protected function get_group_options($coursecontext) {
        $groups = array(0 => get_string('none'));
        if (has_capability('moodle/course:managegroups', $coursecontext)) {
            $groups[COHORT_CREATE_GROUP] = get_string('creategroup', 'enrol_cohort');
        }

        foreach (groups_get_all_groups($coursecontext->instanceid) as $group) {
            $groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext));
        }

        return $groups;
    }
676253
private function validateClass(
        ValidatorContextInterface $context,
        ValidationClassMappingInterface $classMapping = null,
        string $path,
        $object
    ) {
        if (null === $classMapping) {
            return [];
        }

        if (!$this->isWithinGroup($context, $classMapping)) {
            return [];
        }

        $this->logPath($path);

        $errors = [];
        foreach ($classMapping->getConstraints() as $constraint) {
            $this->logConstraint($path, $constraint);

            foreach ($constraint->validate($path, $object, $context, $this) as $error) {
                $this->logError($path, $constraint, $error);

                $errors[] = $error;
            }
        }

        return $errors;
    }
534103
public static function export_user_data(approved_contextlist $contextlist) {
        global $DB;

        // Ensure all contexts are CONTEXT_COURSE.
        $contexts = static::validate_contextlist_contexts($contextlist);
        if (empty($contexts)) {
            return;
        }

        // Get the context instance ids from the contexts. These  are the course ids..
        $contextinstanceids = array_map(function($context) {
            return $context->instanceid;
        }, $contexts);
        $userid = $contextlist->get_user()->id;

        // Now, we just need to fetch and format all entries corresponding to the contextids provided.
        $sql = "SELECT ef.action, r.shortname, ef.courseid, ef.timestart, ef.timeend, ef.timemodified
                  FROM {enrol_flatfile} ef
                  JOIN {context} c ON c.contextlevel = :contextlevel AND c.instanceid = ef.courseid
                  JOIN {role} r ON r.id = ef.roleid
                 WHERE ef.userid = :userid";
        $params = ['contextlevel' => CONTEXT_COURSE, 'userid' => $userid];
        list($insql, $inparams) = $DB->get_in_or_equal($contextinstanceids, SQL_PARAMS_NAMED);
        $sql .= " AND ef.courseid $insql";
        $params = array_merge($params, $inparams);

        $futureenrolments = $DB->get_recordset_sql($sql, $params);
        $enrolmentdata = [];
        foreach ($futureenrolments as $futureenrolment) {
            // It's possible to have more than one future enrolment per course.
            $futureenrolment->timestart = transform::datetime($futureenrolment->timestart);
            $futureenrolment->timeend = transform::datetime($futureenrolment->timeend);
            $futureenrolment->timemodified = transform::datetime($futureenrolment->timemodified);
            $enrolmentdata[$futureenrolment->courseid][] = $futureenrolment;
        }
        $futureenrolments->close();

        // And finally, write out the data to the relevant course contexts.
        $subcontext = \core_enrol\privacy\provider::get_subcontext([get_string('pluginname', 'enrol_flatfile')]);
        foreach ($enrolmentdata as $courseid => $enrolments) {
            $data = (object) [
                'pendingenrolments' => $enrolments,
            ];
            writer::with_context(\context_course::instance($courseid))->export_data($subcontext, $data);
        }
    }
1314083
protected function get_role_options($instance, $coursecontext) {
        global $DB;

        $roles = get_assignable_roles($coursecontext);
        $roles[0] = get_string('none');
        $roles = array_reverse($roles, true); // Descending default sortorder.
        if ($instance->id and !isset($roles[$instance->roleid])) {
            if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
                $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true);
                $roles[$instance->roleid] = role_get_name($role, $coursecontext);
            } else {
                $roles[$instance->roleid] = get_string('error');
            }
        }

        return $roles;
    }
1255553
private function getContextOptions()
    {
        $opts = array(
            'http'=>array(
                'ignore_errors' => true,
                'header' => "Accept: application/json, */*\r\nContent-Encoding: gzip\r\n"
            ),
        );

        if (!empty($this->config->getCertificateAuthorityPath())) {
            $opts['ssl']['cafile'] = $this->config->getCertificateAuthorityPath();
        }

        if (!empty($this->config->getClientCertificatePath())) {
            $opts['ssl']['local_cert'] = $this->config->getClientCertificatePath();
        }

        if (!empty($this->config->getClientKeyPath())) {
            $opts['ssl']['local_pk'] = $this->config->getClientKeyPath();
        }

        $token = $this->config->getToken();
        if (!empty($token)) {
            $opts['http']['header'] .= "Authorization: Bearer ${token}\r\n";
        }

        return $opts;
    }
879570
public static function get_filter_options() {
        $options = [];
        $courseformats = get_sorted_course_formats(true);
        foreach ($courseformats as $courseformat) {
            $options[$courseformat] = get_string('pluginname', "format_$courseformat");
        }
        return $options;
    }
32248
public static function get_restore_name(\context $context) {
        global $DB;
        $instanceid = $context->instanceid;

        if ($context->contextlevel == CONTEXT_MODULE) {
            // For modules get the course name and module name.
            $cm = get_coursemodule_from_id('', $context->instanceid, 0, false, MUST_EXIST);
            $coursename = $DB->get_field('course', 'fullname', array('id' => $cm->course));
            $itemname = $coursename . ' - ' . $cm->name;
        } else {
            $itemname = $DB->get_field('course', 'fullname', array('id' => $context->instanceid));

        }

        return $itemname;
    }
1157430
public function get_contextvisibility($context) {
        global $USER;

        if ($context->contextlevel == CONTEXT_COURSE) {
            return $this->_options['enablecourseinstances'];
        }

        if ($context->contextlevel == CONTEXT_USER) {
            return $this->_options['enableuserinstances'];
        }

        //the context is SITE
        return true;
    }
630384
private function get_context_courseid(\context $context) {

        if (empty($this->contextcourseids[$context->id])) {

            $coursecontext = $context->get_course_context(false);
            if (!$coursecontext) {
                // Default to the frontpage course context.
                $coursecontext = \context_course::instance(SITEID);
            }
            $this->contextcourseids[$context->id] = $coursecontext->instanceid;
        }

        return $this->contextcourseids[$context->id];
    }
1281181
protected function get_context_options() {
        if ($this->contextoptions === null) {
            $this->contextoptions = array();
            $displaylist = core_course_category::make_categories_list('moodle/cohort:manage');
            // We need to index the options array by context id instead of category id and add option for system context.
            $syscontext = context_system::instance();
            if (has_capability('moodle/cohort:manage', $syscontext)) {
                $this->contextoptions[$syscontext->id] = $syscontext->get_context_name();
            }
            foreach ($displaylist as $cid => $name) {
                $context = context_coursecat::instance($cid);
                $this->contextoptions[$context->id] = $name;
            }
        }
        return $this->contextoptions;
    }
1174987
protected function get_context_path() : array {
        $path = [];
        $contexts = array_reverse($this->context->get_parent_contexts(true));
        foreach ($contexts as $context) {
            $name = $context->get_context_name();
            $id = ' _.' . $context->id;
            $path[] = shorten_text(clean_param($name, PARAM_FILE),
                    self::MAX_CONTEXT_NAME_LENGTH, true, json_decode('"' . '\u2026' . '"')) . $id;
        }

        return $path;
    }
1232881
private function getProxySettings(RequestContext $context): array
    {
        $proxy = [];

        if (!is_null($context->getProxy())) {
            $proxy[CURLOPT_PROXY] = $context->getProxy();
        }

        return $proxy;
    }
355107
public function getStreamContextOptions()
    {
        $options = [];
        $context = $this->getStreamContext();
        if ($context !== null) {
            $options = stream_context_get_options($context);
        }
        return $options;
    }
894841
protected function getContextOption($option, $default = null)
    {
        $options    = $this->getContextOptions();
        if (array_key_exists($option, $options)) {
            return $options[$option];
        } else {
            return $default;
        }
    }
1351828
public function evaluate(ContextInterface $context): array
    {
        $logger = $this->getLogger();

        $set = $this->getEncodePolicySet();

        $name = Encoder::policySetName($set);
        $logger === null ?: $logger->debug("Policy Decision Point evaluates '$name' policy set.");

        $target = Encoder::policySetTarget($set);
        $match  = $this->evaluateTarget($context, $target, $logger);
        $result = BasePolicyOrSetAlgorithm::evaluateItem($context, $match, $this->getEncodePolicySet(), $logger);

        $logger === null ?: $logger->debug("Policy Decision Point evaluated '$name' policy set.");

        return $result;
    }
220235
protected function get_options() {
        global $CFG;
        $options = parent::get_options();
        $options['file'] =  substr(__FILE__, strlen($CFG->dirroot.'/'));
        $options['context'] = $this->context;
        $options['currentgroup'] = $this->currentgroup;
        $options['forumid'] = $this->forumid;
        return $options;
    }
1070605
public static function get_available_in_context($contexts) {
        $params = self::validate_parameters(self::get_available_in_context_parameters(), array('contexts' => $contexts));
        $filters = $warnings = array();

        foreach ($params['contexts'] as $contextinfo) {
            try {
                $context = self::get_context_from_params($contextinfo);
                self::validate_context($context);
                $contextinfo['contextid'] = $context->id;
            } catch (Exception $e) {
                $warnings[] = array(
                    'item' => 'context',
                    'itemid' => $context['instanceid'],
                    'warningcode' => $e->getCode(),
                    'message' => $e->getMessage(),
                );
                continue;
            }
            $contextfilters = filter_get_available_in_context($context);

            foreach ($contextfilters as $filter) {
                $filters[] = array_merge($contextinfo, (array) $filter);
            }
        }

        return array(
            'filters' => $filters,
            'warnings' => $warnings,
        );
    }