|
Moodle
2.2.1
http://www.collinsharper.com
|

This is the base class for Moodle question types.
There are detailed comments on each method, explaining what the method is for, and the circumstances under which you might need to override it.
Note: the questiontype API should NOT be considered stable yet. Very few question types have been produced yet, so we do not yet know all the places where the current API is insufficient. I would rather learn from the experiences of the first few question type implementors, and improve the interface to meet their needs, rather the freeze the API prematurely and condem everyone to working round a clunky interface for ever afterwards.
Definition at line 48 of file questiontypebase.php.
| __construct | ( | ) |
Definition at line 55 of file questiontypebase.php.
| actual_number_of_questions | ( | $ | question | ) |
Returns the number of question numbers which are used by the question
This function returns the number of question numbers to be assigned to the question. Most question types will have length one; they will be assigned one number. The 'description' type, however does not use up a number and so has a length of zero. Other question types may wish to handle a bundle of questions and hence return a number greater than one.
| object | $question | The question whose length is to be determined. Question type specific information is included. |
Reimplemented in qtype_description.
Definition at line 830 of file questiontypebase.php.

Whether this question type can perform a frequency analysis of student responses.
If this method returns true, you must implement the get_possible_responses method, and the question_definition class must implement the classify_response method.
Reimplemented in qtype_missingtype, qtype_description, and qtype_multianswer.
Definition at line 139 of file questiontypebase.php.

| create_editing_form | ( | $ | submiturl, |
| $ | question, | ||
| $ | category, | ||
| $ | contexts, | ||
| $ | formeditable | ||
| ) |
Return an instance of the question editing form definition. This looks for a class called edit_{$this->name()}_question_form in the file question/type/{$this->name()}/edit_{$this->name()}_question_form.php and if it exists returns an instance of it.
| string | $submiturl | passed on to the constructor call. |
Definition at line 203 of file questiontypebase.php.

| decode_file | ( | $ | file | ) | [protected] |
Definition at line 1209 of file questiontypebase.php.
| delete_files | ( | $ | questionid, |
| $ | contextid | ||
| ) | [protected] |
Delete all the files belonging to this question.
| int | $questionid | the question being deleted. |
| int | $contextid | the context the question is in. |
Reimplemented in qtype_calculated, qtype_numerical, qtype_calculatedmulti, qtype_multichoice, qtype_match, qtype_truefalse, qtype_essay, and qtype_shortanswer.
Definition at line 1147 of file questiontypebase.php.

| delete_files_in_answers | ( | $ | questionid, |
| $ | contextid, | ||
| $ | answerstoo = false |
||
| ) | [protected] |
Delete all the files belonging to this question's answers.
| int | $questionid | the question being deleted. |
| int | $contextid | the context the question is in. |
| bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
Definition at line 1160 of file questiontypebase.php.


| delete_files_in_combined_feedback | ( | $ | questionid, |
| $ | contextid | ||
| ) | [protected] |
Delete all the files belonging to this question's answers.
| int | $questionid | the question being deleted. |
| int | $contextid | the context the question is in. |
| bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
Definition at line 1181 of file questiontypebase.php.


| delete_question | ( | $ | questionid, |
| $ | contextid | ||
| ) |
Deletes the question-type specific data when a question is deleted.
| int | $question | the question being deleted. |
| int | $contextid | the context this quesiotn belongs to. |
Reimplemented in qtype_calculated, qtype_numerical, qtype_multianswer, qtype_multichoice, qtype_match, qtype_truefalse, and qtype_randomsamatch.
Definition at line 792 of file questiontypebase.php.
| display_question_editing_page | ( | $ | mform, |
| $ | question, | ||
| $ | wizardnow | ||
| ) |
This method should be overriden if you want to include a special heading or some other html on a question editing page besides the question editing form.
| question_edit_form | $mform | a child of question_edit_form |
| object | $question | |
| string | $wizardnow | is '' for first page. |
Reimplemented in qtype_calculated, qtype_random, and qtype_missingtype.
Definition at line 248 of file questiontypebase.php.

| export_to_xml | ( | $ | question, |
| $ | format, | ||
| $ | extra = null |
||
| ) |
Definition at line 976 of file questiontypebase.php.
If your question type has a table that extends the question_answers table, make this method return an array wherer the first element is the table name, and the subsequent entries are the column names (apart from id and answerid).
Definition at line 179 of file questiontypebase.php.
If your question type has a table that extends the question table, and you want the base class to automatically save, backup and restore the extra fields, override this method to return an array wherer the first element is the table name, and the subsequent entries are the column names (apart from id and questionid).
Reimplemented in qtype_shortanswer.
Definition at line 160 of file questiontypebase.php.

Utility method used by qtype_renderer::head_code(). It looks for any of the files script.js or script.php that exist in the plugin folder and ensures they get included.
Definition at line 880 of file questiontypebase.php.
| finished_edit_wizard | ( | $ | form | ) |
Returns true if the editing wizard is finished, false otherwise.
The default implementation returns true, which is suitable for all question- types that only use one editing form. This function is used in question.php to decide whether we can regrade any states of the edited question and redirect to edit.php.
The dataset dependent question-type, which is extended by the calculated question-type, overwrites this method because it uses multiple pages (i.e. a wizard) to set up the question and associated datasets.
| object | $form | The data submitted by the previous page. |
Reimplemented in qtype_calculated, and qtype_calculatedsimple.
Definition at line 910 of file questiontypebase.php.
| generate_test | ( | $ | name, |
| $ | courseid = null |
||
| ) |
Abstract function implemented by each question type. It runs all the code required to set up and save a question of any type for testing purposes. Alternate DB table prefix may be used to facilitate data deletion.
Definition at line 1019 of file questiontypebase.php.

| get_context_by_category_id | ( | $ | category | ) | [protected] |
Get question context by category id
| int | $category |
Definition at line 1043 of file questiontypebase.php.


| get_heading | ( | $ | adding = false | ) |
Method called by display_question_editing_page and by question.php to get heading for breadcrumbs.
Definition at line 288 of file questiontypebase.php.


| get_possible_responses | ( | $ | questiondata | ) |
This method should return all the possible types of response that are recognised for this question.
The question is modelled as comprising one or more subparts. For each subpart, there are one or more classes that that students response might fall into, each of those classes earning a certain score.
For example, in a shortanswer question, there is only one subpart, the text entry field. The response the student gave will be classified according to which of the possible $question->options->answers it matches.
For the matching question type, there will be one subpart for each question stem, and for each stem, each of the possible choices is a class of student's response.
A response is an object with two fields, ->responseclass is a string presentation of that response, and ->fraction, the credit for a response in that class.
Array keys have no specific meaning, but must be unique, and must be the same if this function is called repeatedly.
| object | $question | the question definition data. |
Reimplemented in qtype_calculated, qtype_numerical, qtype_calculatedmulti, qtype_multichoice, qtype_match, qtype_truefalse, and qtype_shortanswer.
Definition at line 871 of file questiontypebase.php.
| get_question_options | ( | $ | question | ) |
Loads the question type specific options for the question.
This function loads any question type specific options for the question from the database into the question object. This information is placed in the $question->options field. A question type is free, however, to decide on a internal structure of the options field.
| object | $question | The question object for the question. This object should be updated to include the question type specific information (it is passed by reference). |
Reimplemented in qtype_random, qtype_truefalse, qtype_numerical, qtype_randomsamatch, qtype_essay, qtype_multianswer, qtype_calculated, qtype_match, and qtype_multichoice.
Definition at line 603 of file questiontypebase.php.
| get_random_guess_score | ( | $ | questiondata | ) |
| object | $question |
Reimplemented in qtype_calculated, qtype_numerical, qtype_randomsamatch, qtype_random, qtype_multianswer, qtype_multichoice, qtype_match, qtype_truefalse, qtype_shortanswer, qtype_missingtype, and qtype_description.
Definition at line 840 of file questiontypebase.php.
| has_html_answers | ( | ) |
Definition at line 148 of file questiontypebase.php.
| import_file | ( | $ | context, |
| $ | component, | ||
| $ | filearea, | ||
| $ | itemid, | ||
| $ | file | ||
| ) |
| import_from_xml | ( | $ | data, |
| $ | question, | ||
| $ | format, | ||
| $ | extra = null |
||
| ) |
IMPORT/EXPORT FUNCTIONS /////////////////.
Definition at line 923 of file questiontypebase.php.
| import_or_save_files | ( | $ | field, |
| $ | context, | ||
| $ | component, | ||
| $ | filearea, | ||
| $ | itemid | ||
| ) | [protected] |
Save the file belonging to one text field.
| array | $field | the data from the form (or from import). This will normally have come from the formslib editor element, so it will be an array with keys 'text', 'format' and 'itemid'. However, when we are importing, it will be an array with keys 'text', 'format' and 'files' |
| object | $context | the context the question is in. |
| string | $component | indentifies the file area question. |
| string | $filearea | indentifies the file area questiontext, generalfeedback, answerfeedback, etc. |
| int | $itemid | identifies the file area. |
Definition at line 1065 of file questiontypebase.php.


| initialise_combined_feedback | ( | question_definition $ | question, |
| $ | questiondata, | ||
| $ | withparts = false |
||
| ) | [protected] |
Initialise the combined feedback fields.
| question_definition | $question | the question_definition we are creating. |
| object | $questiondata | the question data loaded from the database. |
| bool | $withparts | whether to set the shownumcorrect field. |
Definition at line 748 of file questiontypebase.php.

| initialise_question_answers | ( | question_definition $ | question, |
| $ | questiondata, | ||
| $ | forceplaintextanswers = true |
||
| ) | [protected] |
Initialise question_definition::answers field.
| question_definition | $question | the question_definition we are creating. |
| object | $questiondata | the question data loaded from the database. |
| bool | $forceplaintextanswers | most qtypes assume that answers are FORMAT_PLAIN, and dont use the answerformat DB column (it contains the default 0 = FORMAT_MOODLE). Therefore, by default this method ingores answerformat. Pass false here to use answerformat. For example multichoice does this. |
Definition at line 772 of file questiontypebase.php.

| initialise_question_hints | ( | question_definition $ | question, |
| $ | questiondata | ||
| ) | [protected] |
Initialise question_definition::hints field.
| question_definition | $question | the question_definition we are creating. |
| object | $questiondata | the question data loaded from the database. |
Definition at line 723 of file questiontypebase.php.
| initialise_question_instance | ( | question_definition $ | question, |
| $ | questiondata | ||
| ) | [protected] |
Initialise the common question_definition fields.
| question_definition | $question | the question_definition we are creating. |
| object | $questiondata | the question data loaded from the database. |
Reimplemented in qtype_numerical, qtype_calculated, qtype_calculatedmulti, qtype_multichoice, qtype_match, qtype_truefalse, qtype_shortanswer, and qtype_essay.
Definition at line 683 of file questiontypebase.php.
| is_manual_graded | ( | ) |
Reimplemented in qtype_random, and qtype_essay.
Definition at line 108 of file questiontypebase.php.

| is_question_manual_graded | ( | $ | question, |
| $ | otherquestionsinuse | ||
| ) |
| object | $question | a question of this type. |
| string | $otherquestionsinuse | comma-separate list of other question ids in this attempt. |
Reimplemented in qtype_random.
Definition at line 117 of file questiontypebase.php.

Reimplemented in qtype_description.
Definition at line 101 of file questiontypebase.php.
Reimplemented in qtype_random, qtype_randomsamatch, qtype_missingtype, and qtype_description.
Definition at line 124 of file questiontypebase.php.
| local_name | ( | ) |
Definition at line 76 of file questiontypebase.php.


| make_hint | ( | $ | hint | ) | [protected] |
Create a question_hint, or an appropriate subclass for this question, from a row loaded from the database.
| object | $hint | the DB row from the question hints table. |
Reimplemented in qtype_match, and qtype_multichoice.
Definition at line 738 of file questiontypebase.php.

| make_question | ( | $ | questiondata | ) |
Create an appropriate question_definition for the question of this type using data loaded from the database.
| object | $questiondata | the question data loaded from the database. |
Reimplemented in qtype_random, and qtype_missingtype.
Definition at line 659 of file questiontypebase.php.

| make_question_instance | ( | $ | questiondata | ) | [protected] |
Create an appropriate question_definition for the question of this type using data loaded from the database.
| object | $questiondata | the question data loaded from the database. |
Reimplemented in qtype_calculatedmulti, and qtype_multichoice.
Definition at line 672 of file questiontypebase.php.

| menu_name | ( | ) |
The name this question should appear as in the create new question dropdown. Override this method to return false if you don't want your question type to be createable, for example if it is an abstract base type, otherwise, you should not need to override this method.
Reimplemented in qtype_random, and qtype_missingtype.
Definition at line 92 of file questiontypebase.php.

| move_files | ( | $ | questionid, |
| $ | oldcontextid, | ||
| $ | newcontextid | ||
| ) |
Move all the files belonging to this question from one context to another.
| int | $questionid | the question being moved. |
| int | $oldcontextid | the context it is moving from. |
| int | $newcontextid | the context it is moving to. |
Reimplemented in qtype_calculated, qtype_numerical, qtype_calculatedmulti, qtype_multichoice, qtype_match, qtype_truefalse, qtype_essay, and qtype_shortanswer.
Definition at line 1086 of file questiontypebase.php.

| move_files_in_answers | ( | $ | questionid, |
| $ | oldcontextid, | ||
| $ | newcontextid, | ||
| $ | answerstoo = false |
||
| ) | [protected] |
Move all the files belonging to this question's answers when the question is moved from one context to another.
| int | $questionid | the question being moved. |
| int | $oldcontextid | the context it is moving from. |
| int | $newcontextid | the context it is moving to. |
| bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
Definition at line 1103 of file questiontypebase.php.


| move_files_in_combined_feedback | ( | $ | questionid, |
| $ | oldcontextid, | ||
| $ | newcontextid | ||
| ) | [protected] |
Move all the files belonging to this question's answers when the question is moved from one context to another.
| int | $questionid | the question being moved. |
| int | $oldcontextid | the context it is moving from. |
| int | $newcontextid | the context it is moving to. |
| bool | $answerstoo | whether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false. |
Definition at line 1129 of file questiontypebase.php.


| name | ( | ) |
Definition at line 61 of file questiontypebase.php.

| plugin_baseurl | ( | ) |
Definition at line 235 of file questiontypebase.php.

| plugin_dir | ( | ) |
Definition at line 227 of file questiontypebase.php.

| plugin_name | ( | ) |
Definition at line 68 of file questiontypebase.php.

If you use extra_question_fields, overload this function to return question id field name in case you table use another name for this column
Reimplemented in qtype_shortanswer.
Definition at line 168 of file questiontypebase.php.

If the quetsion type uses files in responses, then this method should return an array of all the response variables that might have corresponding files. For example, the essay qtype returns array('attachments', 'answers').
Reimplemented in qtype_essay.
Definition at line 190 of file questiontypebase.php.
| save_combined_feedback_helper | ( | $ | options, |
| $ | formdata, | ||
| $ | context, | ||
| $ | withparts = false |
||
| ) | [protected] |
Can be used to save_question_options() to transfer the combined feedback fields from $formdata to $options.
| object | $options | the $question->options object being built. |
| object | $formdata | the data from the form. |
| object | $context | the context the quetsion is being saved into. |
| bool | $withparts | whether $options->shownumcorrect should be set. |
Definition at line 569 of file questiontypebase.php.

| save_hints | ( | $ | formdata, |
| $ | withparts = false |
||
| ) |
Definition at line 492 of file questiontypebase.php.


| save_question | ( | $ | question, |
| $ | form | ||
| ) |
Saves (creates or updates) a question.
Given some question info and some data about the answers this function parses, organises and saves the question It is used by question.php when saving new data from a form, and also by import.php when importing questions This function in turn calls save_question_options to save question-type specific data.
Whether we are saving a new question or updating an existing one can be determined by testing !empty($question->id). If it is not empty, we are updating.
The question will be saved in category $form->category.
| object | $question | the question object which should be updated. For a new question will be mostly empty. |
| object | $form | the object containing the information to save, as if from the question editing form. |
| object | $course | not really used any more. |
Question already exists, update.
Reimplemented in qtype_calculated, qtype_multianswer, qtype_random, and qtype_description.
Definition at line 341 of file questiontypebase.php.

| save_question_options | ( | $ | question | ) |
Saves question-type specific options
This is called by save_question() to save the question-type specific data
| object | $question | This holds the information from the editing form, it is not a standard question object. |
Reimplemented in qtype_random, qtype_numerical, qtype_calculated, qtype_multianswer, qtype_randomsamatch, qtype_shortanswer, qtype_essay, qtype_match, qtype_multichoice, qtype_calculatedsimple, qtype_calculatedmulti, and qtype_truefalse.
Definition at line 454 of file questiontypebase.php.


| set_default_options | ( | $ | questiondata | ) |
Set any missing settings for this question to the default values. This is called before displaying the question editing form.
| object | $questiondata | the question data, loaded from the databsae, or more likely a newly created question object that is only partially initialised. |
Definition at line 311 of file questiontypebase.php.
$fileoptions [protected] |
array( 'subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0, )
Definition at line 49 of file questiontypebase.php.