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

Tracks an attempt at one particular question in a question_usage_by_activity.
Most calling code should need to access objects of this class. They should be able to do everything through the usage interface. This class is an internal implementation detail of the question engine.
Instances of this class correspond to rows in the question_attempts table, and a collection of question_attempt_steps. Question inteaction models and question types do work with question_attempt objects.
Definition at line 44 of file questionattempt.php.
| __construct | ( | question_definition $ | question, |
| $ | usageid, | ||
| question_usage_observer $ | observer = null, |
||
| $ | maxmark = null |
||
| ) |
#@- Create a new question_attempt. Normally you should create question_attempts indirectly, by calling question_usage_by_activity::add_question().
| question_definition | $question | the question this is an attempt at. |
| int | string | $usageid | The id of the question_usage_by_activity we belong to. Used by get_field_prefix(). |
| question_usage_observer | $observer | tracks changes to the useage this attempt is part of. (Optional, a question_usage_null_observer is used if one is not passed. |
| number | $maxmark | the maximum grade for this question_attempt. If not passed, $question->defaultmark is used. |
Definition at line 148 of file questionattempt.php.
| add_step | ( | question_attempt_step $ | step | ) | [protected] |
Add a step to this question attempt.
| question_attempt_step | $step | the new step. |
Reimplemented in question_attempt_with_restricted_history.
Definition at line 785 of file questionattempt.php.

| check_file_access | ( | $ | options, |
| $ | component, | ||
| $ | filearea, | ||
| $ | args, | ||
| $ | forcedownload | ||
| ) |
Checks whether the users is allow to be served a particular file.
| question_display_options | $options | the options that control display of the question. |
| string | $component | the name of the component we are serving files for. |
| string | $filearea | the name of the file area. |
| array | $args | the remaining bits of the file path. |
| bool | $forcedownload | whether the user must be forced to download the file. |
Definition at line 777 of file questionattempt.php.
Definition at line 1151 of file questionattempt.php.

| extra_file_path_components | ( | ) | [protected] |
Helper function used by rewrite_pluginfile_urls() and rewrite_response_pluginfile_urls().
Definition at line 685 of file questionattempt.php.


| finish | ( | $ | timestamp = null, |
| $ | userid = null |
||
| ) |
Perform a finish action on this question attempt. This corresponds to an external finish action, for example the user pressing Submit all and finish in the quiz, rather than using one of the controls that is part of the question.
| int | $timestamp | the time to record for the action. (If not given, use now.) |
| int | $userid | the user to attribute the aciton to. (If not given, use the current user.) |
Definition at line 1074 of file questionattempt.php.


| format_fraction_as_mark | ( | $ | fraction, |
| $ | dp | ||
| ) |
The current mark, formatted to the stated number of decimal places. Uses format_float() to format floats according to the current locale.
| int | $dp | number of decimal places. |
Definition at line 648 of file questionattempt.php.


| format_mark | ( | $ | dp | ) |
The current mark, formatted to the stated number of decimal places. Uses format_float() to format floats according to the current locale.
| int | $dp | number of decimal places. |
Definition at line 638 of file questionattempt.php.


| format_max_mark | ( | $ | dp | ) |
The maximum mark for this question attempt, formatted to the stated number of decimal places. Uses format_float() to format floats according to the current locale.
| int | $dp | number of decimal places. |
Definition at line 659 of file questionattempt.php.


| fraction_to_mark | ( | $ | fraction | ) |
| number | null | $fraction | a fraction. |
Definition at line 612 of file questionattempt.php.

| get_all_submitted_qt_vars | ( | $ | postdata | ) | [protected] |
Get all the submitted question type data for this question, whithout checking that it is valid or cleaning it in any way.
Definition at line 961 of file questionattempt.php.


Return the hint that applies to the question in its current state, or null.
Definition at line 667 of file questionattempt.php.

| get_behaviour | ( | ) |
For internal use only.
Definition at line 248 of file questionattempt.php.

| get_behaviour_field_name | ( | $ | varname | ) |
Get the name (in the sense a HTML name="" attribute, or a $_POST variable name) to use for a question_type variable belonging to this question_attempt.
See the comment on question_attempt_step for an explanation of question type and behaviour variables.
| $varname | The short form of the variable name. |
Definition at line 300 of file questionattempt.php.


Definition at line 240 of file questionattempt.php.

| get_control_field_name | ( | $ | varname | ) |
Get the name (in the sense a HTML name="" attribute, or a $_POST variable name) to use for a control variables belonging to this question_attempt.
Examples are :sequencecheck and :flagged
| $varname | The short form of the variable name. |
Definition at line 313 of file questionattempt.php.


Get a set of response data for this question attempt that would get the best possible mark. If it is not possible to compute a correct response, this method should return null.
Definition at line 1005 of file questionattempt.php.
This is used by the manual grading code, particularly in association with validation. If there is a mark submitted in the request, then use that, otherwise use the latest mark for this question.
Definition at line 599 of file questionattempt.php.


| get_database_id | ( | ) |
Definition at line 203 of file questionattempt.php.

| get_expected_data | ( | $ | expected, |
| $ | postdata, | ||
| $ | extraprefix | ||
| ) | [protected] |
Get any data from the request that matches the list of expected params.
| array | $expected | variable name => PARAM_... constant. |
| string | $extraprefix | '-' or ''. |
Definition at line 944 of file questionattempt.php.


| get_field_prefix | ( | ) |
Get the prefix added to variable names to give field names for this question attempt.
You should not use this method directly. This is an implementation detail anyway, but if you must access it, use question_usage_by_activity::get_field_prefix().
| $varname | The short form of the variable name. |
Definition at line 327 of file questionattempt.php.

Get the name (in the sense a HTML name="" attribute, or a $_POST variable name) to use for the field that indicates whether this question is flagged.
Definition at line 272 of file questionattempt.php.


| get_fraction | ( | ) |
Get the current fraction of this question attempt. That is, the fraction of the latest step, or null if this question has not yet been graded.
Definition at line 574 of file questionattempt.php.


| get_full_qa | ( | ) |
This method exists so that question_attempt_with_restricted_history can override it. You should not normally need to call it.
Reimplemented in question_attempt_with_restricted_history.
Definition at line 168 of file questionattempt.php.

The same as get_step_iterator(). However, for a question_attempt_with_restricted_history this returns the full list of steps, while get_step_iterator() returns only the limited history.
Reimplemented in question_attempt_with_restricted_history.
Definition at line 381 of file questionattempt.php.


Definition at line 565 of file questionattempt.php.

| get_last_behaviour_var | ( | $ | name, |
| $ | default = null |
||
| ) |
Get the latest value of a particular behaviour variable. That is, get the value from the latest step that has it set. Return null if it is not set in any step.
| string | $name | the name of the variable to get. |
| mixed | default the value to return in the variable has never been set. (Optional, defaults to null.) |
Definition at line 526 of file questionattempt.php.


| get_last_qt_data | ( | $ | default = array() | ) |
Get the qt data from the latest step that has any qt data. Return $default array if it is no step has qt data.
| string | $name | the name of the variable to get. |
| mixed | default the value to return no step has qt data. (Optional, defaults to an empty array.) |
Definition at line 402 of file questionattempt.php.


| get_last_qt_files | ( | $ | name, |
| $ | contextid | ||
| ) |
Get the latest set of files for a particular question type variable of type question_attempt::PARAM_FILES.
| string | $name | the name of the associated variable. |
Definition at line 468 of file questionattempt.php.


| get_last_qt_var | ( | $ | name, |
| $ | default = null |
||
| ) |
Get the latest value of a particular question type variable. That is, get the value from the latest step that has it set. Return null if it is not set in any step.
| string | $name | the name of the variable to get. |
| mixed | default the value to return in the variable has never been set. (Optional, defaults to null.) |
Definition at line 452 of file questionattempt.php.


| get_last_step | ( | ) |
Return the latest step in this question_attempt. For internal/test code use only.
Definition at line 358 of file questionattempt.php.

| get_last_step_with_behaviour_var | ( | $ | name | ) |
Get the last step with a particular behaviour variable set.
| string | $name | the name of the variable to get. |
Definition at line 433 of file questionattempt.php.

| get_last_step_with_qt_var | ( | $ | name | ) |
Get the last step with a particular question type varialbe set.
| string | $name | the name of the variable to get. |
Definition at line 418 of file questionattempt.php.


Definition at line 1134 of file questionattempt.php.


| get_mark | ( | ) |
Definition at line 588 of file questionattempt.php.


| get_max_mark | ( | ) |
Definition at line 620 of file questionattempt.php.

| get_min_fraction | ( | ) |
Definition at line 625 of file questionattempt.php.

| get_num_steps | ( | ) |
Get the number of steps in this attempt. For internal/test code use only.
Definition at line 349 of file questionattempt.php.

| get_qt_field_name | ( | $ | varname | ) |
Get the name (in the sense a HTML name="" attribute, or a $_POST variable name) to use for a question_type variable belonging to this question_attempt.
See the comment on question_attempt_step for an explanation of question type and behaviour variables.
| $varname | The short form of the variable name. |
Definition at line 286 of file questionattempt.php.


| get_question | ( | ) |
Definition at line 173 of file questionattempt.php.

Definition at line 1031 of file questionattempt.php.

| get_response_file_url | ( | stored_file $ | file | ) |
Get the URL of a file that belongs to a response variable of this question_attempt.
| stored_file | $file | the file to link to. |
Definition at line 483 of file questionattempt.php.


Definition at line 1038 of file questionattempt.php.

| get_resume_data | ( | ) | [protected] |
Used by start_based_on() to get the data needed to start a new attempt from the point this attempt has go to.
Definition at line 867 of file questionattempt.php.

Definition at line 389 of file questionattempt.php.

Definition at line 1045 of file questionattempt.php.

| get_slot | ( | ) |
Definition at line 195 of file questionattempt.php.

| get_state | ( | ) |
Get the current state of this question attempt. That is, the state of the latest step.
Definition at line 540 of file questionattempt.php.


| get_state_class | ( | $ | showcorrectness | ) |
| bool | $showcorrectness | Whether right/partial/wrong states should be distinguised. |
Definition at line 558 of file questionattempt.php.


| get_state_string | ( | $ | showcorrectness | ) |
| bool | $showcorrectness | Whether right/partial/wrong states should be distinguised. |
Definition at line 549 of file questionattempt.php.

| get_step | ( | $ | i | ) |
Get one of the steps in this attempt. For internal/test code use only.
| int | $i | the step number. |
Definition at line 337 of file questionattempt.php.

Definition at line 369 of file questionattempt.php.

| get_submitted_data | ( | $ | postdata = null | ) |
Get all the sumbitted data belonging to this question attempt from the current request.
| array | $postdata | (optional, only inteded for testing use) take the data from this array, instead of from $_POST. |
Definition at line 986 of file questionattempt.php.

| get_submitted_var | ( | $ | name, |
| $ | type, | ||
| $ | postdata = null |
||
| ) |
Get a particular parameter from the current request. A wrapper round optional_param(), except that the results is returned without slashes.
| string | $name | the paramter name. |
| int | $type | one of the standard PARAM_... constants, or one of the special extra constands defined by this class. |
| array | $postdata | (optional, only inteded for testing use) take the data from this array, instead of from $_POST. |
Definition at line 882 of file questionattempt.php.


| get_usage_id | ( | ) |
Definition at line 226 of file questionattempt.php.

| get_variant | ( | ) |
Get the variant of the question being used in a given slot.
Definition at line 181 of file questionattempt.php.

Definition at line 1121 of file questionattempt.php.

| has_marks | ( | ) |
Definition at line 579 of file questionattempt.php.

| is_flagged | ( | ) |
Definition at line 262 of file questionattempt.php.

| static load_from_records | ( | $ | records, |
| $ | questionattemptid, | ||
| question_usage_observer $ | observer, | ||
| $ | preferredbehaviour | ||
| ) | [static] |
Create a question_attempt_step from records loaded from the database.
For internal use only.
| Iterator | $records | Raw records loaded from the database. |
| int | $questionattemptid | The id of the question_attempt to extract. |
Definition at line 1164 of file questionattempt.php.


| manual_grade | ( | $ | comment, |
| $ | mark, | ||
| $ | timestamp = null, |
||
| $ | userid = null |
||
| ) |
Perform a manual grading action on this attempt.
| $comment | the comment being added. | |
| $mark | the new mark. (Optional, if not given, then only a comment is added.) | |
| int | $timestamp | the time to record for the action. (If not given, use now.) |
| int | $userid | the user to attribute the aciton to. (If not given, use the current user.) |
Definition at line 1111 of file questionattempt.php.

| prepare_response_files_draft_itemid | ( | $ | name, |
| $ | contextid | ||
| ) |
Prepare a draft file are for the files belonging the a response variable of this question attempt. The draft area is populated with the files from the most recent step having files.
| string | $name | the variable name the files belong to. |
| int | $contextid | the id of the context the quba belongs to. |
Definition at line 503 of file questionattempt.php.


| process_action | ( | $ | submitteddata, |
| $ | timestamp = null, |
||
| $ | userid = null, |
||
| $ | existingstepid = null |
||
| ) |
Perform the action described by $submitteddata.
| array | $submitteddata | the submitted data the determines the action. |
| int | $timestamp | the time to record for the action. (If not given, use now.) |
| int | $userid | the user to attribute the aciton to. (If not given, use the current user.) |
Definition at line 1055 of file questionattempt.php.


| process_response_files | ( | $ | name, |
| $ | draftidname, | ||
| $ | postdata = null, |
||
| $ | text = null |
||
| ) | [protected] |
Handle a submitted variable representing uploaded files.
| string | $name | the field name. |
| string | $draftidname | the field name holding the draft file area id. |
| array | $postdata | (optional, only inteded for testing use) take the data from this array, instead of from $_POST. At the moment, this behaves as if there were no files. |
| string | $text | optional reponse text. |
Definition at line 923 of file questionattempt.php.


| regrade | ( | question_attempt $ | oldqa, |
| $ | finished | ||
| ) |
Perform a regrade. This replays all the actions from $oldqa into this attempt.
| question_attempt | $oldqa | the attempt to regrade. |
| bool | $finished | whether the question attempt should be forced to be finished after the regrade, or whether it may still be in progress (default false). |
Definition at line 1085 of file questionattempt.php.

| render | ( | $ | options, |
| $ | number, | ||
| $ | page = null |
||
| ) |
Get the core_question_renderer, in collaboration with appropriate qbehaviour_renderer and qtype_renderer subclasses, to generate the HTML to display this question attempt in its current state.
| question_display_options | $options | controls how the question is rendered. |
| string | null | $number | The question number to display. |
Definition at line 728 of file questionattempt.php.
| render_at_step | ( | $ | seq, |
| $ | options, | ||
| $ | number, | ||
| $ | preferredbehaviour | ||
| ) |
Like render_question() but displays the question at the past step indicated by $seq, rather than showing the latest step.
| int | $seq | the seq number of the past state to display. |
| question_display_options | $options | controls how the question is rendered. |
| string | null | $number | The question number to display. 'i' is a special value that gets displayed as Information. Null means no number is displayed. |
Definition at line 763 of file questionattempt.php.
| render_head_html | ( | $ | page = null | ) |
Generate any bits of HTML that needs to go in the <head> tag when this question attempt is displayed in the body.
Definition at line 743 of file questionattempt.php.
| rewrite_pluginfile_urls | ( | $ | text, |
| $ | component, | ||
| $ | filearea, | ||
| $ | itemid | ||
| ) |
Calls question_rewrite_question_urls() with appropriate parameters for content belonging to this question.
| string | $text | the content to output. |
| string | $component | the component name (normally 'question' or 'qtype_...') |
| string | $filearea | the name of the file area. |
| int | $itemid | the item id. |
Definition at line 698 of file questionattempt.php.

| rewrite_response_pluginfile_urls | ( | $ | text, |
| $ | contextid, | ||
| $ | name, | ||
| question_attempt_step $ | step | ||
| ) |
Calls question_rewrite_question_urls() with appropriate parameters for content belonging to responses to this question.
| string | $text | the text to update the URLs in. |
| int | $contextid | the id of the context the quba belongs to. |
| string | $name | the variable name the files belong to. |
| question_attempt_step | $step | the step the response is coming from. |
Definition at line 714 of file questionattempt.php.


| select_variant | ( | question_variant_selection_strategy $ | variantstrategy | ) |
Use a strategy to pick a variant.
| question_variant_selection_strategy | $variantstrategy | a strategy. |
Definition at line 796 of file questionattempt.php.

| set_database_id | ( | $ | id | ) |
For internal use only. Set the id of the corresponding database row.
| int | $id | the id of row for this question_attempt, if it is stored in the database. |
Reimplemented in question_attempt_with_restricted_history.
Definition at line 212 of file questionattempt.php.

| set_flagged | ( | $ | flagged | ) |
Set the flagged state of this question.
| bool | $flagged | the new state. |
Reimplemented in question_attempt_with_restricted_history.
Definition at line 256 of file questionattempt.php.
| set_observer | ( | $ | observer | ) |
You should almost certainly not call this method from your code. It is for internal use only.
| question_usage_observer | that should be used to tracking changes made to this qa. |
Definition at line 221 of file questionattempt.php.
| set_question_summary | ( | $ | questionsummary | ) |
Change the quetsion summary. Note, that this is almost never necessary. This method was only added to work around a limitation of the Opaque protocol, which only sends questionLine at the end of an attempt.
| $questionsummary | the new summary to set. |
Reimplemented in question_attempt_with_restricted_history.
Definition at line 1023 of file questionattempt.php.
| set_slot | ( | $ | slot | ) |
Set the number used to identify this question_attempt within the usage. For internal use only.
| int | $slot |
Reimplemented in question_attempt_with_restricted_history.
Definition at line 190 of file questionattempt.php.
| set_usage_id | ( | $ | usageid | ) |
Set the id of the question_usage_by_activity we belong to. For internal use only.
| int|string | the new id. |
Reimplemented in question_attempt_with_restricted_history.
Definition at line 235 of file questionattempt.php.
| start | ( | $ | preferredbehaviour, |
| $ | variant, | ||
| $ | submitteddata = array(), |
||
| $ | timestamp = null, |
||
| $ | userid = null, |
||
| $ | existingstepid = null |
||
| ) |
Start this question attempt.
You should not call this method directly. Call question_usage_by_activity::start_question() instead.
| string | question_behaviour | $preferredbehaviour | the name of the desired archetypal behaviour, or an actual model instance. |
| int | $variant | the variant of the question to start. Between 1 and $this->get_question()->get_num_variants() inclusive. |
| array | $submitteddata | optional, used when re-starting to keep the same initial state. |
| int | $timestamp | optional, the timstamp to record for this action. Defaults to now. |
| int | $userid | optional, the user to attribute this action to. Defaults to the current user. |
| int | $existingstepid | optional, if this step is going to replace an existing step (for example, during a regrade) this is the id of the previous step we are replacing. |
Definition at line 817 of file questionattempt.php.


| start_based_on | ( | question_attempt $ | oldqa | ) |
Start this question attempt, starting from the point that the previous attempt $oldqa had reached.
You should not call this method directly. Call question_usage_by_activity::start_question_based_on() instead.
| question_attempt | $oldqa | a previous attempt at this quetsion that defines the starting point. |
Definition at line 858 of file questionattempt.php.

| summarise_action | ( | question_attempt_step $ | step | ) |
Produce a plain-text summary of what the user did during a step.
| question_attempt_step | $step | the step in quetsion. |
Definition at line 676 of file questionattempt.php.

$behaviour = null [protected] |
Definition at line 82 of file questionattempt.php.
$flagged = false [protected] |
Definition at line 122 of file questionattempt.php.
$id = null [protected] |
Definition at line 70 of file questionattempt.php.
$maxmark [protected] |
Definition at line 91 of file questionattempt.php.
$minfraction = null [protected] |
Definition at line 97 of file questionattempt.php.
$observer [protected] |
Definition at line 125 of file questionattempt.php.
$question [protected] |
Definition at line 85 of file questionattempt.php.
$questionsummary = null [protected] |
Definition at line 103 of file questionattempt.php.
$responsesummary = null [protected] |
Definition at line 109 of file questionattempt.php.
$rightanswer = null [protected] |
Definition at line 116 of file questionattempt.php.
$slot = null [protected] |
Definition at line 76 of file questionattempt.php.
$steps = array() [protected] |
Definition at line 119 of file questionattempt.php.
$usageid [protected] |
Definition at line 73 of file questionattempt.php.
$variant [protected] |
Definition at line 88 of file questionattempt.php.
| const DISCARD = false |
Definition at line 132 of file questionattempt.php.
#@+ Constants used by the intereaction models to indicate whether the current pending step should be kept or discarded.
Definition at line 131 of file questionattempt.php.
| const PARAM_CLEANHTML_FILES = 'paramcleanhtmlfiles' |
Definition at line 67 of file questionattempt.php.
| const PARAM_FILES = 'paramfiles' |
Definition at line 61 of file questionattempt.php.
| const PARAM_MARK = 'parammark' |
Definition at line 55 of file questionattempt.php.
| const USE_RAW_DATA = 'use raw data' |
Definition at line 49 of file questionattempt.php.