MIDDAG for Moodle

form_service

Table of Contents

Methods

generate_file_exporter()  : moodle_url
Generates a file exporter URL based on the provided form data.
generate_file_url()  : moodle_url
Generates a URL for the exported file based on the provided content and form.
get_form_by_idnumber()  : false|deprecated_item
Retrieves a form by its idnumber.
replicate()  : stdClass
Imports a form object, validates its structure, creates a new form if necessary, and performs custom form actions. Updates the form ID if the import is successful.
validate_import_structure()  : bool
Validates the structure of an imported JSON object for a form configuration system.
apply_map_recursive()  : mixed
Recursively applies a mapping to the given data structure. The method traverses arrays, replaces specific values based on a map, and calls itself recursively for nested arrays.
map_all_ids()  : array<string|int, mixed>
Maps all IDs from the input data to new UUID v4 values.
uuid4()  : string
Generates a random UUID (version 4) string based on RFC 4122.

Methods

generate_file_exporter()

Generates a file exporter URL based on the provided form data.

public static generate_file_exporter(form $form) : moodle_url
Parameters
$form : form

the form object containing the raw data to process

Tags
throws
moodle_exception

if the provided form data is invalid JSON

throws
RandomException
throws
JsonException
Return values
moodle_url

the generated URL for the file exporter

generate_file_url()

Generates a URL for the exported file based on the provided content and form.

public static generate_file_url(string $content, form $form) : moodle_url
Parameters
$content : string

the content to be written to the generated file

$form : form

the form object used to generate the file's metadata and context

Return values
moodle_url

the URL pointing to the generated file

get_form_by_idnumber()

Retrieves a form by its idnumber.

public static get_form_by_idnumber(string $idnumber) : false|deprecated_item
Parameters
$idnumber : string

the unique identifier of the form

Tags
throws
coding_exception
throws
dml_exception
Return values
false|deprecated_item

the form object if found, or false if no matching form exists

replicate()

Imports a form object, validates its structure, creates a new form if necessary, and performs custom form actions. Updates the form ID if the import is successful.

public static replicate(stdClass $form) : stdClass
Parameters
$form : stdClass

The form object to be imported. The structure and configuration of the form will be validated during this process.

Tags
throws
moodle_exception

throws an exception if the form structure is invalid or if there is an error during the import process

Return values
stdClass

the imported form object with updated ID and configurations

validate_import_structure()

Validates the structure of an imported JSON object for a form configuration system.

public static validate_import_structure(stdClass $json) : bool
Parameters
$json : stdClass

The JSON object to be validated. Expected to contain specific properties and nested structures.

Return values
bool

returns true if the structure of the JSON object is valid, false otherwise

apply_map_recursive()

Recursively applies a mapping to the given data structure. The method traverses arrays, replaces specific values based on a map, and calls itself recursively for nested arrays.

private static apply_map_recursive(mixed $data, array<string|int, mixed> $map) : mixed
Parameters
$data : mixed

The data structure to be processed, typically an array or a string. Can also include nested arrays.

$map : array<string|int, mixed>

an associative array where keys represent the values to be replaced, and their corresponding values are the replacements

Return values
mixed

Returns the processed data structure with values replaced as per the mapping. If the input is not an array, it returns the unmodified input.

map_all_ids()

Maps all IDs from the input data to new UUID v4 values.

private static map_all_ids(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

input data containing form configuration and action flow with fields, nodes, and edges

Tags
throws
RandomException
Return values
array<string|int, mixed>

an associative array mapping original IDs to newly generated UUID v4 values

uuid4()

Generates a random UUID (version 4) string based on RFC 4122.

private static uuid4() : string
Tags
throws
RandomException
Return values
string

returns the generated UUID v4 as a 36-character string, formatted as xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx, where M indicates the version and N indicates the variant


        
On this page

Search results