public static function get_policies_with_acceptances($userid) {
        // Get the list of policies and versions that current user is able to see
        // and the respective acceptance records for the selected user.
        $policies = static::list_policies();
        $acceptances = static::get_user_acceptances($userid);
        $ret = [];
        foreach ($policies as $policy) {
            $versions = [];
            if ($policy->currentversion && $policy->currentversion->audience != policy_version::AUDIENCE_GUESTS) {
                if (isset($acceptances[$policy->currentversion->id])) {
                    $policy->currentversion->acceptance = $acceptances[$policy->currentversion->id];
                } else {
                    $policy->currentversion->acceptance = null;
                }
                $versions[] = $policy->currentversion;
            }
            foreach ($policy->archivedversions as $version) {
                if ($version->audience != policy_version::AUDIENCE_GUESTS
                        && static::can_user_view_policy_version($version, $userid)) {
                    $version->acceptance = isset($acceptances[$version->id]) ? $acceptances[$version->id] : null;
                    $versions[] = $version;
                }
            }
            if ($versions) {
                $ret[] = (object)['id' => $policy->id, 'versions' => $versions];
            }
        }

        return $ret;
    }