Moodle  2.2.1
http://www.collinsharper.com
question_type Class Reference
Inheritance diagram for question_type:

Public Member Functions

 __construct ()
 name ()
 plugin_name ()
 local_name ()
 menu_name ()
 is_real_question_type ()
 is_manual_graded ()
 is_question_manual_graded ($question, $otherquestionsinuse)
 is_usable_by_random ()
 can_analyse_responses ()
 has_html_answers ()
 extra_question_fields ()
 questionid_column_name ()
 extra_answer_fields ()
 response_file_areas ()
 create_editing_form ($submiturl, $question, $category, $contexts, $formeditable)
 plugin_dir ()
 plugin_baseurl ()
 display_question_editing_page ($mform, $question, $wizardnow)
 get_heading ($adding=false)
 set_default_options ($questiondata)
 save_question ($question, $form)
 save_question_options ($question)
 save_hints ($formdata, $withparts=false)
 get_question_options ($question)
 make_question ($questiondata)
 delete_question ($questionid, $contextid)
 actual_number_of_questions ($question)
 get_random_guess_score ($questiondata)
 get_possible_responses ($questiondata)
 find_standard_scripts ()
 finished_edit_wizard ($form)
 import_from_xml ($data, $question, $format, $extra=null)
 IMPORT/EXPORT FUNCTIONS /////////////////.
 export_to_xml ($question, $format, $extra=null)
 generate_test ($name, $courseid=null)
 move_files ($questionid, $oldcontextid, $newcontextid)
 import_file ($context, $component, $filearea, $itemid, $file)

Protected Member Functions

 save_combined_feedback_helper ($options, $formdata, $context, $withparts=false)
 make_question_instance ($questiondata)
 initialise_question_instance (question_definition $question, $questiondata)
 initialise_question_hints (question_definition $question, $questiondata)
 make_hint ($hint)
 initialise_combined_feedback (question_definition $question, $questiondata, $withparts=false)
 initialise_question_answers (question_definition $question, $questiondata, $forceplaintextanswers=true)
 get_context_by_category_id ($category)
 import_or_save_files ($field, $context, $component, $filearea, $itemid)
 move_files_in_answers ($questionid, $oldcontextid, $newcontextid, $answerstoo=false)
 move_files_in_combined_feedback ($questionid, $oldcontextid, $newcontextid)
 delete_files ($questionid, $contextid)
 delete_files_in_answers ($questionid, $contextid, $answerstoo=false)
 delete_files_in_combined_feedback ($questionid, $contextid)
 decode_file ($file)

Protected Attributes

 $fileoptions

Detailed Description

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.


Constructor & Destructor Documentation

Definition at line 55 of file questiontypebase.php.


Member Function Documentation

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.

Returns:
int The number of question numbers which should be assigned to the question.
Parameters:
object$questionThe 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.

Here is the caller graph for this function:

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.

Returns:
bool whether this report can analyse all the student reponses for things like the quiz statistics report.

Reimplemented in qtype_missingtype, qtype_description, and qtype_multianswer.

Definition at line 139 of file questiontypebase.php.

Here is the call graph for this function:

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.

Parameters:
string$submiturlpassed on to the constructor call.
Returns:
object an instance of the form definition, or null if one could not be found.

Definition at line 203 of file questiontypebase.php.

Here is the call graph for this function:

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.

Parameters:
int$questionidthe question being deleted.
int$contextidthe 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.

Here is the call graph for this function:

delete_files_in_answers ( questionid,
contextid,
answerstoo = false 
) [protected]

Delete all the files belonging to this question's answers.

Parameters:
int$questionidthe question being deleted.
int$contextidthe context the question is in.
bool$answerstoowhether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false.

Definition at line 1160 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

delete_files_in_combined_feedback ( questionid,
contextid 
) [protected]

Delete all the files belonging to this question's answers.

Parameters:
int$questionidthe question being deleted.
int$contextidthe context the question is in.
bool$answerstoowhether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false.

Definition at line 1181 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

delete_question ( questionid,
contextid 
)

Deletes the question-type specific data when a question is deleted.

Parameters:
int$questionthe question being deleted.
int$contextidthe 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.

Parameters:
question_edit_form$mforma child of question_edit_form
object$question
string$wizardnowis '' for first page.

Reimplemented in qtype_calculated, qtype_random, and qtype_missingtype.

Definition at line 248 of file questiontypebase.php.

Here is the call graph for this function:

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).

Returns:
mixed array as above, or null to tell the base class to do nothing.

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).

Returns:
mixed array as above, or null to tell the base class to do nothing.

Reimplemented in qtype_shortanswer.

Definition at line 160 of file questiontypebase.php.

Here is the caller graph for this function:

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.

Parameters:
object$formThe data submitted by the previous page.
Returns:
bool Whether the wizard's last page was submitted or not.

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.

Here is the call graph for this function:

get_context_by_category_id ( category) [protected]

Get question context by category id

Parameters:
int$category
Returns:
object $context

Definition at line 1043 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_heading ( adding = false)

Method called by display_question_editing_page and by question.php to get heading for breadcrumbs.

Returns:
string the heading

Definition at line 288 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
object$questionthe question definition data.
Returns:
array keys are subquestionid, values are arrays of possible responses to that subquestion.

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.

Returns:
bool Indicates success or failure.
Parameters:
object$questionThe 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)
Parameters:
object$question
Returns:
number|null either a fraction estimating what the student would score by guessing, or null, if it is not possible to estimate.

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.

Returns:
whether the question_answers.answer field needs to have restore_decode_content_links_worker called on it.

Definition at line 148 of file questiontypebase.php.

import_file ( context,
component,
filearea,
itemid,
file 
)

Definition at line 1193 of file questiontypebase.php.

Here is the call graph for this function:

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.

Parameters:
array$fieldthe 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$contextthe context the question is in.
string$componentindentifies the file area question.
string$fileareaindentifies the file area questiontext, generalfeedback, answerfeedback, etc.
int$itemididentifies the file area.
Returns:
string the text for this field, after files have been processed.

Definition at line 1065 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

initialise_combined_feedback ( question_definition question,
questiondata,
withparts = false 
) [protected]

Initialise the combined feedback fields.

Parameters:
question_definition$questionthe question_definition we are creating.
object$questiondatathe question data loaded from the database.
bool$withpartswhether to set the shownumcorrect field.

Definition at line 748 of file questiontypebase.php.

Here is the caller graph for this function:

initialise_question_answers ( question_definition question,
questiondata,
forceplaintextanswers = true 
) [protected]

Initialise question_definition::answers field.

Parameters:
question_definition$questionthe question_definition we are creating.
object$questiondatathe question data loaded from the database.
bool$forceplaintextanswersmost 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.

Here is the caller graph for this function:

initialise_question_hints ( question_definition question,
questiondata 
) [protected]

Initialise question_definition::hints field.

Parameters:
question_definition$questionthe question_definition we are creating.
object$questiondatathe 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.

Parameters:
question_definition$questionthe question_definition we are creating.
object$questiondatathe 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.

Returns:
bool true if this question type sometimes requires manual grading.

Reimplemented in qtype_random, and qtype_essay.

Definition at line 108 of file questiontypebase.php.

Here is the caller graph for this function:

is_question_manual_graded ( question,
otherquestionsinuse 
)
Parameters:
object$questiona question of this type.
string$otherquestionsinusecomma-separate list of other question ids in this attempt.
Returns:
bool true if a particular instance of this question requires manual grading.

Reimplemented in qtype_random.

Definition at line 117 of file questiontypebase.php.

Here is the call graph for this function:

Returns:
bool override this to return false if this is not really a question type, for example the description question type is not really a question type.

Reimplemented in qtype_description.

Definition at line 101 of file questiontypebase.php.

Returns:
bool true if this question type can be used by the random question type.

Reimplemented in qtype_random, qtype_randomsamatch, qtype_missingtype, and qtype_description.

Definition at line 124 of file questiontypebase.php.

Returns:
string the name of this question type in the user's language. You should not need to override this method, the default behaviour should be fine.

Definition at line 76 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

make_hint ( hint) [protected]

Create a question_hint, or an appropriate subclass for this question, from a row loaded from the database.

Parameters:
object$hintthe DB row from the question hints table.
Returns:
question_hint

Reimplemented in qtype_match, and qtype_multichoice.

Definition at line 738 of file questiontypebase.php.

Here is the call graph for this function:

make_question ( questiondata)

Create an appropriate question_definition for the question of this type using data loaded from the database.

Parameters:
object$questiondatathe question data loaded from the database.
Returns:
question_definition the corresponding question_definition.

Reimplemented in qtype_random, and qtype_missingtype.

Definition at line 659 of file questiontypebase.php.

Here is the caller graph for this function:

make_question_instance ( questiondata) [protected]

Create an appropriate question_definition for the question of this type using data loaded from the database.

Parameters:
object$questiondatathe question data loaded from the database.
Returns:
question_definition an instance of the appropriate question_definition subclass. Still needs to be initialised.

Reimplemented in qtype_calculatedmulti, and qtype_multichoice.

Definition at line 672 of file questiontypebase.php.

Here is the call graph for this function:

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.

Returns:
mixed the desired string, or false to hide this question type in the menu.

Reimplemented in qtype_random, and qtype_missingtype.

Definition at line 92 of file questiontypebase.php.

Here is the call graph for this function:

move_files ( questionid,
oldcontextid,
newcontextid 
)

Move all the files belonging to this question from one context to another.

Parameters:
int$questionidthe question being moved.
int$oldcontextidthe context it is moving from.
int$newcontextidthe 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.

Here is the call graph for this function:

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.

Parameters:
int$questionidthe question being moved.
int$oldcontextidthe context it is moving from.
int$newcontextidthe context it is moving to.
bool$answerstoowhether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false.

Definition at line 1103 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
int$questionidthe question being moved.
int$oldcontextidthe context it is moving from.
int$newcontextidthe context it is moving to.
bool$answerstoowhether there is an 'answer' question area, as well as an 'answerfeedback' one. Default false.

Definition at line 1129 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

name ( )
Returns:
string the name of this question type.

Definition at line 61 of file questiontypebase.php.

Here is the caller graph for this function:

Returns:
string the URL of the folder this plugin's files live in.

Definition at line 235 of file questiontypebase.php.

Here is the call graph for this function:

Returns:
string the full path of the folder this plugin's files live in.

Definition at line 227 of file questiontypebase.php.

Here is the call graph for this function:

Returns:
string the full frankenstyle name for this plugin.

Definition at line 68 of file questiontypebase.php.

Here is the caller graph for this function:

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.

Here is the caller graph for this function:

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').

Returns:
array response variable names that may have associated files.

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.

Parameters:
object$optionsthe $question->options object being built.
object$formdatathe data from the form.
object$contextthe context the quetsion is being saved into.
bool$withpartswhether $options->shownumcorrect should be set.

Definition at line 569 of file questiontypebase.php.

Here is the caller graph for this function:

save_hints ( formdata,
withparts = false 
)

Definition at line 492 of file questiontypebase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
object$questionthe question object which should be updated. For a new question will be mostly empty.
object$formthe object containing the information to save, as if from the question editing form.
object$coursenot really used any more.
Returns:
object On success, return the new question object. On failure, return an object as follows. If the error object has an errors field, display that as an error message. Otherwise, the editing form will be redisplayed with validation errors, from validation_errors field, which is itself an object, shown next to the form fields. (I don't think this is accurate 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.

Here is the call graph for this function:

save_question_options ( question)

Saves question-type specific options

This is called by save_question() to save the question-type specific data

Returns:
object $result->error or $result->noticeyesno or $result->notice
Parameters:
object$questionThis 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.

Here is the call graph for this function:

Here is the caller graph for this function:

set_default_options ( questiondata)

Set any missing settings for this question to the default values. This is called before displaying the question editing form.

Parameters:
object$questiondatathe 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.


Field Documentation

$fileoptions [protected]
Initial value:
 array(
        'subdirs' => false,
        'maxfiles' => -1,
        'maxbytes' => 0,
    )

Definition at line 49 of file questiontypebase.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations