Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
moodle1_qtype_handler Class Reference

Base class for all question type handlers. More...

Inheritance diagram for moodle1_qtype_handler:
moodle1_plugin_handler moodle1_xml_handler moodle1_handler loggable moodle1_qtype_calculated_handler moodle1_qtype_essay_handler moodle1_qtype_match_handler moodle1_qtype_multianswer_handler moodle1_qtype_multichoice_handler moodle1_qtype_numerical_handler moodle1_qtype_ordering_handler moodle1_qtype_randomsamatch_handler moodle1_qtype_shortanswer_handler moodle1_qtype_truefalse_handler

Public Member Functions

 __construct (moodle1_question_bank_handler $qbankhandler, $qtype)
 implementation details follow //////////////////////////////////////////
 
 get_component_name ()
 Returns the normalized name of the plugin, eg mod_workshop.
 
 get_converter ()
 
 get_paths ()
 
 get_question_subpaths ()
 Returns the list of paths within one <QUESTION> that this qtype needs to have included in the grouped question structure.
 
 log ($message, $level, $a=null, $depth=null, $display=false)
 This function will be responsible for handling the params, and to call to the corresponding logger->process() once all modifications in params have been performed.
 
 process_question (array $data, array $raw)
 Gives the qtype handler a chance to write converted data into questions.xml.
 
 use_xml_writer (xml_writer $xmlwriter)
 Provides a xml_writer instance to this qtype converter.
 

Protected Member Functions

 close_xml_writer ()
 Question type handlers cannot close the xml_writer.
 
 get_default_numerical_options ($oldquestiontextformat, $units)
 Returns default numerical_option structure.
 
 has_xml_writer ()
 Checks if the XML writer has been opened by self::open_xml_writer().
 
 make_sure_xml_exists ($filename, $rootelement=false, $content=array())
 Makes sure that a new XML file exists, or creates it itself.
 
 migrate_files ($text, $component, $filearea, $itemid)
 Migrate files belonging to one qtype plugin text field.
 
 open_xml_writer ($filename)
 Question type handlers cannot open the xml_writer.
 
 write_answers (array $answers, $qtype)
 Converts the answers and writes them into the questions.xml.
 
 write_dataset_definitions (array $datasetdefinitions)
 Writes the dataset_definitions structure.
 
 write_numerical_options (array $numericaloption)
 Writes the numerical_options structure.
 
 write_numerical_units (array $numericalunits)
 Writes the grouped numerical_units structure.
 
 write_xml ($element, array $data, array $attribs=array(), $parent='/')
 Writes the given XML tree data into the currently opened file.
 

Protected Attributes

moodle1_converter $converter
 
string $pluginname
 
string $plugintype
 
moodle1_question_bank_handler $qbankhandler
 
null string $xmlfilename
 the name of file we are writing to
 
null xml_writer $xmlwriter
 

Detailed Description

Base class for all question type handlers.

Member Function Documentation

◆ close_xml_writer()

moodle1_qtype_handler::close_xml_writer ( )
finalprotected

Question type handlers cannot close the xml_writer.

Reimplemented from moodle1_xml_handler.

◆ get_component_name()

moodle1_plugin_handler::get_component_name ( )
inherited

Returns the normalized name of the plugin, eg mod_workshop.

Return values
string

◆ get_converter()

moodle1_handler::get_converter ( )
inherited
Return values
moodle1_converterthe converter that required this handler

◆ get_default_numerical_options()

moodle1_qtype_handler::get_default_numerical_options ( $oldquestiontextformat,
$units )
protected

Returns default numerical_option structure.

This structure is not present in moodle.xml, we create a new artificial one here.

See also
write_numerical_options()
Parameters
int$oldquestiontextformat
Return values
array

◆ get_paths()

moodle1_qtype_handler::get_paths ( )
final
See also
self\get_question_subpaths()

◆ get_question_subpaths()

moodle1_qtype_handler::get_question_subpaths ( )

◆ has_xml_writer()

moodle1_xml_handler::has_xml_writer ( )
protectedinherited

Checks if the XML writer has been opened by self::open_xml_writer().

Return values
bool

◆ log()

moodle1_handler::log ( $message,
$level,
$a = null,
$depth = null,
$display = false )
inherited

This function will be responsible for handling the params, and to call to the corresponding logger->process() once all modifications in params have been performed.

Implements loggable.

◆ make_sure_xml_exists()

moodle1_xml_handler::make_sure_xml_exists ( $filename,
$rootelement = false,
$content = array() )
protectedinherited

Makes sure that a new XML file exists, or creates it itself.

This is here so we can check that all XML files that the restore process relies on have been created by an executed handler. If the file is not found, this method can create it using the given $rootelement as an empty root container in the file.

Parameters
string$filenamerelative file name like 'course/course.xml'
string | bool$rootelementroot element to use, false to not create the file
array$contentcontent of the root element
Return values
booltrue is the file existed, false if it did not

◆ migrate_files()

moodle1_qtype_handler::migrate_files ( $text,
$component,
$filearea,
$itemid )
protected

Migrate files belonging to one qtype plugin text field.

Parameters
array$textthe html fragment containing references to files
string$componentthe component for restored files
string$fileareathe file area for restored files
int$itemidthe itemid for restored files
Return values
stringthe text for this field, after files references have been processed

◆ open_xml_writer()

moodle1_qtype_handler::open_xml_writer ( $filename)
finalprotected

Question type handlers cannot open the xml_writer.

Reimplemented from moodle1_xml_handler.

◆ process_question()

moodle1_qtype_handler::process_question ( array $data,
array $raw )

◆ use_xml_writer()

moodle1_qtype_handler::use_xml_writer ( xml_writer $xmlwriter)

Provides a xml_writer instance to this qtype converter.

Parameters
xml_writer$xmlwriter

◆ write_answers()

moodle1_qtype_handler::write_answers ( array $answers,
$qtype )
protected

Converts the answers and writes them into the questions.xml.

The structure "answers" is used by several qtypes. It contains data from {question_answers} table.

Parameters
array$answersas parsed by the grouped parser in moodle.xml
string$qtypecontaining the answers

◆ write_dataset_definitions()

moodle1_qtype_handler::write_dataset_definitions ( array $datasetdefinitions)
protected

Writes the dataset_definitions structure.

Parameters
array$datasetdefinitionsarray of dataset_definition structures

◆ write_numerical_options()

moodle1_qtype_handler::write_numerical_options ( array $numericaloption)
protected

Writes the numerical_options structure.

See also
get_default_numerical_options()
Parameters
array$numericaloption

◆ write_numerical_units()

moodle1_qtype_handler::write_numerical_units ( array $numericalunits)
protected

Writes the grouped numerical_units structure.

Parameters
array$numericalunits

◆ write_xml()

moodle1_xml_handler::write_xml ( $element,
array $data,
array $attribs = array(),
$parent = '/' )
protectedinherited

Writes the given XML tree data into the currently opened file.

Parameters
string$elementthe name of the root element of the tree
array$datathe associative array of data to write
array$attribslist of additional fields written as attributes instead of nested elements
string$parentused internally during the recursion, do not set yourself

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