|
Moodle
2.2.1
http://www.collinsharper.com
|
This class keeps track of a group of questions that are being attempted, and which state, and so on, each one is currently in.
A quiz attempt or a lesson attempt could use an instance of this class to keep track of all the questions in the attempt and process student submissions. It is basically a collection of {} objects.
The questions being attempted as part of this usage are identified by an integer that is passed into many of the methods as $slot. ($question->id is not used so that the same question can be used more than once in an attempt.)
Normally, calling code should be able to do everything it needs to be calling methods of this class. You should not normally need to get individual {} objects and play around with their inner workind, in code that it outside the quetsion engine.
Instances of this class correspond to rows in the question_usages table.
Definition at line 52 of file questionusage.php.
| __construct | ( | $ | component, |
| $ | context | ||
| ) |
Create a new instance. Normally, calling code should use question_engine::make_questions_usage_by_activity() or question_engine::load_questions_usage_by_activity() rather than calling this constructor directly.
| string | $component | the plugin creating this attempt. For example mod_quiz. |
| object | $context | the context this usage belongs to. |
Definition at line 87 of file questionusage.php.
| add_question | ( | question_definition $ | question, |
| $ | maxmark = null |
||
| ) |
Add another question to this usage.
The added question is not started until you call start_question() on it.
| question_definition | $question | the question to add. |
| number | $maxmark | the maximum this question will be marked out of in this attempt (optional). If not given, $question->defaultmark is used. |
Definition at line 167 of file questionusage.php.

| check_file_access | ( | $ | slot, |
| $ | options, | ||
| $ | component, | ||
| $ | filearea, | ||
| $ | args, | ||
| $ | forcedownload | ||
| ) |
Checks whether the users is allow to be served a particular file.
| int | $slot | the number used to identify this question within this usage. |
| 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 400 of file questionusage.php.

| check_slot | ( | $ | slot | ) | [protected] |
Check whether $number actually corresponds to a question attempt that is part of this usage. Throws an exception if not.
| int | $slot | a number allegedly identifying a question within this usage. |
Definition at line 222 of file questionusage.php.

| extract_responses | ( | $ | slot, |
| $ | postdata = null |
||
| ) |
Get the submitted data from the current request that belongs to this particular question.
| int | $slot | the number used to identify this question within this usage. |
| $postdata | optional, only intended for testing. Use this data instead of the data from $_POST. |
Definition at line 540 of file questionusage.php.


| finish_all_questions | ( | $ | timestamp = null | ) |
Finish the active phase of an attempt at a question. See finish_question() for a fuller description of what 'finish' means.
Definition at line 628 of file questionusage.php.
| finish_question | ( | $ | slot, |
| $ | timestamp = null |
||
| ) |
Finish the active phase of an attempt at a question.
This is an external act of finishing the attempt. Think, for example, of the 'Submit all and finish' button in the quiz. Some behaviours, (for example, immediatefeedback) give a way of finishing the active phase of a question attempt as part of a process_action() call.
After the active phase is over, the only changes possible are things like manual grading, or changing the flag state.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 618 of file questionusage.php.

Note the part of the question_usage_by_activity comment that explains that question_attempt objects should be considered part of the inner workings of the question engine, and should not, if possible, be accessed directly.
Definition at line 212 of file questionusage.php.

| get_correct_response | ( | $ | slot | ) |
Get the correct response to a particular question. Passing the results of this method to process_action() will probably result in full marks. If it is not possible to compute a correct response, this method should return null.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 601 of file questionusage.php.

| get_field_prefix | ( | $ | slot | ) |
You should probably not use this method in code outside the question engine. The main reason for exposing it was for the benefit of unit tests.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 428 of file questionusage.php.

Definition at line 194 of file questionusage.php.
| get_id | ( | ) |
Definition at line 120 of file questionusage.php.


| get_num_variants | ( | $ | slot | ) |
Get the number of variants available for the question in this slot.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 437 of file questionusage.php.


| get_observer | ( | ) |
Definition at line 140 of file questionusage.php.

Definition at line 113 of file questionusage.php.

Definition at line 108 of file questionusage.php.

Definition at line 103 of file questionusage.php.

| get_question | ( | $ | slot | ) |
Get the question_definition for a question in this attempt.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 184 of file questionusage.php.

| get_question_action_time | ( | $ | slot | ) |
Get the time of the most recent action performed on a question.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 276 of file questionusage.php.

| get_question_attempt | ( | $ | slot | ) |
Note the part of the question_usage_by_activity comment that explains that question_attempt objects should be considered part of the inner workings of the question engine, and should not, if possible, be accessed directly.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 237 of file questionusage.php.


| get_question_fraction | ( | $ | slot | ) |
Get the current fraction awarded for the attempt at a question.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 286 of file questionusage.php.

| get_question_mark | ( | $ | slot | ) |
Get the current mark awarded for the attempt at a question.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 296 of file questionusage.php.

| get_question_max_mark | ( | $ | slot | ) |
Get the maximum mark possible for the attempt at a question.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 305 of file questionusage.php.

| get_question_state | ( | $ | slot | ) |
Get the current state of the attempt at a question.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 247 of file questionusage.php.

| get_question_state_class | ( | $ | slot, |
| $ | showcorrectness | ||
| ) |
| int | $slot | the number used to identify this question within this usage. |
| bool | $showcorrectness | Whether right/partial/wrong states should be distinguised. |
Definition at line 267 of file questionusage.php.

| get_question_state_string | ( | $ | slot, |
| $ | showcorrectness | ||
| ) |
| int | $slot | the number used to identify this question within this usage. |
| bool | $showcorrectness | Whether right/partial/wrong states should be distinguised. |
Definition at line 257 of file questionusage.php.

| get_question_summary | ( | $ | slot | ) |
Definition at line 329 of file questionusage.php.

| get_response_summary | ( | $ | slot | ) |
Definition at line 336 of file questionusage.php.

| get_right_answer_summary | ( | $ | slot | ) |
Definition at line 343 of file questionusage.php.

| get_slots | ( | ) |
Definition at line 189 of file questionusage.php.

| get_total_mark | ( | ) |
Get the current mark awarded for the attempt at a question.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 315 of file questionusage.php.
| get_variant | ( | $ | slot | ) |
Get the variant of the question being used in a given slot.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 446 of file questionusage.php.

| static load_from_records | ( | $ | records, |
| $ | qubaid | ||
| ) | [static] |
Create a question_usage_by_activity 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 692 of file questionusage.php.


| manual_grade | ( | $ | slot, |
| $ | comment, | ||
| $ | mark | ||
| ) |
Perform a manual grading action on a question attempt.
| int | $slot | the number used to identify this question within this usage. |
| string | $comment | the comment being added to the question attempt. |
| number | $mark | the mark that is being assigned. Can be null to just add a comment. |
Definition at line 642 of file questionusage.php.

| process_action | ( | $ | slot, |
| $ | submitteddata, | ||
| $ | timestamp = null |
||
| ) |
Process a specific action on a specific question.
| int | $slot | the number used to identify this question within this usage. |
| $submitteddata | the submitted data that constitutes the action. |
Definition at line 549 of file questionusage.php.


| process_all_actions | ( | $ | timestamp = null, |
| $ | postdata = null |
||
| ) |
Process all the question actions in the current request.
If there is a parameter slots included in the post data, then only those question numbers will be processed, otherwise all questions in this useage will be.
This function also does update_question_flags().
| int | $timestamp | optional, use this timestamp as 'now'. |
| array | $postdata | optional, only intended for testing. Use this data instead of the data from $_POST. |
Definition at line 512 of file questionusage.php.

| question_count | ( | ) |
Definition at line 200 of file questionusage.php.
| regrade_all_questions | ( | $ | finished = false | ) |
Regrade all the questions in this usage (without changing their max mark).
| bool | $finished | whether each question should be forced to be finished after the regrade, or whether it may still be in progress (default false). |
Definition at line 677 of file questionusage.php.

| regrade_question | ( | $ | slot, |
| $ | finished = false, |
||
| $ | newmaxmark = null |
||
| ) |
Regrade a question in this usage. This replays the sequence of submitted actions to recompute the outcomes.
| int | $slot | the number used to identify this question within this usage. |
| 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). |
| number | $newmaxmark | (optional) if given, will change the max mark while regrading. |
Definition at line 656 of file questionusage.php.


| render_question | ( | $ | slot, |
| $ | options, | ||
| $ | number = null |
||
| ) |
Get the core_question_renderer, in collaboration with appropriate qbehaviour_renderer and qtype_renderer subclasses, to generate the HTML to display this question.
| int | $slot | the number used to identify this question within this usage. |
| 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 357 of file questionusage.php.

| render_question_at_step | ( | $ | slot, |
| $ | seq, | ||
| $ | options, | ||
| $ | number = null |
||
| ) |
Like render_question() but displays the question at the past step indicated by $seq, rather than showing the latest step.
| int | $slot | the number used to identify this question within this usage. |
| 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 384 of file questionusage.php.

| render_question_head_html | ( | $ | slot | ) |
Generate any bits of HTML that needs to go in the <head> tag when this question is displayed in the body.
| int | $slot | the number used to identify this question within this usage. |
Definition at line 368 of file questionusage.php.

| replace_loaded_question_attempt_info | ( | $ | slot, |
| $ | qa | ||
| ) |
Replace a particular question_attempt with a different one.
For internal use only. Used when reloading the state of a question from the database.
| array | $records | Raw records loaded from the database. |
| int | $questionattemptid | The id of the question_attempt to extract. |
Definition at line 416 of file questionusage.php.

| set_id_from_database | ( | $ | id | ) |
For internal use only. Used by question_engine_data_mapper to set the id when a usage is saved to the database.
| int | $id | the newly determined id for this usage. |
Definition at line 132 of file questionusage.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 usage. |
Definition at line 149 of file questionusage.php.
| set_preferred_behaviour | ( | $ | behaviour | ) |
| string | $behaviour | the name of an archetypal behaviour, that should be used by questions in this usage if possible. |
Definition at line 97 of file questionusage.php.
| start_all_questions | ( | question_variant_selection_strategy $ | variantstrategy = null, |
| $ | timestamp = null, |
||
| $ | userid = null |
||
| ) |
Start the attempt at all questions that has been added to this usage.
| question_variant_selection_strategy | how to pick which variant of each question to use. | |
| 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. |
Definition at line 473 of file questionusage.php.
| start_question | ( | $ | slot, |
| $ | variant = null |
||
| ) |
Start the attempt at a question that has been added to this usage.
| int | $slot | the number used to identify this question within this usage. |
| int | $variant | which variant of the question to use. Must be between 1 and ->get_num_variants($slot) inclusive. If not give, a variant is chosen at random. |
Definition at line 457 of file questionusage.php.

| start_question_based_on | ( | $ | slot, |
| question_attempt $ | oldqa | ||
| ) |
Start the attempt at a question, starting from the point where the previous question_attempt $oldqa had reached. This is used by the quiz 'Each attempt builds on last' mode.
| int | $slot | the number used to identify this question within this usage. |
| question_attempt | $oldqa | a previous attempt at this quetsion that defines the starting point. |
Definition at line 493 of file questionusage.php.

| update_question_flags | ( | $ | postdata = null | ) |
Update the flagged state for all question_attempts in this usage, if their flagged state was changed in the request.
| $postdata | optional, only intended for testing. Use this data instead of the data from $_POST. |
Definition at line 584 of file questionusage.php.

| validate_sequence_number | ( | $ | slot, |
| $ | postdata = null |
||
| ) |
Check that the sequence number, that detects weird things like the student clicking back, is OK. If the sequence check variable is not present, returns false. If the check variable is present and correct, returns true. If the variable is present and wrong, throws an exception.
| int | $slot | the number used to identify this question within this usage. |
| array | $submitteddata | the submitted data that constitutes the action. |
Definition at line 565 of file questionusage.php.


$context [protected] |
Definition at line 67 of file questionusage.php.
$id = null [protected] |
Definition at line 58 of file questionusage.php.
$observer [protected] |
Definition at line 76 of file questionusage.php.
$owningcomponent [protected] |
Definition at line 70 of file questionusage.php.
$preferredbehaviour = null [protected] |
Definition at line 64 of file questionusage.php.
$questionattempts = array() [protected] |
Definition at line 73 of file questionusage.php.