public static function get_policy_version($versionid, $policies = null) {
        if ($policies === null) {
            $policies = self::list_policies();
        }
        foreach ($policies as $policy) {
            if ($policy->currentversionid == $versionid) {
                return $policy->currentversion;

            } else {
                foreach ($policy->draftversions as $draft) {
                    if ($draft->id == $versionid) {
                        return $draft;
                    }
                }

                foreach ($policy->archivedversions as $archived) {
                    if ($archived->id == $versionid) {
                        return $archived;
                    }
                }
            }
        }

        throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
    }