Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
core_privacy\local\request\moodle_content_writer Class Reference

The moodle_content_writer is the default Moodle implementation of a content writer. More...

Inheritance diagram for core_privacy\local\request\moodle_content_writer:
core_privacy\local\request\content_writer

Public Member Functions

 __construct (writer $writer)
 Constructor for the content writer. More...
 
 export_area_files (array $subcontext, $component, $filearea, $itemid)
 Export all files within the specified component, filearea, itemid combination. More...
 
 export_custom_file (array $subcontext, $filename, $filecontent)
 Export a piece of data in a custom format. More...
 
 export_data (array $subcontext, stdClass $data)
 Export the supplied data within the current context, at the supplied subcontext. More...
 
 export_file (array $subcontext, stored_file $file)
 Export the specified file in the target location. More...
 
 export_metadata (array $subcontext, string $key, $value, string $description)
 Export metadata about the supplied subcontext. More...
 
 export_related_data (array $subcontext, $name, $data)
 Export a piece of related data. More...
 
 export_user_preference (string $component, string $key, string $value, string $description)
 Export the specified user preference. More...
 
 finalise_content ()
 Perform any required finalisation steps and return the location of the finalised export. More...
 
 rewrite_pluginfile_urls (array $subcontext, $component, $filearea, $itemid, $text)
 Prepare a text area by processing pluginfile URLs within it. More...
 
 set_context (\context $context)
 Set the context for the current item being processed. More...
 

Public Attributes

const MAX_CONTEXT_NAME_LENGTH = 32
 Maximum context name char size.
 

Protected Member Functions

 check_plugin_is_installed (string $component)
 Check to see if a specified plugin is installed. More...
 
 condense_array (array $array)
 Creates a multidimensional array out of array elements. More...
 
 copy_data (array $path, array $destination)
 Copy a file to the specified path. More...
 
 get_context_path ()
 Determine the path for the current context. More...
 
 get_file_content (string $filepath)
 Get the contents of a file. More...
 
 get_files_target_path ($component, $filearea, $itemid)
 Get a path within a subcontext where exported files should be written to. More...
 
 get_files_target_url ($component, $filearea, $itemid)
 Get a relative url to the directory of the exported files within a subcontext. More...
 
 get_full_path (array $subcontext, string $name)
 Get the fully-qualified file path within the current context, and subcontext, using the specified filename. More...
 
 get_path (array $subcontext, string $name)
 Get the relative file path within the current context, and subcontext, using the specified filename. More...
 
 make_tree_object (array $tree, array $treekey, array $currentkey=[])
 Add more detail to the tree to help with sorting and display in the renderer. More...
 
 prepare_for_export ()
 This creates three different bits of data from all of the files that will be exported. More...
 
 sort_my_list (array &$tree)
 Sorts the tree list into an order that makes more sense. More...
 
 write_data (string $path, string $data)
 Write the data to the specified path. More...
 
 write_html_data ()
 Writes the appropriate files for creating an HTML index page for human navigation of the user data export.
 

Protected Attributes

array $checkedplugins = []
 The list of plugins that have been checked to see if they are installed.
 
context $context = null
 The current context of the writer.
 
stored_file[] $files = []
 The list of files to be exported.
 
string $path = null
 The base path on disk for this instance.
 

Detailed Description

The moodle_content_writer is the default Moodle implementation of a content writer.

It exports data to a rich tree structure using Moodle's context system, and produces a single zip file with all content.

Objects of data are stored as JSON.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core_privacy\local\request\moodle_content_writer::__construct ( writer  $writer)

Constructor for the content writer.

Note: The writer factory must be passed.

Parameters
writer$writerThe factory.

Implements core_privacy\local\request\content_writer.

Member Function Documentation

◆ check_plugin_is_installed()

core_privacy\local\request\moodle_content_writer::check_plugin_is_installed ( string  $component)
protected

Check to see if a specified plugin is installed.

Parameters
string$componentThe component name e.g. tool_log
Return values
boolWhether this component is installed.

◆ condense_array()

core_privacy\local\request\moodle_content_writer::condense_array ( array  $array)
protected

Creates a multidimensional array out of array elements.

Parameters
array$arrayArray which items are to be condensed into a multidimensional array.
Return values
arrayThe multidimensional array.

◆ copy_data()

core_privacy\local\request\moodle_content_writer::copy_data ( array  $path,
array  $destination 
)
protected

Copy a file to the specified path.

Parameters
array$pathCurrent location of the file.
array$destinationDestination path to copy the file to.

◆ export_area_files()

core_privacy\local\request\moodle_content_writer::export_area_files ( array  $subcontext,
  $component,
  $filearea,
  $itemid 
)

Export all files within the specified component, filearea, itemid combination.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$componentThe name of the component that the files belong to.
string$fileareaThe filearea within that component.
string$itemidWhich item those files belong to.

Implements core_privacy\local\request\content_writer.

◆ export_custom_file()

core_privacy\local\request\moodle_content_writer::export_custom_file ( array  $subcontext,
  $filename,
  $filecontent 
)

Export a piece of data in a custom format.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$filenameThe name of the file to be exported.
string$filecontentThe content to be exported.

Implements core_privacy\local\request\content_writer.

◆ export_data()

core_privacy\local\request\moodle_content_writer::export_data ( array  $subcontext,
stdClass  $data 
)

Export the supplied data within the current context, at the supplied subcontext.

Parameters
array$subcontextThe location within the current context that this data belongs.
stdClass$dataThe data to be exported
Return values
content_writer

Implements core_privacy\local\request\content_writer.

◆ export_file()

core_privacy\local\request\moodle_content_writer::export_file ( array  $subcontext,
stored_file  $file 
)

Export the specified file in the target location.

Parameters
array$subcontextThe location within the current context that this data belongs.
stored_file$fileThe file to be exported.

Implements core_privacy\local\request\content_writer.

◆ export_metadata()

core_privacy\local\request\moodle_content_writer::export_metadata ( array  $subcontext,
string  $key,
  $value,
string  $description 
)

Export metadata about the supplied subcontext.

Metadata consists of a key/value pair and a description of the value.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$keyThe metadata name.
string$valueThe metadata value.
string$descriptionThe description of the value.
Return values
content_writer

Implements core_privacy\local\request\content_writer.

◆ export_related_data()

core_privacy\local\request\moodle_content_writer::export_related_data ( array  $subcontext,
  $name,
  $data 
)

Export a piece of related data.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$nameThe name of the file to be exported.
stdClass$dataThe related data to export.
Return values
content_writer

Implements core_privacy\local\request\content_writer.

◆ export_user_preference()

core_privacy\local\request\moodle_content_writer::export_user_preference ( string  $component,
string  $key,
string  $value,
string  $description 
)

Export the specified user preference.

Parameters
string$componentThe name of the component.
string$keyThe name of th key to be exported.
string$valueThe value of the preference
string$descriptionA description of the value
Return values
content_writer

Implements core_privacy\local\request\content_writer.

◆ finalise_content()

core_privacy\local\request\moodle_content_writer::finalise_content ( )

Perform any required finalisation steps and return the location of the finalised export.

Return values
string

Implements core_privacy\local\request\content_writer.

◆ get_context_path()

core_privacy\local\request\moodle_content_writer::get_context_path ( )
protected

Determine the path for the current context.

Return values
arrayThe context path.
Exceptions
coding_exception

◆ get_file_content()

core_privacy\local\request\moodle_content_writer::get_file_content ( string  $filepath)
protected

Get the contents of a file.

Parameters
string$filepathThe file path.
Return values
stringcontents of the file.
Exceptions
moodle_exceptionIf the file cannot be opened.

◆ get_files_target_path()

core_privacy\local\request\moodle_content_writer::get_files_target_path (   $component,
  $filearea,
  $itemid 
)
protected

Get a path within a subcontext where exported files should be written to.

Parameters
string$componentThe name of the component that the files belong to.
string$fileareaThe filearea within that component.
string$itemidWhich item those files belong to.
Return values
stringThe path

◆ get_files_target_url()

core_privacy\local\request\moodle_content_writer::get_files_target_url (   $component,
  $filearea,
  $itemid 
)
protected

Get a relative url to the directory of the exported files within a subcontext.

Parameters
string$componentThe name of the component that the files belong to.
string$fileareaThe filearea within that component.
string$itemidWhich item those files belong to.
Return values
stringThe url

◆ get_full_path()

core_privacy\local\request\moodle_content_writer::get_full_path ( array  $subcontext,
string  $name 
)
protected

Get the fully-qualified file path within the current context, and subcontext, using the specified filename.

Parameters
string[]$subcontextThe location within the current context to export this data.
string$nameThe intended filename, including any extensions.
Return values
stringThe fully-qualfiied file path.

◆ get_path()

core_privacy\local\request\moodle_content_writer::get_path ( array  $subcontext,
string  $name 
)
protected

Get the relative file path within the current context, and subcontext, using the specified filename.

Parameters
string[]$subcontextThe location within the current context to export this data.
string$nameThe intended filename, including any extensions.
Return values
stringThe fully-qualfiied file path.

◆ make_tree_object()

core_privacy\local\request\moodle_content_writer::make_tree_object ( array  $tree,
array  $treekey,
array  $currentkey = [] 
)
protected

Add more detail to the tree to help with sorting and display in the renderer.

Parameters
array$treeThe file structure currently as a multidimensional array.
array$treekeyAn array of the current file paths.
array$currentkeyThe current short path of the tree.
Return values
arrayAn array of objects that has additional data.

◆ prepare_for_export()

core_privacy\local\request\moodle_content_writer::prepare_for_export ( )
protected

This creates three different bits of data from all of the files that will be exported.

$tree - A multidimensional array of the navigation tree structure. $treekey - An array with the short path of the file and element data for html (data_file_{number} or 'No var') $allfiles - All *.json files that need to be added as an index to be referenced by the js files to display the user data.

Return values
arrayreturns a tree, tree key, and a list of all files.

◆ rewrite_pluginfile_urls()

core_privacy\local\request\moodle_content_writer::rewrite_pluginfile_urls ( array  $subcontext,
  $component,
  $filearea,
  $itemid,
  $text 
)

Prepare a text area by processing pluginfile URLs within it.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$componentThe name of the component that the files belong to.
string$fileareaThe filearea within that component.
string$itemidWhich item those files belong to.
string$textThe text to be processed
Return values
stringThe processed string

Implements core_privacy\local\request\content_writer.

◆ set_context()

core_privacy\local\request\moodle_content_writer::set_context ( \context  $context)

Set the context for the current item being processed.

Parameters
context$contextThe context to use

Implements core_privacy\local\request\content_writer.

◆ sort_my_list()

core_privacy\local\request\moodle_content_writer::sort_my_list ( array &  $tree)
protected

Sorts the tree list into an order that makes more sense.

Order is: 1 - Items with a context first, the lower the number the higher up the tree. 2 - Items that are directories. 3 - Items that are log directories. 4 - Links to a page.

Parameters
array$treeThe tree structure to order.

◆ write_data()

core_privacy\local\request\moodle_content_writer::write_data ( string  $path,
string  $data 
)
protected

Write the data to the specified path.

Parameters
string$pathThe path to export the data at.
string$dataThe data to be exported.
Exceptions
moodle_exceptionIf the file cannot be written for some reason.

The documentation for this class was generated from the following file: