public static function get_relevant_users($query, $courseid) {
        global $CFG, $PAGE;

        // Validate parameter.
        self::validate_parameters(self::get_relevant_users_parameters(),
                ['query' => $query, 'courseid' => $courseid]);

        // Validate the context (search page is always system context).
        $systemcontext = \context_system::instance();
        self::validate_context($systemcontext);

        // Get course object too.
        if ($courseid) {
            $coursecontext = \context_course::instance($courseid);
        } else {
            $coursecontext = null;
        }

        // If not logged in, can't see anyone when forceloginforprofiles is on.
        if (!empty($CFG->forceloginforprofiles)) {
            if (!isloggedin() || isguestuser()) {
                return [];
            }
        }

        $users = \core_user::search($query, $coursecontext);

        $result = [];
        foreach ($users as $user) {
            // Get a standard exported user object.
            $fulldetails = (new user_summary_exporter($user))->export($PAGE->get_renderer('core'));

            // To avoid leaking private data to students, only include the specific information we
            // are going to display (and not the email, idnumber, etc).
            $result[] = (object)['id' => $fulldetails->id, 'fullname' => $fulldetails->fullname,
                    'profileimageurlsmall' => $fulldetails->profileimageurlsmall];
        }
        return $result;
    }