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 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 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.

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

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.

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

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.

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.
return: $this

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

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

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

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.
return: array                       The metadata as a series of keys to value + descrition objects.

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.

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

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.

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.
return: string                      The content of the file.

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

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
return: string                      The processed string

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.

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

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

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
return: \core_privacy\local\request\content_writer

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

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

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

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

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.

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.
return: array

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

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