Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
Importer for Moodle XML question format. More...
Public Member Functions | |
can_import_file ($file) | |
Check if the given file is capable of being imported by this plugin. | |
clean_question_name ($name) | |
Ensure that a question name does not contain anything nasty, and will fit in the DB field. | |
clean_question_name ($name) | |
Ensure that a question name does not contain anything nasty, and will fit in the DB field. | |
create_default_question_name ($questiontext, $default) | |
Construct a reasonable default question name, based on the start of the question text. | |
create_default_question_name ($questiontext, $default) | |
Construct a reasonable default question name, based on the start of the question text. | |
export_file_extension () | |
exportpreprocess () | |
Do any pre-processing that may be required. | |
exportprocess ($checkcapabilities=true) | |
Perform the export. | |
format ($format) | |
get_format ($id) | |
Convert internal Moodle text format code into human readable form. | |
get_single ($id) | |
Convert internal single question code into human readable form. | |
getpath ($xml, $path, $default, $istext=false, $error='') | |
return the value of a node, given a path to the node if it doesn't exist return the default value | |
import_answer ($answer, $withanswerfiles=false, $defaultformat='html') | |
Import the common parts of a single answer. | |
import_calculated ($question) | |
Import a calculated question. | |
import_combined_feedback ($qo, $questionxml, $withshownumpartscorrect=false) | |
Import the common overall feedback fields. | |
import_description ($question) | |
Import description type question. | |
import_essay ($question) | |
Import essay type question. | |
import_files ($xml) | |
Import files from a node in the XML. | |
import_files_as_draft ($xml) | |
import_headers ($question) | |
import parts of question common to all types | |
import_hint ($hintxml, $defaultformat) | |
Import a question hint. | |
import_hints ($qo, $questionxml, $withparts=false, $withoptions=false, $defaultformat='html') | |
Import all the question hints. | |
import_match ($question) | |
Import matching type question. | |
import_multianswer ($question) | |
Import cloze type question. | |
import_multichoice ($question) | |
import multiple choice question | |
import_numerical ($question) | |
Import numerical type question. | |
import_question_tags ($qo, $questionxml) | |
Import all the question tags. | |
import_questions ($xml) | |
import_shortanswer ($question) | |
Import short answer type question. | |
import_text ($text) | |
process text string from xml file | |
import_text_with_files ($data, $path, $defaultvalue='', $defaultformat='html') | |
import_truefalse ($question) | |
Import true/false type question. | |
importpostprocess () | |
importpostprocess () | |
Override if any post-processing is required. | |
importpreprocess () | |
importpreprocess () | |
Perform any required pre-processing. | |
importprocess ($filename, $lesson, $pageid) | |
importprocess () | |
Process the file This method should not normally be overidden. | |
mime_type () | |
The string mime-type of the files that this plugin reads or writes. | |
provide_export () | |
provide_import () | |
readdata ($filename) | |
readquestions ($lines) | |
Parse the array of lines into an array of questions this could burn memory - but it won't happen that much so fingers crossed! | |
set_can_access_backupdata ($canaccess) | |
set_display_progress ($displayprogress) | |
Change whether to display progress messages. | |
set_importcontext ($context) | |
setCategory ($category) | |
set the category | |
setCatfromfile ($catfromfile) | |
set catfromfile | |
setCattofile ($cattofile) | |
set cattofile | |
setContextfromfile ($contextfromfile) | |
set contextfromfile | |
setContexts ($contexts) | |
set an array of contexts. | |
setContexttofile ($contexttofile) | |
set contexttofile | |
setCourse ($course) | |
set the course class variable | |
setFilename ($filename) | |
set the filename | |
setMatchgrades ($matchgrades) | |
set matchgrades | |
setQuestions ($questions) | |
Set the specific questions to export. | |
setRealfilename ($realfilename) | |
set the "real" filename (this is what the user typed, regardless of wha happened next) | |
setStoponerror ($stoponerror) | |
set stoponerror | |
trans_format ($name) | |
Translate human readable format name into internal Moodle code number Note the reverse function is called get_format. | |
trans_single ($name) | |
Translate human readable single answer option to internal code number. | |
try_importing_using_qtypes ($data, $question=null, $extra=null, $qtypehint='') | |
Import for questiontype plugins. | |
try_importing_using_qtypes ($data, $question=null, $extra=null, $qtypehint='') | |
Import for questiontype plugins Do not override. | |
validate_file (stored_file $file) | |
Validate the given file. | |
write_answer ($answer, $extra='') | |
write_answers ($answers) | |
write_combined_feedback ($questionoptions, $questionid, $contextid) | |
Output the combined feedback fields. | |
write_files ($files) | |
Generte the XML to represent some files. | |
write_hint ($hint, $contextid) | |
write_hints ($question) | |
Write out the hints. | |
writequestion ($question) | |
Turns question into an xml segment. | |
writetext ($raw, $indent=0, $short=true) | |
Generates <text></text> tags, processing raw text therein. | |
xml_escape ($string) | |
Take a string, and wrap it in a CDATA secion, if that is required to make the output XML valid. | |
Public Attributes | |
$canaccessbackupdata = true | |
$category = null | |
$catfromfile = 0 | |
$cattofile = 0 | |
$contextfromfile = 0 | |
context[] | $contexts |
$contexttofile = 0 | |
$course = null | |
$displayerrors = true | |
bool | $displayprogress = true |
$displayprogress Whether to display progress. | |
$filename = '' | |
$importerrors = 0 | |
$matchgrades = 'error' | |
$qtypeconvert | |
$questionids = array() | |
$questions = array() | |
$realfilename = '' | |
$stoponerror = true | |
$translator = null | |
Protected Member Functions | |
add_blank_combined_feedback ($question) | |
Since the lesson module tries to re-use the question bank import classes in a crazy way, this is necessary to stop things breaking. | |
add_blank_combined_feedback ($question) | |
Add a blank combined feedback to a question object. | |
assemble_category_path ($names) | |
Convert a list of category names, possibly preceeded by one of the context tokens like $course$, into a string representation of the category path. | |
count_questions ($questions) | |
Count all non-category questions in the questions array. | |
count_questions ($questions) | |
Count all non-category questions in the questions array. | |
create_category_path ($catpath, $lastcategoryinfo=null) | |
find and/or create the category described by a delimited list e.g. | |
create_dummy_question_representing_category (string $categoryname, $categoryinfo) | |
Create 'dummy' question for category export. | |
defaultquestion () | |
return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields. | |
defaultquestion () | |
return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields. | |
error ($message, $text='', $questionname='') | |
Handle parsing error. | |
error ($message, $text='', $questionname='') | |
Handle parsing error. | |
exportpostprocess () | |
Do an post-processing that may be required. | |
format_question_text ($question) | |
Convert the question text to plain text, so it can safely be displayed during import to let the user see roughly what is going on. | |
format_question_text ($question) | |
Convert the question text to plain text, so it can safely be displayed during import to let the user see roughly what is going on. | |
get_category_path ($id, $includecontext=true) | |
get the category as a path (e.g., tom/dick/harry) | |
get_name () | |
Return the localized pluginname string for the question format. | |
get_qtype ($qtype) | |
Turn the internal question type name into a human readable form. | |
import_category ($question) | |
This is not a real question type. | |
import_question ($questionxml) | |
presave_process ($content) | |
Enable any processing to be done on the content just prior to the file being saved default is to do nothing. | |
readdata ($filename) | |
Return complete file within an array, one item per line. | |
readquestion ($lines) | |
readquestion ($lines) | |
Given the data known to define a question in this format, this function converts it into a question object suitable for processing and insertion into Moodle. | |
split_category_path ($path) | |
Convert a string, as returned by assemble_category_path(), back into an array of category names. | |
try_exporting_using_qtypes ($name, $question, $extra=null) | |
Provide export functionality for plugin questiontypes Do not override. | |
validate_is_utf8_file (stored_file $file) | |
Check if the given file has the required utf8 encoding. | |
Protected Attributes | |
array | $answerfiles = [] |
Array of files for question answers. | |
array | $feedbackfiles = [] |
Array of files for feedback to question answers. | |
$importcontext = null | |
Importer for Moodle XML question format.
See http://docs.moodle.org/en/Moodle_XML_format for a description of the format.
|
protectedinherited |
Add a blank combined feedback to a question object.
object | question |
object | question |
|
protectedinherited |
Convert a list of category names, possibly preceeded by one of the context tokens like $course$, into a string representation of the category path.
Names are separated by / delimiters. And /s in the name are replaced by //.
To reverse the process and split the paths into names, use split_category_path().
array | $names |
string |
|
inherited |
Check if the given file is capable of being imported by this plugin.
Note that expensive or detailed integrity checks on the file should not be performed by this method. Simple file type or magic-number tests would be suitable.
stored_file | $file | the file to check |
bool | whether this plugin can import the file |
Reimplemented in qformat_blackboard_six_base.
|
inherited |
Ensure that a question name does not contain anything nasty, and will fit in the DB field.
string | $name | the raw question name. |
string | a safe question name. |
|
inherited |
Ensure that a question name does not contain anything nasty, and will fit in the DB field.
string | $name | the raw question name. |
string | a safe question name. |
|
protectedinherited |
Count all non-category questions in the questions array.
array | questions An array of question objects. |
int | The count. |
|
protectedinherited |
Count all non-category questions in the questions array.
array | questions An array of question objects. |
int | The count. |
|
protectedinherited |
find and/or create the category described by a delimited list e.g.
$course$/tom/dick/harry or tom/dick/harry
removes any context string no matter whether $getcontext is set but if $getcontext is set then ignore the context and use selected category context.
string | catpath delimited category path | |
object | $lastcategoryinfo | Contains category information |
mixed | category object or null if fails |
|
inherited |
Construct a reasonable default question name, based on the start of the question text.
string | $questiontext | the question text. |
string | $default | default question name to use if the constructed one comes out blank. |
string | a reasonable question name. |
|
inherited |
Construct a reasonable default question name, based on the start of the question text.
string | $questiontext | the question text. |
string | $default | default question name to use if the constructed one comes out blank. |
string | a reasonable question name. |
|
protectedinherited |
Create 'dummy' question for category export.
string | $categoryname | the name of the category |
object | $categoryinfo | description of the category |
stdClass | 'dummy' question for category |
|
protectedinherited |
return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields.
This should not be overridden.
object | default question |
|
protectedinherited |
return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields.
This should not be overridden.
object | default question |
|
protectedinherited |
Handle parsing error.
string | $message | information about error |
string | $text | imported text that triggered the error |
string | $questionname | imported question name |
qformat_xml::export_file_extension | ( | ) |
string | the file extension (including .) that is normally used for files handled by this plugin. |
Reimplemented from qformat_default.
|
protectedinherited |
Do an post-processing that may be required.
bool | success |
|
inherited |
|
inherited |
Perform the export.
For most types this should not need to be overrided.
bool | $checkcapabilities | Whether to check capabilities when exporting the questions. |
string | The content of the export. |
qformat_xml::format | ( | $format | ) |
int | $format | a FORMAT_... constant. |
string | the attribute to add to an XML tag. |
|
protectedinherited |
get the category as a path (e.g., tom/dick/harry)
int | id the id of the most nested catgory |
string | the path |
qformat_xml::get_format | ( | $id | ) |
Convert internal Moodle text format code into human readable form.
int | id internal code |
string | format text |
|
protectedinherited |
Return the localized pluginname string for the question format.
string | the pluginname string for the question format |
|
protected |
Turn the internal question type name into a human readable form.
(In the past, the code used to use integers internally. Now, it uses strings, so there is less need for this, but to maintain backwards-compatibility we change two of the type names.)
string | $qtype | question type plugin name. |
string\$qtype | string to use in the file. |
qformat_xml::get_single | ( | $id | ) |
Convert internal single question code into human readable form.
int | id single question code |
string | single question string |
qformat_xml::getpath | ( | $xml, | |
$path, | |||
$default, | |||
$istext = false, | |||
$error = '' ) |
return the value of a node, given a path to the node if it doesn't exist return the default value
array | xml data to read |
array | path path to node expressed as array |
mixed | default |
bool | istext process as text |
string | error if set value must exist, return false and issue message if not |
mixed | value |
qformat_xml::import_answer | ( | $answer, | |
$withanswerfiles = false, | |||
$defaultformat = 'html' ) |
Import the common parts of a single answer.
array | answer xml tree for single answer | |
bool | $withanswerfiles | if true, the answers are HTML (or $defaultformat) and so may contain files, otherwise the answers are plain text. |
array | Default text format for the feedback, and the answers if $withanswerfiles is true. |
object | answer object |
qformat_xml::import_calculated | ( | $question | ) |
Import a calculated question.
object | $question | the imported XML data. |
|
protected |
This is not a real question type.
It's a dummy type used to specify the import category. The format is: <question type="category"> <category>tom/dick/harry</category> <info format="moodle_auto_format"><text>Category description</text></info> </question>
qformat_xml::import_combined_feedback | ( | $qo, | |
$questionxml, | |||
$withshownumpartscorrect = false ) |
Import the common overall feedback fields.
object | $question | the part of the XML relating to this question. |
object | $qo | the question data to add the fields to. |
bool | $withshownumpartscorrect | include the shownumcorrect field. |
qformat_xml::import_description | ( | $question | ) |
Import description type question.
array | question question array from xml tree |
object | question object |
qformat_xml::import_essay | ( | $question | ) |
Import essay type question.
array | question question array from xml tree |
object | question object |
qformat_xml::import_files | ( | $xml | ) |
Import files from a node in the XML.
array | $xml | an array of <file> nodes from the the parsed XML. |
array | of things representing files - in the form that save_question expects. |
qformat_xml::import_headers | ( | $question | ) |
import parts of question common to all types
$question | array question question array from xml tree |
object | question object |
qformat_xml::import_hint | ( | $hintxml, | |
$defaultformat ) |
Import a question hint.
array | $hintxml | hint xml fragment. |
string | $defaultformat | the text format to assume for hints that do not specify. |
object | hint for storing in the database. |
qformat_xml::import_hints | ( | $qo, | |
$questionxml, | |||
$withparts = false, | |||
$withoptions = false, | |||
$defaultformat = 'html' ) |
Import all the question hints.
object | $qo | the question data that is being constructed. |
array | $questionxml | The xml representing the question. |
bool | $withparts | whether the extra fields relating to parts should be imported. |
bool | $withoptions | whether the extra options field should be imported. |
string | $defaultformat | the text format to assume for hints that do not specify. |
array | of objects representing the hints in the file. |
qformat_xml::import_match | ( | $question | ) |
Import matching type question.
array | question question array from xml tree |
object | question object |
qformat_xml::import_multianswer | ( | $question | ) |
Import cloze type question.
array | question question array from xml tree |
object | question object |
qformat_xml::import_multichoice | ( | $question | ) |
import multiple choice question
array | question question array from xml tree |
object | question object |
qformat_xml::import_numerical | ( | $question | ) |
Import numerical type question.
array | question question array from xml tree |
object | question object |
|
protected |
array | $questionxml | xml describing the question |
null|stdClass | an object with data to be fed to question type save_question_options |
qformat_xml::import_question_tags | ( | $qo, | |
$questionxml ) |
Import all the question tags.
object | $qo | the question data that is being constructed. |
array | $questionxml | The xml representing the question. |
array | of objects representing the tags in the file. |
qformat_xml::import_questions | ( | $xml | ) |
array | $xml | the xmlized xml |
stdClass[] | question objects to pass to question type save_question_options |
qformat_xml::import_shortanswer | ( | $question | ) |
Import short answer type question.
array | question question array from xml tree |
object | question object |
qformat_xml::import_text | ( | $text | ) |
process text string from xml file
array | $text | bit of xml tree after ['text'] |
string | processed text. |
qformat_xml::import_truefalse | ( | $question | ) |
Import true/false type question.
array | question question array from xml tree |
object | question object |
|
inherited |
Reimplemented in qformat_blackboard_six_base.
|
inherited |
Override if any post-processing is required.
bool | success |
Reimplemented in qformat_blackboard_six_base.
|
inherited |
Perform any required pre-processing.
bool | success |
|
inherited |
Process the file This method should not normally be overidden.
bool | success |
qformat_xml::mime_type | ( | ) |
The string mime-type of the files that this plugin reads or writes.
Reimplemented from qformat_default.
|
protected |
Enable any processing to be done on the content just prior to the file being saved default is to do nothing.
string | output text |
string | processed output text |
Reimplemented from qformat_default.
qformat_xml::provide_export | ( | ) |
bool | whether this plugin provides export functionality. |
Reimplemented from qformat_default.
qformat_xml::provide_import | ( | ) |
Reimplemented from qformat_default.
|
inherited |
Reimplemented in qformat_blackboard_six.
|
protectedinherited |
Return complete file within an array, one item per line.
string | filename name of file |
mixed | contents array or false on failure |
Reimplemented in qformat_blackboard_six.
|
protectedinherited |
Given the data known to define a question in this format, this function converts it into a question object suitable for processing and insertion into Moodle.
If your format does not use blank lines to delimit questions (e.g. an XML format) you must override 'readquestions' too
$lines | mixed data that represents question |
object | question object |
qformat_xml::readquestions | ( | $lines | ) |
Parse the array of lines into an array of questions this could burn memory - but it won't happen that much so fingers crossed!
array | of lines from the input file. | |
stdClass | $context |
array | (of objects) question objects. |
Reimplemented from qformat_default.
|
inherited |
bool | $canaccess | Whether the current use can access the backup data folder. Determines where export files are saved. |
|
inherited |
Change whether to display progress messages.
There is normally no need to use this function as the default for $displayprogress is true. Set to false for unit tests.
bool | $displayprogress |
|
inherited |
set the category
object | category the category object |
|
inherited |
set catfromfile
bool | catfromfile allow categories embedded in import file |
|
inherited |
set cattofile
bool | cattofile exports categories within export file |
|
inherited |
set contextfromfile
bool | $contextfromfile | allow contexts embedded in import file |
|
inherited |
set an array of contexts.
context[] | $contexts |
|
inherited |
set contexttofile
bool | cattofile exports categories within export file |
|
inherited |
set the course class variable
course | object Moodle course variable |
|
inherited |
set the filename
string | filename name of file to import/export |
|
inherited |
set matchgrades
string | matchgrades error or nearest for grades |
|
inherited |
Set the specific questions to export.
Should not include questions with parents (sub questions of cloze question type). Only used for question export.
array | of question objects |
|
inherited |
set the "real" filename (this is what the user typed, regardless of wha happened next)
string | realfilename name of file as typed by user |
|
inherited |
set stoponerror
bool | stoponerror stops database write if any errors reported |
|
protectedinherited |
Convert a string, as returned by assemble_category_path(), back into an array of category names.
Each category name is cleaned by a call to clean_param(, PARAM_TEXT), which matches the cleaning in question/bank/managecategories/category_form.php.
string | $path |
array | of category names. |
qformat_xml::trans_format | ( | $name | ) |
qformat_xml::trans_single | ( | $name | ) |
Translate human readable single answer option to internal code number.
string | name true/false |
int | internal code number |
|
protectedinherited |
Provide export functionality for plugin questiontypes Do not override.
name | questiontype name |
question | object data to export |
extra | mixed any addition format specific data needed |
string | the data to append to export or false if error (or unhandled) |
|
inherited |
Import for questiontype plugins.
mixed | $data | The segment of data containing the question |
object | $question | processed (so far) by standard import code if appropriate |
object | $extra | mixed any additional format specific data that may be passed by the format |
string | $qtypehint | hint about a question type from format |
object | question object suitable for save_options() or false if cannot handle |
|
inherited |
Import for questiontype plugins Do not override.
data | mixed The segment of data containing the question |
question | object processed (so far) by standard import code if appropriate |
extra | mixed any additional format specific data that may be passed by the format |
qtypehint | hint about a question type from format |
object | question object suitable for save_options() or false if cannot handle |
qformat_xml::validate_file | ( | stored_file | $file | ) |
Validate the given file.
For more expensive or detailed integrity checks.
stored_file | $file | the file to check |
string | the error message that occurred while validating the given file |
Reimplemented from qformat_default.
|
protectedinherited |
Check if the given file has the required utf8 encoding.
stored_file | $file | the file to check |
string | the error message if the file encoding is not UTF-8 |
qformat_xml::write_combined_feedback | ( | $questionoptions, | |
$questionid, | |||
$contextid ) |
Output the combined feedback fields.
object | $questionoptions | the question definition data. |
int | $questionid | the question id. |
int | $contextid | the question context id. |
string | XML to output. |
qformat_xml::write_files | ( | $files | ) |
Generte the XML to represent some files.
array | of store array of stored_file objects. |
string\$string | the XML. |
qformat_xml::write_hints | ( | $question | ) |
Write out the hints.
object | $question | the question definition data. |
string | XML to output. |
qformat_xml::writequestion | ( | $question | ) |
Turns question into an xml segment.
object | $question | the question data. |
string | xml segment |
Reimplemented from qformat_default.
qformat_xml::writetext | ( | $raw, | |
$indent = 0, | |||
$short = true ) |
Generates <text></text> tags, processing raw text therein.
string | $raw | the content to output. |
int | $indent | the current indent level. |
bool | $short | stick it on one line. |
string | formatted text. |
qformat_xml::xml_escape | ( | $string | ) |
Take a string, and wrap it in a CDATA secion, if that is required to make the output XML valid.
string | $string | a string |
string | the string, wrapped in CDATA if necessary. |
|
inherited |