Return an array of valid options for the cohorts.

@param stdClass $instance
@param context $context
@return array
974808
protected function get_cohort_options($instance, $context) {
        global $DB, $CFG;

        require_once($CFG->dirroot . '/cohort/lib.php');

        $cohorts = array();

        if ($instance->id) {
            if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) {
                $name = format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid)));
                $cohorts = array($instance->customint1 => $name);
            } else {
                $cohorts = array($instance->customint1 => get_string('error'));
            }
        } else {
            $cohorts = array('' => get_string('choosedots'));
            $allcohorts = cohort_get_available_cohorts($context, 0, 0, 0);
            foreach ($allcohorts as $c) {
                $cohorts[$c->id] = format_string($c->name);
            }
        }
        return $cohorts;
    }
104218
public function value_editor_options(\context $context = null) {
        global $CFG;
        require_once($CFG->libdir.'/formslib.php');
        if (!$context) {
            $context = $this->get_handler()->get_configuration_context();
        }
        return ['maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'context' => $context];
    }
428714
public function get_instance_name($instance) {
        if (empty($instance->name)) {
            $enrol = $this->get_name();
            return get_string('pluginname', 'enrol_'.$enrol);
        } else {
            $context = context_course::instance($instance->courseid);
            return format_string($instance->name, true, array('context'=>$context));
        }
    }
509027
public static function getClassMethods($context, $class) {
        $methods = array();

        foreach ($class->getMethods() as $method) {
            $meta = static::getMeta($method);
            $methods[$meta['name']] = static::scanDependency($context, preg_replace('/public static function (.+)\\(/', "function {$context['funcprefix']}\$1(", $meta['code']), $meta['code']);
        }

        return $methods;
    }
685380
public function get_action_icons(stdClass $instance) {
        global $OUTPUT;

        $context = context_course::instance($instance->courseid);

        $icons = array();
        if (has_capability('enrol/manual:enrol', $context) or has_capability('enrol/manual:unenrol', $context)) {
            $managelink = new moodle_url("/enrol/manual/manage.php", array('enrolid'=>$instance->id));
            $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_manual'), 'core', array('class'=>'iconsmall')));
        }
        $parenticons = parent::get_action_icons($instance);
        $icons = array_merge($icons, $parenticons);

        return $icons;
    }
704970
public function bind(Context $context)
    {
        if (! isset($context->__UBID)) {
            $context->__UBID = 0;
        }
        $context->__UBID ++;
        
        return spl_object_hash($context) . $context->__UBID;
    }
267560
public function get_child_contexts() {
        global $DB;

        debugging('Fetching of system context child courses is strongly discouraged on production servers (it may eat all available memory)!');

        // Just get all the contexts except for CONTEXT_SYSTEM level
        // and hope we don't OOM in the process - don't cache
        $sql = "SELECT c.*
                  FROM {context} c
                 WHERE contextlevel > ".CONTEXT_SYSTEM;
        $records = $DB->get_records_sql($sql);

        $result = array();
        foreach ($records as $record) {
            $result[$record->id] = context::create_instance_from_record($record);
        }

        return $result;
    }
977144
public function context(Context $context = null) : Context
    {
        if (!$this->context) {
            $this->context = $context ?: new SimpleContext;
        }

        return $this->context;
    }
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;
    }
989158
public static function get_editor_options($context) {
        global $CFG;

        $editoroptions = [
                'subdirs'  => 0,
                'context'  => $context,
                'maxfiles' => EDITOR_UNLIMITED_FILES,
                'maxbytes' => $CFG->maxbytes,
                'noclean' => 0,
                'trusttext' => 0,
                'autosave' => false
        ];

        return $editoroptions;
    }
1225629
private function resolveContext(array $context)
    {
        $defaultOptions = [
            self::OPTION_OBJECT                    => $this->object,
            self::OPTION_EXCEPTION_ON_INVALID_TYPE => $this->exceptionOnInvalidType,
            self::OPTION_OBJECT_FOR_MAP            => $this->objectForMap,
            self::OPTION_MULTI_LINE_LITERAL_BLOCK  => $this->multiLineLiteralBlock,
            self::OPTION_INLINE                    => $this->inline,
            self::OPTION_INDENT                    => $this->indent,
        ];

        return array_merge($defaultOptions, $context);
    }
1091114
protected function context()
    {
        return collect($this->option())->only([
            'ansi',
            'no-ansi',
            'no-interaction',
            'quiet',
            'verbose',
        ])->filter()->mapWithKeys(function ($value, $key) {
            return ["--{$key}" => $value];
        })->all();
    }
753450
public static function get_context_data(\context $context, \stdClass $user) : \stdClass {
        global $DB;

        $basedata = (object) [];
        if ($context instanceof \context_module) {
            return static::get_context_module_data($context, $user);
        }
        if ($context instanceof \context_block) {
            return static::get_context_block_data($context, $user);
        }

        return $basedata;
    }
1309496
protected function _meridianSelect($options, $context)
    {
        $options += [
            'name' => '',
            'val' => null,
            'options' => ['am' => 'am', 'pm' => 'pm'],
            'templateVars' => [],
        ];

        return $this->_select->render($options, $context);
    }
202251
public static function export_context_files(\context $context, \stdClass $user) {
        if ($context instanceof \context_module) {
            return static::export_context_module_files($context, $user);
        }
    }
418661
protected function doMethodConfiguration($instance, stdClass $prototype)
    {
        foreach ($prototype as $method => $args) {
            call_user_func_array([$instance, $method], $args);
        }

        return $instance;
    }
1029289
protected function registerDeferredServiceProvider($provider, ServiceProvider $instance): array
    {
        $deferred = [];

        foreach ($instance->provides() as $provide) {
            $deferred[$provide] = $provider;
        }

        return [
            'instance' => $instance,
            'eager'    => false,
            'when'     => $instance->when(),
            'deferred' => $deferred,
        ];
    }