Moodle PHP Documentation 4.4
Moodle 4.4.8+ (Build: 20250530) (000b0c27711)
restore_qtype_calculated_plugin Class Reference

restore plugin class that provides the necessary information needed to restore one calculated qtype plugin More...

Inheritance diagram for restore_qtype_calculated_plugin:
restore_qtype_plugin restore_plugin restore_qtype_calculatedmulti_plugin restore_qtype_calculatedsimple_plugin

Public Member Functions

 define_plugin_structure ($connectionpoint)
 
 get_excluded_identity_hash_fields ()
 Return fields to be excluded from hashing during restores.
 
 launch_after_execute_methods ()
 after_execute dispatcher for any restore_plugin class
 
 launch_after_restore_methods ()
 after_restore dispatcher for any restore_plugin class
 
 process_calculated_option ($data)
 Process the qtype/calculated_option element.
 
 process_calculated_record ($data)
 Process the qtype/calculated_record element.
 
 process_question_answer ($data)
 Processes the answer element (question answers).
 
 process_question_dataset_definition ($data)
 Processes the dataset_definition element (question dataset definitions).
 
 process_question_dataset_item ($data)
 Processes the dataset_item element (question dataset items).
 
 process_question_numerical_option ($data)
 Processes the numerical_option element (question numerical options).
 
 process_question_numerical_unit ($data)
 Processes the numerical_unit element (question numerical units).
 
 recode_legacy_state_answer ($state)
 Decode legacy question_states.answer for this qtype.
 
 recode_response ($questionid, $sequencenumber, array $response)
 Do any re-coding necessary in the student response.
 

Static Public Member Functions

static convert_backup_to_questiondata (array $backupdata)
 Convert the backup structure of this question type into a structure matching its question data.
 
static define_plugin_decode_contents ()
 Return the contents of the questions stuff that must be processed by the links decoder.
 
static get_restore_decode_contents ($plugintype)
 Returns one array with all the decode contents to be processed by the links decoder.
 
static remove_excluded_question_data (stdClass $questiondata, array $excludefields=[])
 Remove excluded fields from the questiondata structure.
 

Protected Member Functions

 add_question_datasets (&$paths)
 Add to $paths the restore_path_elements needed to handle question_datasets (defs and items) for a given question Used by various qtypes (calculated, numerical)
 
 add_question_numerical_options (&$paths)
 Add to $paths the restore_path_elements needed to handle question_numerical_options for a given question Used by various qtypes (calculated, numerical)
 
 add_question_numerical_units (&$paths)
 Add to $paths the restore_path_elements needed to handle question_numerical_units for a given question Used by various qtypes (calculated, numerical)
 
 add_question_question_answers (&$paths)
 Add to $paths the restore_path_elements needed to handle question_answers for a given question Used by various qtypes (calculated, essay, multianswer, multichoice, numerical, shortanswer, truefalse)
 
 add_related_files ($component, $filearea, $mappingitemname, $filesctxid=null, $olditemid=null)
 Add all the existing file, given their component and filearea and one backup_ids itemname to match with.
 
 apply_date_offset ($value)
 Apply course startdate offset based in original course startdate and course_offset_startdate setting Note we are using one static cache here, but by restoreid, so it's ok for concurrence/multiple executions in the same request.
 
 define_excluded_identity_hash_fields ()
 Return a list of paths to fields to be removed from questiondata before creating an identity hash.
 
 define_question_plugin_structure ()
 Returns the paths to be handled by the plugin at question level.
 
 get_mapping ($itemname, $oldid)
 Return the complete mapping from the given itemname, itemid.
 
 get_mappingid ($itemname, $oldid, $ifnotfound=false)
 Return the new id of a mapping for the given itemname.
 
 get_namefor ($name='')
 Simple helper function that returns the name for the restore_path_element It's not mandatory to use it but recommended ;-)
 
 get_new_parentid ($itemname)
 Returns the latest (parent) new id mapped by one pathelement.
 
 get_old_parentid ($itemname)
 Returns the latest (parent) old id mapped by one pathelement.
 
 get_pathfor ($path='')
 Simple helper function that returns the base (prefix) of the path for the restore_path_element Useful if we used get_recommended_name() in backup.
 
 get_restoreid ()
 
 get_setting_value ($name)
 Returns the value of one (task/plan) setting.
 
 get_task ()
 Get the task we are part of.
 
 set_mapping ($itemname, $oldid, $newid, $restorefiles=false, $filesctxid=null, $parentid=null)
 To send ids pairs to backup_ids_table and to store them into paths.
 

Protected Attributes

restore_path_element $connectionpoint
 
array array $excludedhashfields = []
 List of fields to exclude form hashing during restore.
 
string $pluginname
 
string $plugintype
 
restore_structure_step $step
 
restore_course_task restore_activity_task $task
 

Detailed Description

restore plugin class that provides the necessary information needed to restore one calculated qtype plugin

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

Member Function Documentation

◆ convert_backup_to_questiondata()

static restore_qtype_calculated_plugin::convert_backup_to_questiondata ( array $backupdata)
static

Convert the backup structure of this question type into a structure matching its question data.

This should take the hierarchical array of tags from the question's backup structure, and return a structure that matches that returned when calling {

See also
get_question_options()} for this question type. See https://docs.moodle.org/dev/Question_data_structures#Representation_1:_%24questiondata for an explanation of this structure.

This data will then be used to produce an identity hash for comparison with questions in the database.

This base implementation deals with all common backup elements created by the add_question_*_options() methods in this class, plus elements added by define_question_plugin_structure() named for the qtype. The question type will need to extend this function if define_question_plugin_structure() adds any other elements to the backup.

Parameters
array$backupdataThe hierarchical array of tags from the backup.
Return values
stdClassThe questiondata object.

Reimplemented from restore_qtype_plugin.

◆ define_excluded_identity_hash_fields()

restore_qtype_calculated_plugin::define_excluded_identity_hash_fields ( )
protected

Return a list of paths to fields to be removed from questiondata before creating an identity hash.

Fields that should be excluded from common elements such as answers or numerical units that are used by the plugin will be excluded automatically. This method just needs to define any specific to this plugin, such as foreign keys used in the plugin's tables.

The returned array should be a list of slash-delimited paths to locate the fields to be removed from the questiondata object. For example, if you want to remove the field $questiondata->options->questionid, the path would be '/options/questionid'. If a field in the path is an array, the rest of the path will be applied to each object in the array. So if you have $questiondata->options->answers[], the path '/options/answers/id' will remove the 'id' field from each element of the 'answers' array.

Return values
array

Reimplemented from restore_qtype_plugin.

Reimplemented in restore_qtype_calculatedmulti_plugin.

◆ define_plugin_decode_contents()

static restore_qtype_plugin::define_plugin_decode_contents ( )
staticinherited

Return the contents of the questions stuff that must be processed by the links decoder.

Only common stuff to all plugins, in this case:

  • question: text and feedback
  • question_answers: text and feedback
  • question_hints: hint

Note each qtype will have, if needed, its own define_decode_contents method

Reimplemented from restore_plugin.

◆ get_excluded_identity_hash_fields()

restore_qtype_plugin::get_excluded_identity_hash_fields ( )
finalinherited

Return fields to be excluded from hashing during restores.

Return values
array

◆ get_mappingid()

restore_plugin::get_mappingid ( $itemname,
$oldid,
$ifnotfound = false )
protectedinherited

Return the new id of a mapping for the given itemname.

Parameters
string$itemnamethe type of item
int$oldidthe item ID from the backup
mixed$ifnotfoundwhat to return if $oldid wasnt found. Defaults to false

◆ get_pathfor()

restore_plugin::get_pathfor ( $path = '')
protectedinherited

Simple helper function that returns the base (prefix) of the path for the restore_path_element Useful if we used get_recommended_name() in backup.

It's not mandatory to use it but recommended ;-)

◆ get_restore_decode_contents()

static restore_plugin::get_restore_decode_contents ( $plugintype)
staticinherited

Returns one array with all the decode contents to be processed by the links decoder.

This method, given one plugin type, returns one array of restore_decode_content objects that will be added to the restore decoder in order to perform modifications under the plugin contents.

The objects are retrieved by calling to the define_decode_contents method (when available), first in the main restore_xxxx_plugin class and later on each of the available subclasses

◆ get_task()

restore_plugin::get_task ( )
protectedinherited

Get the task we are part of.

Return values
restore_activity_task|restore_course_taskthe task.

◆ launch_after_execute_methods()

restore_plugin::launch_after_execute_methods ( )
inherited

after_execute dispatcher for any restore_plugin class

This method will dispatch execution to the corresponding after_execute_xxx() method when available, with xxx being the connection point of the instance, so plugin classes with multiple connection points will support multiple after_execute methods, one for each connection point

◆ launch_after_restore_methods()

restore_plugin::launch_after_restore_methods ( )
inherited

after_restore dispatcher for any restore_plugin class

This method will dispatch execution to the corresponding after_restore_xxx() method when available, with xxx being the connection point of the instance, so plugin classes with multiple connection points will support multiple after_restore methods, one for each connection point

◆ process_question_answer()

restore_qtype_plugin::process_question_answer ( $data)
inherited

Processes the answer element (question answers).

Common for various qtypes. It handles both creation (if the question is being created) and mapping (if the question already existed and is being reused)

◆ process_question_dataset_definition()

restore_qtype_plugin::process_question_dataset_definition ( $data)
inherited

Processes the dataset_definition element (question dataset definitions).

Common for various qtypes. It handles both creation (if the question is being created) and mapping (if the question already existed and is being reused)

◆ process_question_dataset_item()

restore_qtype_plugin::process_question_dataset_item ( $data)
inherited

Processes the dataset_item element (question dataset items).

Common for various qtypes. It handles both creation (if the question is being created) and mapping (if the question already existed and is being reused)

◆ process_question_numerical_option()

restore_qtype_plugin::process_question_numerical_option ( $data)
inherited

Processes the numerical_option element (question numerical options).

Common for various qtypes. It handles both creation (if the question is being created) and mapping (if the question already existed and is being reused)

◆ process_question_numerical_unit()

restore_qtype_plugin::process_question_numerical_unit ( $data)
inherited

Processes the numerical_unit element (question numerical units).

Common for various qtypes. It handles both creation (if the question is being created) and mapping (if the question already existed and is being reused)

◆ recode_legacy_state_answer()

restore_qtype_plugin::recode_legacy_state_answer ( $state)
inherited

◆ recode_response()

restore_qtype_plugin::recode_response ( $questionid,
$sequencenumber,
array $response )
inherited

Do any re-coding necessary in the student response.

Parameters
int$questionidthe new id of the question
int$sequencenumberof the step within the qusetion attempt.
arraythe response data from the backup.
Return values
arraythe recoded response.

Reimplemented in restore_qtype_calculatedmulti_plugin, restore_qtype_match_plugin, restore_qtype_multianswer_plugin, and restore_qtype_multichoice_plugin.

◆ remove_excluded_question_data()

static restore_qtype_plugin::remove_excluded_question_data ( stdClass $questiondata,
array $excludefields = [] )
staticinherited

Remove excluded fields from the questiondata structure.

This removes fields that will not match or not be present in the question data structure produced by {

See also
self::convert_backup_to_questiondata()} and {
get_question_options()} (such as IDs), so that the remaining data can be used to produce an identity hash for comparing the two.

For plugins, it should be sufficient to override {

See also
self::define_excluded_identity_hash_fields()} with a list of paths specific to the plugin type. Overriding this method is only necessary if the plugin's {
question_type\get_question_options()} method adds additional data to the question that is not included in the backup.
Parameters
stdClass$questiondata
array$excludefieldsPaths to the fields to exclude.
Return values
stdClassThe $questiondata with excluded fields removed.

Reimplemented in restore_qtype_multianswer_plugin.

◆ set_mapping()

restore_plugin::set_mapping ( $itemname,
$oldid,
$newid,
$restorefiles = false,
$filesctxid = null,
$parentid = null )
protectedinherited

To send ids pairs to backup_ids_table and to store them into paths.

This method will send the given itemname and old/new ids to the backup_ids_temp table, and, at the same time, will save the new id into the corresponding restore_path_element for easier access by children. Also will inject the known old context id for the task in case it's going to be used for restoring files later


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