Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
Base class for question import and export formats. More...
Public Member Functions | |
can_import_file ($file) | |
Check if the given file is capable of being imported by this plugin. More... | |
clean_question_name ($name) | |
Ensure that a question name does not contain anything nasty, and will fit in the DB field. More... | |
clean_question_name ($name) | |
Ensure that a question name does not contain anything nasty, and will fit in the DB field. More... | |
create_default_question_name ($questiontext, $default) | |
Construct a reasonable default question name, based on the start of the question text. More... | |
create_default_question_name ($questiontext, $default) | |
Construct a reasonable default question name, based on the start of the question text. More... | |
export_file_extension () | |
exportpreprocess () | |
Do any pre-processing that may be required. More... | |
exportprocess ($checkcapabilities=true) | |
Perform the export. More... | |
importpostprocess () | |
importpostprocess () | |
Override if any post-processing is required. More... | |
importpreprocess () | |
importpreprocess () | |
Perform any required pre-processing. More... | |
importprocess ($filename, $lesson, $pageid) | |
importprocess () | |
Process the file This method should not normally be overidden. More... | |
mime_type () | |
The string mime-type of the files that this plugin reads or writes. More... | |
provide_export () | |
provide_import () | |
provide_import () | |
readdata ($filename) | |
set_can_access_backupdata ($canaccess) | |
set_display_progress ($displayprogress) | |
Change whether to display progress messages. More... | |
set_importcontext ($context) | |
setCategory ($category) | |
set the category More... | |
setCatfromfile ($catfromfile) | |
set catfromfile More... | |
setCattofile ($cattofile) | |
set cattofile More... | |
setContextfromfile ($contextfromfile) | |
set contextfromfile More... | |
setContexts ($contexts) | |
set an array of contexts. More... | |
setContexttofile ($contexttofile) | |
set contexttofile More... | |
setCourse ($course) | |
set the course class variable More... | |
setFilename ($filename) | |
set the filename More... | |
setMatchgrades ($matchgrades) | |
set matchgrades More... | |
setQuestions ($questions) | |
Set the specific questions to export. More... | |
setRealfilename ($realfilename) | |
set the "real" filename (this is what the user typed, regardless of wha happened next) More... | |
setStoponerror ($stoponerror) | |
set stoponerror More... | |
try_importing_using_qtypes ($data, $question=null, $extra=null, $qtypehint='') | |
Import for questiontype plugins. More... | |
try_importing_using_qtypes ($data, $question=null, $extra=null, $qtypehint='') | |
Import for questiontype plugins Do not override. More... | |
Public Attributes | |
$canaccessbackupdata = true | |
$category = null | |
$catfromfile = 0 | |
$cattofile = 0 | |
$contextfromfile = 0 | |
$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. More... | |
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. More... | |
count_questions ($questions) | |
Count all non-category questions in the questions array. More... | |
count_questions ($questions) | |
Count all non-category questions in the questions array. More... | |
create_category_path ($catpath, $lastcategoryinfo=null) | |
find and/or create the category described by a delimited list e.g. More... | |
create_dummy_question_representing_category (string $categoryname, $categoryinfo) | |
Create 'dummy' question for category export. More... | |
defaultquestion () | |
return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields. More... | |
defaultquestion () | |
return an "empty" question Somewhere to specify question parameters that are not handled by import but are required db fields. More... | |
error ($message, $text='', $questionname='') | |
Handle parsing error. More... | |
error ($message, $text='', $questionname='') | |
Handle parsing error. | |
exportpostprocess () | |
Do an post-processing that may be required. More... | |
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) More... | |
presave_process ($content) | |
Enable any processing to be done on the content just prior to the file being saved default is to do nothing. More... | |
readdata ($filename) | |
Return complete file within an array, one item per line. More... | |
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. More... | |
readquestions ($lines) | |
readquestions ($lines) | |
Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion(). More... | |
split_category_path ($path) | |
Convert a string, as returned by assemble_category_path(), back into an array of category names. More... | |
try_exporting_using_qtypes ($name, $question, $extra=null) | |
Provide export functionality for plugin questiontypes Do not override. More... | |
writequestion ($question) | |
convert a single question object into text output in the given format. More... | |
Protected Attributes | |
$importcontext = null | |
Base class for question import and export formats.
|
protected |
Add a blank combined feedback to a question object.
object | question |
object | question |
|
protected |
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 |
qformat_default::can_import_file | ( | $file | ) |
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, and qformat_webct.
qformat_default::clean_question_name | ( | $name | ) |
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. |
qformat_default::clean_question_name | ( | $name | ) |
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. |
|
protected |
Count all non-category questions in the questions array.
array | questions An array of question objects. |
int | The count. |
|
protected |
Count all non-category questions in the questions array.
array | questions An array of question objects. |
int | The count. |
|
protected |
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 |
qformat_default::create_default_question_name | ( | $questiontext, | |
$default | |||
) |
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. |
qformat_default::create_default_question_name | ( | $questiontext, | |
$default | |||
) |
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. |
|
protected |
Create 'dummy' question for category export.
string | $categoryname | the name of the category |
object | $categoryinfo | description of the category |
stdClass | 'dummy' question for category |
|
protected |
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 |
|
protected |
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 |
|
protected |
Handle parsing error.
string | $message | information about error |
string | $text | imported text that triggered the error |
string | $questionname | imported question name |
qformat_default::export_file_extension | ( | ) |
string | the file extension (including .) that is normally used for files handled by this plugin. |
Reimplemented in qformat_gift, qformat_xhtml, and qformat_xml.
|
protected |
Do an post-processing that may be required.
bool | success |
qformat_default::exportpreprocess | ( | ) |
qformat_default::exportprocess | ( | $checkcapabilities = true | ) |
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. |
|
protected |
get the category as a path (e.g., tom/dick/harry)
int | id the id of the most nested catgory |
string | the path |
qformat_default::importpostprocess | ( | ) |
Reimplemented in qformat_blackboard_six_base, and qformat_webct.
qformat_default::importpostprocess | ( | ) |
Override if any post-processing is required.
bool | success |
Reimplemented in qformat_blackboard_six_base, and qformat_webct.
qformat_default::importpreprocess | ( | ) |
Perform any required pre-processing.
bool | success |
qformat_default::importprocess | ( | ) |
Process the file This method should not normally be overidden.
bool | success |
qformat_default::mime_type | ( | ) |
The string mime-type of the files that this plugin reads or writes.
Reimplemented in qformat_blackboard_six_base, qformat_examview, qformat_webct, and qformat_xml.
|
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 in qformat_xhtml, and qformat_xml.
qformat_default::provide_export | ( | ) |
bool | whether this plugin provides export functionality. |
Reimplemented in qformat_aiken, qformat_gift, qformat_xhtml, and qformat_xml.
qformat_default::provide_import | ( | ) |
Reimplemented in qformat_blackboard_six_base, and qformat_webct.
qformat_default::provide_import | ( | ) |
bool | whether this plugin provides import functionality. |
Reimplemented in qformat_blackboard_six_base, and qformat_webct.
qformat_default::readdata | ( | $filename | ) |
Reimplemented in qformat_blackboard_six, and qformat_webct.
|
protected |
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, and qformat_webct.
|
protected |
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 |
|
protected |
Reimplemented in qformat_blackboard_six, qformat_xml, qformat_blackboard_six_pool, and qformat_blackboard_six_qti.
|
protected |
Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion().
Questions are defined as anything between blank lines.
NOTE this method used to take $context as a second argument. However, at the point where this method was called, it was impossible to know what context the quetsions were going to be saved into, so the value could be wrong. Also, none of the standard question formats were using this argument, so it was removed. See MDL-32220.
If your format does not use blank lines as a delimiter then you will need to override this method. Even then try to use readquestion for each question
array | lines array of lines from readdata |
array | array of question objects |
Reimplemented in qformat_blackboard_six, qformat_xml, qformat_blackboard_six_pool, and qformat_blackboard_six_qti.
qformat_default::set_can_access_backupdata | ( | $canaccess | ) |
bool | $canaccess | Whether the current use can access the backup data folder. Determines where export files are saved. |
qformat_default::set_display_progress | ( | $displayprogress | ) |
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 |
qformat_default::setCategory | ( | $category | ) |
set the category
object | category the category object |
qformat_default::setCatfromfile | ( | $catfromfile | ) |
set catfromfile
bool | catfromfile allow categories embedded in import file |
qformat_default::setCattofile | ( | $cattofile | ) |
set cattofile
bool | cattofile exports categories within export file |
qformat_default::setContextfromfile | ( | $contextfromfile | ) |
set contextfromfile
bool | $contextfromfile | allow contexts embedded in import file |
qformat_default::setContexts | ( | $contexts | ) |
set an array of contexts.
array | $contexts | Moodle course variable |
qformat_default::setContexttofile | ( | $contexttofile | ) |
set contexttofile
bool | cattofile exports categories within export file |
qformat_default::setCourse | ( | $course | ) |
set the course class variable
course | object Moodle course variable |
qformat_default::setFilename | ( | $filename | ) |
set the filename
string | filename name of file to import/export |
qformat_default::setMatchgrades | ( | $matchgrades | ) |
set matchgrades
string | matchgrades error or nearest for grades |
qformat_default::setQuestions | ( | $questions | ) |
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 |
qformat_default::setRealfilename | ( | $realfilename | ) |
set the "real" filename (this is what the user typed, regardless of wha happened next)
string | realfilename name of file as typed by user |
qformat_default::setStoponerror | ( | $stoponerror | ) |
set stoponerror
bool | stoponerror stops database write if any errors reported |
|
protected |
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/category_form.php.
string | $path |
array | of category names. |
|
protected |
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) |
qformat_default::try_importing_using_qtypes | ( | $data, | |
$question = null , |
|||
$extra = null , |
|||
$qtypehint = '' |
|||
) |
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 |
qformat_default::try_importing_using_qtypes | ( | $data, | |
$question = null , |
|||
$extra = null , |
|||
$qtypehint = '' |
|||
) |
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 |
|
protected |
convert a single question object into text output in the given format.
This must be overriden
object | question question object |
mixed | question export text or null if not implemented |
Reimplemented in qformat_aiken, qformat_gift, qformat_xhtml, and qformat_xml.
qformat_default::$qtypeconvert |