protected function prepare_policy($policyid, $versionid) {

        if ($versionid) {
            $this->policy = api::get_policy_version($versionid);

        } else {
            $this->policy = array_reduce(api::list_current_versions(), function ($carry, $current) use ($policyid) {
                if ($current->policyid == $policyid) {
                    return $current;
                }
                return $carry;
            });
        }

        if (empty($this->policy)) {
            throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
        }
    }