Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 400 and 401]

Zip writer wrapper.

Copyright: 2020 Simey Lameze <simey@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 567 lines (19 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: zipwriter  - X-Ref

Zip writer wrapper.

__construct(\ZipStream\ZipStream $archive, stdClass $options = null)   X-Ref
zipwriter constructor.

param: \ZipStream\ZipStream $archive
param: stdClass|null $options

set_root_context(context $rootcontext)   X-Ref
Set a root context for use during the export.

This is primarily used for creating paths within the archive relative to the root context.

param: context $rootcontext

get_course()   X-Ref
Get the course object for the root context.

return: stdClass

parse_options(stdClass $options)   X-Ref
Parse options.

param: stdClass $options

finish()   X-Ref
Finish writing the zip footer.


get_stream_writer(string $filename, stdClass $exportoptions = null)   X-Ref
Get the stream writer.

param: string $filename
param: stdClass|null $exportoptions
return: static

get_file_writer(string $filename, stdClass $exportoptions = null)   X-Ref
Get the file writer.

param: string $filename
param: stdClass|null $exportoptions
return: static

get_file_path()   X-Ref
Get the file path for a file-based zip writer.

If this is not a file-based writer then no value is returned.

return: null|string

add_file_from_stored_file(context $context,string $filepathinzip,stored_file $file)   X-Ref
Add a file from the File Storage API.

param: context $context
param: string $filepathinzip
param: stored_file $file The file to add

add_file_from_string(context $context,string $filepathinzip,string $content)   X-Ref
Add a file from string content.

param: context $context
param: string $filepathinzip
param: string $content

add_file_from_template(context $context,string $filepathinzip,string $template,stdClass $templatedata)   X-Ref
Create a file based on a Mustache Template and associated data.

param: context $context
param: string $filepathinzip
param: string $template
param: stdClass $templatedata

add_template_requirements()   X-Ref
Ensure that all requirements for a templated page are present.

This includes CSS, and any other similar content.

add_content_from_dirroot(string $dirrootpath, string $pathinzip)   X-Ref
Add content from the dirroot into the specified path in the zip file.

param: string $dirrootpath
param: string $pathinzip

is_file_in_archive(context $context, string $filepathinzip)   X-Ref
Check whether the file was actually added to the archive.

param: context $context
param: string $filepathinzip
return: bool

get_context_path(context $context, string $filepathinzip)   X-Ref
Get the full path to the context within the zip.

param: context $context
param: string $filepathinzip
return: string

get_relative_context_path(context $rootcontext, context $targetcontext, string $filepathinzip)   X-Ref
No description

sanitise_filename(string $filepath)   X-Ref
No description

get_context_folder_name(context $context)   X-Ref
Get the name of the folder for the specified context.

param: context $context
return: string

rewrite_other_pluginfile_urls(context $context,string $content,string $component,string $filearea,?int $pluginfileitemid)   X-Ref
Rewrite any pluginfile URLs in the content.

param: context $context
param: string $content
param: string $component
param: string $filearea
param: null|int $pluginfileitemid The itemid to use in the pluginfile URL when composing any required URLs
return: string

add_pluginfiles_for_content(context $context,string $subdir,string $content,string $component,string $filearea,int $fileitemid,?int $pluginfileitemid)   X-Ref
Export files releating to this text area.

param: context $context
param: string $subdir The sub directory to export any files to
param: string $content
param: string $component
param: string $filearea
param: int $fileitemid The itemid as used in the Files API
param: null|int $pluginfileitemid The itemid to use in the pluginfile URL when composing any required URLs
return: exported_item

get_filepath_for_file(stored_file $file, string $parentdir, bool $escape)   X-Ref
Get the filepath for the specified stored_file.

param: stored_file $file
param: string $parentdir Any parent directory to place this file in
param: bool $escape
return: string