public function get_output_dir($subdirs = array(), $onlymodelid = false) {
        global $CFG;

        $subdirstr = '';
        foreach ($subdirs as $subdir) {
            $subdirstr .= DIRECTORY_SEPARATOR . $subdir;
        }

        $outputdir = get_config('analytics', 'modeloutputdir');
        if (empty($outputdir)) {
            // Apply default value.
            $outputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
        }

        // Append model id.
        $outputdir .= DIRECTORY_SEPARATOR . $this->model->id;
        if (!$onlymodelid) {
            // Append version + subdirs.
            $outputdir .= DIRECTORY_SEPARATOR . $this->model->version . $subdirstr;
        }

        make_writable_directory($outputdir);

        return $outputdir;
    }