Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

format.php  - Default format class for file imports/exports. Doesn't do everything on it's own -- it needs to be extended. Included by import.ph

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 821 lines (33 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes

qformat_default:: (16 methods):
  provide_import()
  set_importcontext()
  error()
  try_importing_using_qtypes()
  importpreprocess()
  importprocess()
  count_questions()
  readdata()
  readquestions()
  readquestion()
  create_default_question_name()
  clean_question_name()
  defaultquestion()
  importpostprocess()
  format_question_text()
  add_blank_combined_feedback()

qformat_based_on_xml:: (3 methods):
  cleaninput()
  text_field()
  getpath()

Defines 3 functions


Class: qformat_default  - X-Ref

provide_import()   X-Ref
No description

set_importcontext($context)   X-Ref
No description

error($message, $text='', $questionname='')   X-Ref
Handle parsing error

param: string $message information about error
param: string $text imported text that triggered the error
param: string $questionname imported question name

try_importing_using_qtypes($data, $question = null, $extra = null,$qtypehint = '')   X-Ref
Import for questiontype plugins

param: mixed $data The segment of data containing the question
param: object $question processed (so far) by standard import code if appropriate
param: object $extra mixed any additional format specific data that may be passed by the format
param: string $qtypehint hint about a question type from format
return: object question object suitable for save_options() or false if cannot handle

importpreprocess()   X-Ref
No description

importprocess($filename, $lesson, $pageid)   X-Ref
No description

count_questions($questions)   X-Ref
Count all non-category questions in the questions array.

param: array questions An array of question objects.
return: int The count.

readdata($filename)   X-Ref
No description

readquestions($lines)   X-Ref
No description

readquestion($lines)   X-Ref
No description

create_default_question_name($questiontext, $default)   X-Ref
Construct a reasonable default question name, based on the start of the question text.

param: string $questiontext the question text.
param: string $default default question name to use if the constructed one comes out blank.
return: string a reasonable question name.

clean_question_name($name)   X-Ref
Ensure that a question name does not contain anything nasty, and will fit in the DB field.

param: string $name the raw question name.
return: string a safe question name.

defaultquestion()   X-Ref
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.

return: object default question

importpostprocess()   X-Ref
No description

format_question_text($question)   X-Ref
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.


add_blank_combined_feedback($question)   X-Ref
Since the lesson module tries to re-use the question bank import classes in
a crazy way, this is necessary to stop things breaking.


Class: qformat_based_on_xml  - X-Ref

Since the lesson module tries to re-use the question bank import classes in
a crazy way, this is necessary to stop things breaking. This should be exactly
the same as the class defined in question/format.php.

cleaninput($str)   X-Ref
A lot of imported files contain unwanted entities.
This method tries to clean up all known problems.

param: string str string to correct
return: string the corrected string

text_field($text)   X-Ref
Return the array moodle is expecting
for an HTML text. No processing is done on $text.
qformat classes that want to process $text
for instance to import external images files
and recode urls in $text must overwrite this method.

param: array $text some HTML text string
return: array with keys text, format and files.

getpath($xml, $path, $default, $istext=false, $error='')   X-Ref
Return the value of a node, given a path to the node
if it doesn't exist return the default value.

param: array xml data to read
param: array path path to node expressed as array
param: mixed default
param: bool istext process as text
param: string error if set value must exist, return false and issue message if not
return: mixed value

Functions that are not part of a class:

lesson_import_question_files($field, $data, $answer, $contextid)   X-Ref
Import files embedded into answer or response

param: string $field nfield name (answer or response)
param: array $data imported data
param: object $answer answer object
param: int $contextid

lesson_save_question_options($question, $lesson, $contextid)   X-Ref
Given some question info and some data about the the answers
this function parses, organises and saves the question

This is only used when IMPORTING questions and is only called
from format.php
Lifted from mod/quiz/lib.php -
1. all reference to oldanswers removed
2. all reference to quiz_multichoice table removed
3. In shortanswer questions usecase is store in the qoption field
4. In numeric questions store the range as two answers
5. truefalse options are ignored
6. For multichoice questions with more than one answer the qoption field is true

param: object $question Contains question data like question, type and answers.
param: object $lesson
param: int $contextid
return: object Returns $result->error or $result->notice.