public function export(string $zipfilename, bool $includeweights = true) : string {

        if (!$this->model) {
            throw new \coding_exception('No model object provided.');
        }

        if (!$this->model->can_export_configuration()) {
            throw new \moodle_exception('errornoexportconfigrequirements', 'analytics');
        }

        $zip = new \zip_packer();
        $zipfiles = [];

        // Model config in JSON.
        $modeldata = $this->export_model_data();

        $exporttmpdir = make_request_directory('analyticsexport');
        $jsonfilepath = $exporttmpdir . DIRECTORY_SEPARATOR . 'model-config.json';
        if (!file_put_contents($jsonfilepath, json_encode($modeldata))) {
            print_error('errornoexportconfig', 'analytics');
        }
        $zipfiles[self::CONFIG_FILE_NAME] = $jsonfilepath;

        // ML backend.
        if ($includeweights && $this->model->is_trained()) {
            $processor = $this->model->get_predictions_processor(true);
            $outputdir = $this->model->get_output_dir(array('execution'));
            $mlbackenddir = $processor->export($this->model->get_unique_id(), $outputdir);
            $mlbackendfiles = get_directory_list($mlbackenddir);
            foreach ($mlbackendfiles as $mlbackendfile) {
                $fullpath = $mlbackenddir . DIRECTORY_SEPARATOR . $mlbackendfile;
                // Place the ML backend files inside a mlbackend/ dir.
                $zipfiles['mlbackend/' . $mlbackendfile] = $fullpath;
            }
        }

        $zipfilepath = $exporttmpdir . DIRECTORY_SEPARATOR . $zipfilename;
        $zip->archive_to_pathname($zipfiles, $zipfilepath);

        return $zipfilepath;
    }