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

Public Member Functions

 __construct ()
 get_type_name ()
 make_behaviour (question_attempt $qa, $preferredbehaviour)
 start_attempt (question_attempt_step $step, $variant)
 apply_attempt_state (question_attempt_step $step)
 get_question_summary ()
 get_num_variants ()
 get_variants_selection_seed ()
 get_min_fraction ()
 clear_wrong_from_response (array $response)
 get_num_parts_right (array $response)
 get_renderer (moodle_page $page)
 get_expected_data ()
 get_correct_response ()
 format_text ($text, $format, $qa, $component, $filearea, $itemid, $clean=false)
 html_to_text ($text, $format)
 format_questiontext ($qa)
 format_generalfeedback ($qa)
 check_file_access ($qa, $options, $component, $filearea, $args, $forcedownload)

Data Fields

 $id
 $category
 $contextid
 $parent = 0
 $qtype
 $name
 $questiontext
 $questiontextformat
 $generalfeedback
 $generalfeedbackformat
 $defaultmark = 1
 $length = 1
 $penalty = 0
 $stamp
 $version
 $hidden = 0
 $timecreated
 $timemodified
 $createdby
 $modifiedby
 $hints = array()

Detailed Description

The definition of a question of a particular type.

This class is a close match to the question table in the database. Definitions of question of a particular type normally subclass one of the more specific classes question_with_responses, question_graded_automatically or question_information_item.

Definition at line 41 of file questionbase.php.


Constructor & Destructor Documentation

Constructor. Normally to get a question, you call question_bank::load_question(), but questions can be created directly, for example in unit test code.

Returns:
unknown_type

Reimplemented in question_information_item, and qtype_shortanswer_question.

Definition at line 112 of file questionbase.php.

Here is the caller graph for this function:


Member Function Documentation

When an in-progress question_attempt is re-loaded from the database, this method is called so that the question can re-initialise its internal state as needed by this attempt.

For example, the multiple choice question type needs to set the order of the choices to the order that was set up when start_attempt was called originally. All the information required to do this should be in the $step object, which is the first step of the question_attempt being loaded.

Parameters:
question_attempt_stepThe first step of the question_attempt being loaded.

Reimplemented in qtype_calculatedmulti_multi_question, qtype_multianswer_question, qtype_match_question, qtype_numerical_question, qtype_multichoice_base, qtype_calculatedmulti_single_question, and qtype_calculated_question.

Definition at line 179 of file questionbase.php.

check_file_access ( qa,
options,
component,
filearea,
args,
forcedownload 
)

Checks whether the users is allow to be served a particular file.

Parameters:
question_attempt$qathe question attempt being displayed.
question_display_options$optionsthe options that control display of the question.
string$componentthe name of the component we are serving files for.
string$fileareathe name of the file area.
array$argsthe remaining bits of the file path.
bool$forcedownloadwhether the user must be forced to download the file.
Returns:
bool true if the user can access this file.

Reimplemented in qtype_numerical_question, qtype_match_question, qtype_multianswer_question, qtype_shortanswer_question, qtype_truefalse_question, qtype_essay_question, and qtype_multichoice_base.

Definition at line 327 of file questionbase.php.

Given a response, rest the parts that are wrong.

Parameters:
array$responsea response
Returns:
array a cleaned up response with the wrong bits reset.

Reimplemented in qtype_multichoice_multi_question, and qtype_match_question.

Definition at line 227 of file questionbase.php.

Returns:
the result of applying format_text() to the general feedback.

Definition at line 312 of file questionbase.php.

Here is the call graph for this function:

Returns:
the result of applying format_text() to the question text.

Definition at line 306 of file questionbase.php.

Here is the call graph for this function:

format_text ( text,
format,
qa,
component,
filearea,
itemid,
clean = false 
)

Apply format_text() to some content with appropriate settings for this question.

Parameters:
string$textsome content that needs to be output.
int$formatthe FORMAT_... constant.
question_attempt$qathe question attempt.
string$componentused for rewriting file area URLs.
string$fileareaused for rewriting file area URLs.
bool$cleanWhether the HTML needs to be cleaned. Generally, parts of the question do not need to be cleaned, and student input does.
Returns:
string the text formatted for output by format_text.

Definition at line 285 of file questionbase.php.

Here is the caller graph for this function:

get_correct_response ( ) [abstract]

What data would need to be submitted to get this question correct. If there is more than one correct answer, this method should just return one possibility. If it is not possible to compute a correct response, this method should return null.

Returns:
array|null parameter name => value.

Reimplemented in question_graded_by_strategy, question_information_item, qtype_multichoice_multi_question, qtype_multichoice_single_question, qtype_match_question, qtype_numerical_question, qtype_multianswer_question, qtype_essay_question, qtype_missingtype_question, and qtype_truefalse_question.

Here is the caller graph for this function:

get_expected_data ( ) [abstract]

What data may be included in the form submission when a student submits this question in its current state?

This information is used in calls to optional_param. The parameter name has question_attempt::get_field_prefix() automatically prepended.

Returns:
array|string variable name => PARAM_... constant, or, as a special case that should only be used in unavoidable, the constant question_attempt::USE_RAW_DATA meaning take all the raw submitted data belonging to this question.

Reimplemented in question_information_item, qtype_multichoice_multi_question, qtype_match_question, qtype_multichoice_single_question, qtype_multianswer_question, qtype_essay_question, qtype_numerical_question, qtype_shortanswer_question, qtype_missingtype_question, and qtype_truefalse_question.

Some questions can return a negative mark if the student gets it wrong.

This method returns the lowest mark the question can return, on the fraction scale. that is, where the maximum possible mark is 1.0.

Returns:
number minimum fraction this question will ever return.

Reimplemented in qtype_multichoice_multi_question, qtype_multichoice_single_question, and qtype_multianswer_question.

Definition at line 218 of file questionbase.php.

get_num_parts_right ( array response)

Return the number of subparts of this response that are right.

Parameters:
array$responsea response
Returns:
array with two elements, the number of correct subparts, and the total number of subparts.

Reimplemented in qtype_multichoice_multi_question, and qtype_match_question.

Definition at line 237 of file questionbase.php.

Returns:
int the number of vaiants that this question has.

Reimplemented in qtype_calculated_question, and qtype_calculatedmulti_single_question.

Definition at line 198 of file questionbase.php.

Generate a brief, plain-text, summary of this question. This is used by various reports. This should show the particular variant of the question as presented to students. For example, the calculated quetsion type would fill in the particular numbers that were presented to the student. This method will return null if such a summary is not possible, or inappropriate.

Returns:
string|null a plain text summary of this question.

Reimplemented in question_information_item, qtype_match_question, qtype_multianswer_question, and qtype_multichoice_base.

Definition at line 191 of file questionbase.php.

Here is the call graph for this function:

Parameters:
moodle_pagethe page we are outputting to.
Returns:
qtype_renderer the renderer to use for outputting this question.

Reimplemented in qtype_multichoice_multi_question, and qtype_multichoice_single_question.

Definition at line 245 of file questionbase.php.

Here is the call graph for this function:

Returns:
the name of the question type (for example multichoice) that this question is.

Definition at line 119 of file questionbase.php.

Returns:
string that can be used to seed the pseudo-random selection of a variant.

Reimplemented in qtype_calculated_question, and qtype_calculatedmulti_single_question.

Definition at line 206 of file questionbase.php.

html_to_text ( text,
format 
)

Convert some part of the question text to plain text. This might be used, for example, by get_response_summary().

Parameters:
string$textThe HTML to reduce to plain text.
int$formatthe FORMAT_... constant.
Returns:
string the equivalent plain text.

Definition at line 301 of file questionbase.php.

Here is the call graph for this function:

Here is the caller graph for this function:

make_behaviour ( question_attempt qa,
preferredbehaviour 
)

Creat the appropriate behaviour for an attempt at this quetsion, given the desired (archetypal) behaviour.

This default implementation will suit most normal graded questions.

If your question is of a patricular type, then it may need to do something different. For example, if your question can only be graded manually, then it should probably return a manualgraded behaviour, irrespective of what is asked for.

If your question wants to do somthing especially complicated is some situations, then you may wish to return a particular behaviour related to the one asked for. For example, you migth want to return a qbehaviour_interactive_adapted_for_myqtype.

Parameters:
question_attempt$qathe attempt we are creating an behaviour for.
string$preferredbehaviourthe requested type of behaviour.
Returns:
question_behaviour the new behaviour object.

Reimplemented in question_graded_automatically_with_countback, question_information_item, and qtype_essay_question.

Definition at line 143 of file questionbase.php.

Here is the call graph for this function:

start_attempt ( question_attempt_step step,
variant 
)

Start a new attempt at this question, storing any information that will be needed later in the step.

This is where the question can do any initialisation required on a per-attempt basis. For example, this is where the multiple choice question type randomly shuffles the choices (if that option is set).

Any information about how the question has been set up for this attempt should be stored in the $step, by calling $step->set_qt_var(...).

Parameters:
question_attempt_stepThe first step of the question_attempt being started. Can be used to store state.
int$varantwhich variant of this question to start. Will be between 1 and get_num_variants() inclusive.

Reimplemented in qtype_calculatedmulti_multi_question, qtype_missingtype_question, qtype_multianswer_question, qtype_numerical_question, qtype_match_question, qtype_multichoice_base, qtype_calculatedmulti_single_question, and qtype_calculated_question.

Definition at line 163 of file questionbase.php.


Field Documentation

Definition at line 47 of file questionbase.php.

Definition at line 50 of file questionbase.php.

$createdby

Definition at line 98 of file questionbase.php.

$defaultmark = 1

Definition at line 74 of file questionbase.php.

$generalfeedback

Definition at line 68 of file questionbase.php.

$generalfeedbackformat

Definition at line 71 of file questionbase.php.

$hidden = 0

Definition at line 89 of file questionbase.php.

$hints = array()

Definition at line 104 of file questionbase.php.

$id

Definition at line 44 of file questionbase.php.

$length = 1

Definition at line 77 of file questionbase.php.

$modifiedby

Definition at line 101 of file questionbase.php.

$name

Definition at line 59 of file questionbase.php.

$parent = 0

Definition at line 53 of file questionbase.php.

$penalty = 0

Definition at line 80 of file questionbase.php.

$qtype

Definition at line 56 of file questionbase.php.

$questiontext

Definition at line 62 of file questionbase.php.

$questiontextformat

Definition at line 65 of file questionbase.php.

$stamp

Definition at line 83 of file questionbase.php.

$timecreated

Definition at line 92 of file questionbase.php.

$timemodified

Definition at line 95 of file questionbase.php.

Definition at line 86 of file questionbase.php.


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