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

Handles the conversion of the question bank included in the moodle.xml file. More...

Inheritance diagram for moodle1_question_bank_handler:
moodle1_xml_handler moodle1_handler loggable

Public Member Functions

 get_converter ()
 
 get_current_category_context ()
 Returns the information about the question category context being currently parsed.
 
 get_file_manager ()
 Return the file manager instance used.
 
 get_paths ()
 Registers path that are not qtype-specific.
 
 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.
 
 on_question_categories_end ()
 Stops writing questions.xml.
 
 on_question_categories_start ()
 Starts writing questions.xml and prepares the file manager instance.
 
 on_question_category_end ()
 Closes the question_category and annotates the category id so that it can be dumped into course/inforef.xml.
 
 on_question_category_start ()
 Initializes the current category cache.
 
 on_questions_end ()
 Closes the questions wrapper.
 
 process_question (array $data, array $raw)
 Writes the common <question> data and re-dispateches the whole grouped <QUESTION> data to the qtype for appending its qtype specific data processing.
 
 process_question_category ($data, $raw)
 Populates the current question category data.
 
 process_question_category_context ($data)
 Inject the context related information into the current category.
 

Protected Member Functions

 close_xml_writer ()
 Close the XML writer.
 
 get_qtype_handler ($qtype)
 Provides access to the qtype handlers.
 
 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.
 
 open_xml_writer ($filename)
 Opens the XML writer - after calling, one is free to use $xmlwriter.
 
 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
 
array $currentcategory = null
 the current question category being parsed
 
array $currentcategoryraw = null
 of the raw data for the current category
 
moodle1_file_manager $fileman = null
 instance used to convert question images
 
null string $xmlfilename
 the name of file we are writing to
 
null xml_writer $xmlwriter
 

Detailed Description

Handles the conversion of the question bank included in the moodle.xml file.

Member Function Documentation

◆ close_xml_writer()

moodle1_xml_handler::close_xml_writer ( )
protectedinherited

Close the XML writer.

At the moment, the caller must close all tags before calling

Return values
void

Reimplemented in moodle1_qtype_handler.

◆ get_converter()

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

◆ get_current_category_context()

moodle1_question_bank_handler::get_current_category_context ( )

Returns the information about the question category context being currently parsed.

Return values
arraywith keys contextid, contextlevel and contextinstanceid

◆ get_file_manager()

moodle1_question_bank_handler::get_file_manager ( )

Return the file manager instance used.

Return values
moodle1_file_manager

◆ get_qtype_handler()

moodle1_question_bank_handler::get_qtype_handler ( $qtype)
protected

Provides access to the qtype handlers.

Returns either list of all qtype handler instances (if passed '*') or a particular handler for the given qtype or false if the qtype is not supported.

Exceptions
moodle1_convert_exception
Parameters
string$qtypethe name of the question type or '*' for returning all
Return values
array|moodle1_qtype_handler|bool

◆ 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

◆ open_xml_writer()

moodle1_xml_handler::open_xml_writer ( $filename)
protectedinherited

Opens the XML writer - after calling, one is free to use $xmlwriter.

Parameters
string$filenameXML file name to write into
Return values
void

Reimplemented in moodle1_qtype_handler.

◆ process_question()

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

Writes the common <question> data and re-dispateches the whole grouped <QUESTION> data to the qtype for appending its qtype specific data processing.

Parameters
array$data
array$raw
Return values
array

◆ process_question_category()

moodle1_question_bank_handler::process_question_category ( $data,
$raw )

Populates the current question category data.

Bacuse of the known subpath-in-the-middle problem (CONTEXT in this case), this is actually called twice for both halves of the data. We merge them here into the currentcategory array.

◆ 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: