public static function get_user_minors($userid, array $extrafields = null) {
        global $DB;

        $ctxfields = context_helper::get_preload_record_columns_sql('c');
        $namefields = get_all_user_name_fields(true, 'u');
        $pixfields = user_picture::fields('u', $extrafields);

        $sql = "SELECT $ctxfields, $namefields, $pixfields
                  FROM {role_assignments} ra
                  JOIN {context} c ON c.contextlevel = ".CONTEXT_USER." AND ra.contextid = c.id
                  JOIN {user} u ON c.instanceid = u.id
                 WHERE ra.userid = ?
              ORDER BY u.lastname ASC, u.firstname ASC";

        $rs = $DB->get_recordset_sql($sql, [$userid]);

        $minors = [];

        foreach ($rs as $record) {
            context_helper::preload_from_record($record);
            $childcontext = context_user::instance($record->id);
            if (has_capability('tool/policy:acceptbehalf', $childcontext, $userid)) {
                $minors[$record->id] = $record;
            }
        }

        $rs->close();

        return $minors;
    }