Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
The GIFT import filter was designed as an easy to use method for teachers writing questions as a text file. 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. | |
extract_idnumber_and_tags_from_comment (string $comment) | |
Extract any tags or idnumber declared in the question comment. | |
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) | |
readquestion ($lines) | |
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 | |
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_general_feedback ($question, $indent="\t") | |
Outputs the general feedback for the question, if any. | |
write_idnumber_and_tags (stdClass $questiondata) | |
Prepare any question idnumber or tags for export. | |
write_name ($name) | |
write_questiontext ($text, $format, $defaultformat=FORMAT_MOODLE) | |
writequestion ($question) | |
convert a single question object into text output in the given format. | |
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. | |
answerweightparser (&$answer) | |
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. | |
check_answer_count ($min, $answers, $text) | |
commentparser ($answer, $defaultformat) | |
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. | |
escapedchar_post ($string) | |
escapedchar_pre ($string) | |
exportpostprocess () | |
Do an post-processing that may be required. | |
format_const_to_name ($format) | |
format_name_to_const ($format) | |
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. | |
parse_text_with_format ($text, $defaultformat=FORMAT_MOODLE) | |
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. | |
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(). | |
repchar ($text, $notused=0) | |
split_category_path ($path) | |
Convert a string, as returned by assemble_category_path(), back into an array of category names. | |
split_truefalse_comment ($answer, $defaultformat) | |
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 | |
$importcontext = null | |
The GIFT import filter was designed as an easy to use method for teachers writing questions as a text file.
It supports most question types and the missing word format.
Multiple Choice / Missing Word Who's buried in Grant's tomb?{~Grant ~Jefferson =no one} Grant is {~buried =entombed ~living} in Grant's tomb. True-False: Grant is buried in Grant's tomb.{FALSE} Short-Answer. Who's buried in Grant's tomb?{=no one =nobody} Numerical When was Ulysses S. Grant born?{#1822:5} Matching Match the following countries with their corresponding capitals.{=Canada->Ottawa =Italy->Rome =Japan->Tokyo}
Comment lines start with a double backslash (//). Optional question names are enclosed in double colon(\). Answer feedback is indicated with hash mark (#). Percentage answer weights immediately follow the tilde (for multiple choice) or equal sign (for short answer and numerical), and are enclosed in percent signs (% %). See docs and examples.txt for more.
This filter was written through the collaboration of numerous members of the Moodle community. It was originally based on the missingword format, which included code from Thomas Robb and others. Paul Tsuchido Shew wrote this filter in December 2003.
|
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_gift::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_gift::extract_idnumber_and_tags_from_comment | ( | string | $comment | ) |
Extract any tags or idnumber declared in the question comment.
string | $comment | E.g. "// Line 1.::n//Line 2.\n". |
array | with two elements. string $idnumber (or '') and string[] of tags. |
|
protected |
int | $format | one of the FORMAT_ constants. |
string | the corresponding name. |
|
protected |
int | $format | one of the FORMAT_ constants. |
string | the corresponding name. |
|
protectedinherited |
get the category as a path (e.g., tom/dick/harry)
int | id the id of the most nested catgory |
string | the path |
|
protectedinherited |
Return the localized pluginname string for the question format.
string | the pluginname string for the question format |
|
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 |
|
inherited |
The string mime-type of the files that this plugin reads or writes.
Reimplemented in qformat_blackboard_six_base, and qformat_xml.
|
protectedinherited |
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_xml.
qformat_gift::provide_export | ( | ) |
bool | whether this plugin provides export functionality. |
Reimplemented from qformat_default.
qformat_gift::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.
qformat_gift::readquestion | ( | $lines | ) |
Reimplemented from qformat_default.
|
protectedinherited |
Reimplemented in qformat_blackboard_six, qformat_blackboard_six_pool, qformat_blackboard_six_qti, and qformat_xml.
|
protectedinherited |
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_blackboard_six_pool, qformat_blackboard_six_qti, and qformat_xml.
|
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. |
|
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_gift::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_gift::write_general_feedback | ( | $question, | |
$indent = "\t" ) |
Outputs the general feedback for the question, if any.
This needs to be the last thing before the }.
object | $question | the question data. |
string | $indent | to put before the general feedback. Defaults to a tab. If this is not blank, a newline is added after the line. |
qformat_gift::write_idnumber_and_tags | ( | stdClass | $questiondata | ) |
Prepare any question idnumber or tags for export.
stdClass | $questiondata | the question data we are exporting. |
string | a string that can be written as a line in the GIFT file, e.g. "// [id:myid] [tag:some-tag]::n". Will be '' if none. |
qformat_gift::writequestion | ( | $question | ) |
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 from qformat_default.
|
inherited |