Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

GIFT format question importer/exporter.

Copyright: 2003 Paul Tsuchido Shew
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 886 lines (36 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class


Class: qformat_gift  - X-Ref

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.

provide_import()   X-Ref
No description

provide_export()   X-Ref
No description

export_file_extension()   X-Ref
No description

validate_file(stored_file $file)   X-Ref
Validate the given file.

For more expensive or detailed integrity checks.

param: stored_file $file the file to check
return: string the error message that occurred while validating the given file

answerweightparser(&$answer)   X-Ref
No description

commentparser($answer, $defaultformat)   X-Ref
No description

split_truefalse_comment($answer, $defaultformat)   X-Ref
No description

escapedchar_pre($string)   X-Ref
No description

escapedchar_post($string)   X-Ref
No description

check_answer_count($min, $answers, $text)   X-Ref
No description

parse_text_with_format($text, $defaultformat = FORMAT_MOODLE)   X-Ref
No description

readquestion($lines)   X-Ref
No description

repchar($text, $notused = 0)   X-Ref
No description

format_const_to_name($format)   X-Ref

param: int $format one of the FORMAT_ constants.
return: string the corresponding name.

format_name_to_const($format)   X-Ref

param: int $format one of the FORMAT_ constants.
return: string the corresponding name.

extract_idnumber_and_tags_from_comment(string $comment)   X-Ref
Extract any tags or idnumber declared in the question comment.

param: string $comment E.g. "// Line 1.\n//Line 2.\n".
return: array with two elements. string $idnumber (or '') and string[] of tags.

write_name($name)   X-Ref
No description

write_questiontext($text, $format, $defaultformat = FORMAT_MOODLE)   X-Ref
No description

write_general_feedback($question, $indent = "\t")   X-Ref
Outputs the general feedback for the question, if any. This needs to be the
last thing before the }.

param: object $question the question data.
param: string $indent to put before the general feedback. Defaults to a tab.

writequestion($question)   X-Ref
No description

write_idnumber_and_tags(stdClass $questiondata)   X-Ref
Prepare any question idnumber or tags for export.

param: stdClass $questiondata the question data we are exporting.
return: string a string that can be written as a line in the GIFT file,