Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

This file contains the moodle format implementation of the content writer.

Copyright: 2018 Andrew Nicols <andrew@nicols.co.uk>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 550 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: content_writer  - X-Ref

An implementation of the content_writer for use in unit tests.

This implementation does not export any data but instead stores it in
structures within the instance which can be easily queried for use
during unit tests.

has_any_data($subcontext = [])   X-Ref
Whether any data has been exported at all within the current context.

return: bool
param: array $subcontext The location within the current context that this data belongs -

has_any_data_in_any_context()   X-Ref
Whether any data has been exported for any context.

return: bool

__construct(\core_privacy\local\request\writer $writer)   X-Ref
Constructor for the content writer.

Note: The writer_factory must be passed.
param: \core_privacy\local\request\writer          $writer    The writer factory.

set_context(\context $context)   X-Ref
Set the context for the current item being processed.

param: \context        $context    The context to use

get_current_context()   X-Ref
Return the current context.

return: \context

export_data(array $subcontext, \stdClass $data)   X-Ref
Export the supplied data within the current context, at the supplied subcontext.

param: array           $subcontext The location within the current context that this data belongs.
param: \stdClass       $data       The data to be exported

get_data(array $subcontext = [])   X-Ref
Get all data within the subcontext.

return: array                       The metadata as a series of keys to value + descrition objects.
param: array           $subcontext The location within the current context that this data belongs.

export_metadata(array $subcontext, string $key, $value, string $description)   X-Ref
Export metadata about the supplied subcontext.

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

return: $this
param: array           $subcontext The location within the current context that this data belongs.
param: string          $key        The metadata name.
param: string          $value      The metadata value.
param: string          $description    The description of the value.

get_all_metadata(array $subcontext = [])   X-Ref
Get all metadata within the subcontext.

return: array                       The metadata as a series of keys to value + descrition objects.
param: array           $subcontext The location within the current context that this data belongs.

get_metadata(array $subcontext, $key, $valueonly = true)   X-Ref
Get the specified metadata within the subcontext.

return: array                       The metadata as a series of keys to value + descrition objects.
param: array           $subcontext The location within the current context that this data belongs.
param: string          $key        The metadata to be fetched within the context + subcontext.
param: boolean         $valueonly  Whether to fetch only the value, rather than the value + description.

export_related_data(array $subcontext, $name, $data)   X-Ref
Export a piece of related data.

param: array           $subcontext The location within the current context that this data belongs.
param: string          $name       The name of the file to be exported.
param: \stdClass       $data       The related data to export.

get_related_data(array $subcontext = [], $filename = null)   X-Ref
Get all data within the subcontext.

return: array                       The metadata as a series of keys to value + descrition objects.
param: array           $subcontext The location within the current context that this data belongs.
param: string          $filename   The name of the intended filename.

export_custom_file(array $subcontext, $filename, $filecontent)   X-Ref
Export a piece of data in a custom format.

param: array           $subcontext The location within the current context that this data belongs.
param: string          $filename   The name of the file to be exported.
param: string          $filecontent    The content to be exported.

get_custom_file(array $subcontext = [], $filename = null)   X-Ref
Get the specified custom file within the subcontext.

return: string                      The content of the file.
param: array           $subcontext The location within the current context that this data belongs.
param: string          $filename   The name of the file to be fetched within the context + subcontext.

rewrite_pluginfile_urls(array $subcontext, $component, $filearea, $itemid, $text)   X-Ref
Prepare a text area by processing pluginfile URLs within it.

Note that this method does not implement the pluginfile URL rewriting. Such a job tightly depends on how the
actual writer exports files so it can be reliably tested only in real writers such as
{@link core_privacy\local\request\moodle_content_writer}.

However we have to remove @@PLUGINFILE@@ since otherwise {@link format_text()} shows debugging messages

return: string                      The processed string
param: array           $subcontext The location within the current context that this data belongs.
param: string          $component  The name of the component that the files belong to.
param: string          $filearea   The filearea within that component.
param: string          $itemid     Which item those files belong to.
param: string          $text       The text to be processed

export_area_files(array $subcontext, $component, $filearea, $itemid)   X-Ref
Export all files within the specified component, filearea, itemid combination.

param: array           $subcontext The location within the current context that this data belongs.
param: string          $component  The name of the component that the files belong to.
param: string          $filearea   The filearea within that component.
param: string          $itemid     Which item those files belong to.

export_file(array $subcontext, \stored_file $file)   X-Ref
Export the specified file in the target location.

param: array           $subcontext The location within the current context that this data belongs.
param: \stored_file    $file       The file to be exported.

get_files(array $subcontext = [])   X-Ref
Get all files in the specfied subcontext.

return: \stored_file[]              The list of stored_files in this context + subcontext.
param: array           $subcontext The location within the current context that this data belongs.

export_user_preference(string $component,string $key,string $value,string $description)   X-Ref
Export the specified user preference.

return: \core_privacy\local\request\content_writer
param: string          $component  The name of the component.
param: string          $key        The name of th key to be exported.
param: string          $value      The value of the preference
param: string          $description    A description of the value

get_user_preferences(string $component)   X-Ref
Get all user preferences for the specified component.

return: \stdClass
param: string          $component  The name of the component.

get_user_context_preferences(string $component)   X-Ref
Get all user preferences for the specified component.

return: \stdClass
param: string          $component  The name of the component.

finalise_content()   X-Ref
Perform any required finalisation steps and return the location of the finalised export.

return: string

fetch_root($base, $subcontext, $temporarycontextid = null)   X-Ref
Fetch the entire root record at the specified location type, creating it if required.

return: array
param: \stdClass   $base The base to use - e.g. $this->data
param: array       $subcontext The subcontext to fetch
param: int         $temporarycontextid A temporary context ID to use for the fetch.

fetch_data_root($base, $subcontext)   X-Ref
Fetch the data region of the specified root.

return: array
param: \stdClass   $base The base to use - e.g. $this->data
param: array       $subcontext The subcontext to fetch