Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
question_usage_by_activity Class Reference

This class keeps track of a group of questions that are being attempted, and which state, and so on, each one is currently in. More...

Public Member Functions

 __construct ($component, $context)
 Create a new instance. More...
 
 add_question (question_definition $question, $maxmark=null)
 Add another question to this usage. More...
 
 add_question_in_place_of_other ($slot, question_definition $question, $maxmark=null)
 Add another question to this usage, in the place of an existing slot. More...
 
 can_question_finish_during_attempt ($slot)
 Whether this attempt at a given question could be completed just by the student interacting with the question, before finish_question() is called. More...
 
 check_file_access ($slot, $options, $component, $filearea, $args, $forcedownload)
 Checks whether the users is allow to be served a particular file. More...
 
 extract_responses ($slot, $postdata=null)
 Get the submitted data from the current request that belongs to this particular question. More...
 
 finish_all_questions ($timestamp=null)
 Finish the active phase of an attempt at a question. More...
 
 finish_question ($slot, $timestamp=null)
 Finish the active phase of an attempt at a question. More...
 
 get_attempt_iterator ()
 Note the part of the } 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. More...
 
 get_correct_response ($slot)
 Get the correct response to a particular question. More...
 
 get_field_prefix ($slot)
 You should probably not use this method in code outside the question engine. More...
 
 get_first_question_number ()
 
 get_id ()
 
 get_num_variants ($slot)
 Get the number of variants available for the question in this slot. More...
 
 get_observer ()
 
 get_owning_component ()
 
 get_owning_context ()
 
 get_preferred_behaviour ()
 
 get_question ($slot)
 Get the question_definition for a question in this attempt. More...
 
 get_question_action_time ($slot)
 Get the time of the most recent action performed on a question. More...
 
 get_question_attempt ($slot)
 Note the part of the } 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. More...
 
 get_question_attempt_metadata ($slot, $name)
 Return one of the bits of metadata for a particular question attempt in this usage. More...
 
 get_question_fraction ($slot)
 Get the current fraction awarded for the attempt at a question. More...
 
 get_question_mark ($slot)
 Get the current mark awarded for the attempt at a question. More...
 
 get_question_max_mark ($slot)
 Get the maximum mark possible for the attempt at a question. More...
 
 get_question_state ($slot)
 Get the current state of the attempt at a question. More...
 
 get_question_state_class ($slot, $showcorrectness)
 
 get_question_state_string ($slot, $showcorrectness)
 
 get_question_summary ($slot)
 Get a simple textual summary of the question that was asked. More...
 
 get_response_summary ($slot)
 Get a simple textual summary of response given. More...
 
 get_right_answer_summary ($slot)
 Get a simple textual summary of the correct response to a question. More...
 
 get_slots ()
 
 get_summary_information (question_display_options $options)
 Get summary information about this usage. More...
 
 get_total_mark ()
 Get the total mark for all questions in this usage. More...
 
 get_variant ($slot)
 Get the variant of the question being used in a given slot. More...
 
 is_autosave_required ($slot, $postdata=null)
 Check, based on the sequence number, whether this auto-save is still required. More...
 
 manual_grade ($slot, $comment, $mark, $commentformat=null)
 Perform a manual grading action on a question attempt. More...
 
 next_slot_number ()
 The slot number that will be allotted to the next question added.
 
 prepare_simulated_post_data ($simulatedresponses)
 Transform an array of response data for slots to an array of post data as you would get from quiz attempt form. More...
 
 process_action ($slot, $submitteddata, $timestamp=null)
 Process a specific action on a specific question. More...
 
 process_all_actions ($timestamp=null, $postdata=null)
 Process all the question actions in the current request. More...
 
 process_all_autosaves ($timestamp=null, $postdata=null)
 Process all the question autosave data in the current request. More...
 
 process_autosave ($slot, $submitteddata, $timestamp=null)
 Process an autosave action on a specific question. More...
 
 question_count ()
 
 regrade_all_questions ($finished=false)
 Regrade all the questions in this usage (without changing their max mark). More...
 
 regrade_question ($slot, $finished=false, $newmaxmark=null)
 Regrade a question in this usage. More...
 
 render_question ($slot, $options, $number=null)
 Get the }, in collaboration with appropriate * qbehaviour_renderer} and qtype_renderer subclasses, to generate the HTML to display this question. More...
 
 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. More...
 
 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. More...
 
 replace_loaded_question_attempt_info ($slot, $qa)
 Replace a particular question_attempt with a different one. More...
 
 set_id_from_database ($id)
 For internal use only. More...
 
 set_max_mark ($slot, $maxmark)
 Change the max mark for this question_attempt. More...
 
 set_observer ($observer)
 You should almost certainly not call this method from your code. More...
 
 set_preferred_behaviour ($behaviour)
 
 set_question_attempt_metadata ($slot, $name, $value)
 Set some metadata for a particular question attempt in this usage. More...
 
 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. More...
 
 start_question ($slot, $variant=null, $timenow=null)
 Start the attempt at a question that has been added to this usage. More...
 
 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. More...
 
 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. More...
 
 validate_sequence_number ($slot, $postdata=null)
 Check that the sequence number, that detects weird things like the student clicking back, is OK. More...
 

Static Public Member Functions

static load_from_records ($records, $qubaid)
 Create a question_usage_by_activity from records loaded from the database. More...
 

Protected Member Functions

 check_slot ($slot)
 Check whether $number actually corresponds to a question attempt that is part of this usage. More...
 
 get_slots_in_request ($postdata=null)
 Get the list of slot numbers that should be processed as part of processing the current request. More...
 

Protected Attributes

context $context
 the context this usage belongs to.
 
integer string $id = null
 the id for this usage. More...
 
question_usage_observer $observer
 that tracks changes to this usage.
 
string $owningcomponent
 plugin name of the plugin this usage belongs to.
 
string $preferredbehaviour = null
 name of an archetypal behaviour, that should be used by questions in this usage if possible.
 
array $questionattempts = array()
 that make up this usage.
 

Detailed Description

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 {@question_attempt} 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 {@question_attempt} 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.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

question_usage_by_activity::__construct (   $component,
  $context 
)

Create a new instance.

Normally, calling code should use } or * question_engine::load_questions_usage_by_activity() rather than calling this constructor directly.

Parameters
string$componentthe plugin creating this attempt. For example mod_quiz.
object$contextthe context this usage belongs to.

Member Function Documentation

◆ add_question()

question_usage_by_activity::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.

Parameters
question_definition$questionthe question to add.
number$maxmarkthe maximum this question will be marked out of in this attempt (optional). If not given, $question->defaultmark is used.
Return values
intthe number used to identify this question within this usage.

◆ add_question_in_place_of_other()

question_usage_by_activity::add_question_in_place_of_other (   $slot,
question_definition  $question,
  $maxmark = null 
)

Add another question to this usage, in the place of an existing slot.

The question_attempt that was in that slot is moved to the end at a new slot number, which is returned.

The added question is not started until you call start_question() on it.

Parameters
int$slotthe slot-number of the question to replace.
question_definition$questionthe question to add.
number$maxmarkthe maximum this question will be marked out of in this attempt (optional). If not given, the max mark from the $qa we are replacing is used.
Return values
intthe new slot number of the question that was displaced.

◆ can_question_finish_during_attempt()

question_usage_by_activity::can_question_finish_during_attempt (   $slot)

Whether this attempt at a given question could be completed just by the student interacting with the question, before finish_question() is called.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
booleanwhether the attempt at the given question can finish naturally.

◆ check_file_access()

question_usage_by_activity::check_file_access (   $slot,
  $options,
  $component,
  $filearea,
  $args,
  $forcedownload 
)

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

Parameters
int$slotthe number used to identify this question within this usage.
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.
Return values
booltrue if the user can access this file.

◆ check_slot()

question_usage_by_activity::check_slot (   $slot)
protected

Check whether $number actually corresponds to a question attempt that is part of this usage.

Throws an exception if not.

Parameters
int$slota number allegedly identifying a question within this usage.

◆ extract_responses()

question_usage_by_activity::extract_responses (   $slot,
  $postdata = null 
)

Get the submitted data from the current request that belongs to this particular question.

Parameters
int$slotthe number used to identify this question within this usage.
array | null$postdataoptional, only intended for testing. Use this data instead of the data from $_POST.
Return values
arraysubmitted data specific to this question.

◆ finish_all_questions()

question_usage_by_activity::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.

Parameters
int | null$timestamp(optional) the timestamp to consider 'now'.

◆ finish_question()

question_usage_by_activity::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.

Parameters
int$slotthe number used to identify this question within this usage.
int | null$timestamp(optional) the timestamp to consider 'now'.

◆ get_attempt_iterator()

question_usage_by_activity::get_attempt_iterator ( )

Note the part of the } 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.

Return values
question_attempt_iteratorfor iterating over all the questions being attempted. as part of this usage.

◆ get_correct_response()

question_usage_by_activity::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.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
arraythat constitutes a correct response to this question.

◆ get_field_prefix()

question_usage_by_activity::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.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
stringreturn the prefix that is pre-pended to field names in the HTML that is output.

◆ get_first_question_number()

question_usage_by_activity::get_first_question_number ( )
Return values
intthe identifying number of the first question that was added to this usage.

◆ get_id()

question_usage_by_activity::get_id ( )
Return values
int|stringIf this usage came from the database, then the id from the question_usages table is returned. Otherwise a random string is returned.

◆ get_num_variants()

question_usage_by_activity::get_num_variants (   $slot)

Get the number of variants available for the question in this slot.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
intthe number of variants available.

◆ get_observer()

question_usage_by_activity::get_observer ( )
Return values
question_usage_observerthat is tracking changes made to this usage.

◆ get_owning_component()

question_usage_by_activity::get_owning_component ( )
Return values
stringthe name of the plugin that owns this attempt.

◆ get_owning_context()

question_usage_by_activity::get_owning_context ( )
Return values
contextthe context this usage belongs to.

◆ get_preferred_behaviour()

question_usage_by_activity::get_preferred_behaviour ( )
Return values
stringthe name of the preferred behaviour.

◆ get_question()

question_usage_by_activity::get_question (   $slot)

Get the question_definition for a question in this attempt.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
question_definitionthe requested question object.

◆ get_question_action_time()

question_usage_by_activity::get_question_action_time (   $slot)

Get the time of the most recent action performed on a question.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
inttimestamp.

◆ get_question_attempt()

question_usage_by_activity::get_question_attempt (   $slot)

Note the part of the } 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.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
question_attemptthe corresponding question_attempt object.

◆ get_question_attempt_metadata()

question_usage_by_activity::get_question_attempt_metadata (   $slot,
  $name 
)

Return one of the bits of metadata for a particular question attempt in this usage.

Parameters
int$slotthe slot number of the question of inereest.
string$namethe name of the metadata variable to return.
Return values
stringthe value of that metadata variable.

◆ get_question_fraction()

question_usage_by_activity::get_question_fraction (   $slot)

Get the current fraction awarded for the attempt at a question.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
number|nullThe current fraction for this question, or null if one has not been assigned yet.

◆ get_question_mark()

question_usage_by_activity::get_question_mark (   $slot)

Get the current mark awarded for the attempt at a question.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
number|nullThe current mark for this question, or null if one has not been assigned yet.

◆ get_question_max_mark()

question_usage_by_activity::get_question_max_mark (   $slot)

Get the maximum mark possible for the attempt at a question.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
numberthe available marks for this question.

◆ get_question_state()

question_usage_by_activity::get_question_state (   $slot)

Get the current state of the attempt at a question.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
question_state.

◆ get_question_state_class()

question_usage_by_activity::get_question_state_class (   $slot,
  $showcorrectness 
)
Parameters
int$slotthe number used to identify this question within this usage.
bool$showcorrectnessWhether right/partial/wrong states should be distinguised.
Return values
stringa CSS class name for the current state.

◆ get_question_state_string()

question_usage_by_activity::get_question_state_string (   $slot,
  $showcorrectness 
)
Parameters
int$slotthe number used to identify this question within this usage.
bool$showcorrectnessWhether right/partial/wrong states should be distinguised.
Return values
stringA brief textual description of the current state.

◆ get_question_summary()

question_usage_by_activity::get_question_summary (   $slot)

Get a simple textual summary of the question that was asked.

Parameters
int$slotthe slot number of the question to summarise.
Return values
stringthe question summary.

◆ get_response_summary()

question_usage_by_activity::get_response_summary (   $slot)

Get a simple textual summary of response given.

Parameters
int$slotthe slot number of the question to get the response summary for.
Return values
stringthe response summary.

◆ get_right_answer_summary()

question_usage_by_activity::get_right_answer_summary (   $slot)

Get a simple textual summary of the correct response to a question.

Parameters
int$slotthe slot number of the question to get the right answer summary for.
Return values
stringthe right answer summary.

◆ get_slots()

question_usage_by_activity::get_slots ( )
Return values
arrayall the identifying numbers of all the questions in this usage.

◆ get_slots_in_request()

question_usage_by_activity::get_slots_in_request (   $postdata = null)
protected

Get the list of slot numbers that should be processed as part of processing the current request.

Parameters
array$postdataoptional, only intended for testing. Use this data instead of the data from $_POST.
Return values
arrayof slot numbers.

◆ get_summary_information()

question_usage_by_activity::get_summary_information ( question_display_options  $options)

Get summary information about this usage.

Some behaviours may be able to provide interesting summary information about the attempt as a whole, and this method provides access to that data. To see how this works, try setting a quiz to one of the CBM behaviours, and then look at the extra information displayed at the top of the quiz review page once you have sumitted an attempt.

In the return value, the array keys are identifiers of the form qbehaviour_behaviourname_meaningfullkey. For qbehaviour_deferredcbm_highsummary. The values are arrays with two items, title and content. Each of these will be either a string, or a renderable.

Parameters
question_display_options$optionsdisplay options to apply.
Return values
arrayas described above.

◆ get_total_mark()

question_usage_by_activity::get_total_mark ( )

Get the total mark for all questions in this usage.

Return values
numberThe sum of marks of all the question_attempts in this usage.

◆ get_variant()

question_usage_by_activity::get_variant (   $slot)

Get the variant of the question being used in a given slot.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
intthe variant of this question that is being used.

◆ is_autosave_required()

question_usage_by_activity::is_autosave_required (   $slot,
  $postdata = null 
)

Check, based on the sequence number, whether this auto-save is still required.

Parameters
int$slotthe number used to identify this question within this usage.
array | null$postdatathe submitted data that constitutes the action.
Return values
booltrue if the check variable is present and correct, otherwise false.

◆ load_from_records()

static question_usage_by_activity::load_from_records (   $records,
  $qubaid 
)
static

Create a question_usage_by_activity from records loaded from the database.

For internal use only.

Parameters
Iterator$recordsRaw records loaded from the database.
int$qubaidThe id of the question usage we are loading.
Return values
question_usage_by_activityThe newly constructed usage.

◆ manual_grade()

question_usage_by_activity::manual_grade (   $slot,
  $comment,
  $mark,
  $commentformat = null 
)

Perform a manual grading action on a question attempt.

Parameters
int$slotthe number used to identify this question within this usage.
string$commentthe comment being added to the question attempt.
number$markthe mark that is being assigned. Can be null to just add a comment.
int$commentformatone of the FORMAT_... constants. The format of $comment.

◆ prepare_simulated_post_data()

question_usage_by_activity::prepare_simulated_post_data (   $simulatedresponses)

Transform an array of response data for slots to an array of post data as you would get from quiz attempt form.

Parameters
$simulatedresponsesarray keys are slot nos => contains arrays representing student responses which will be passed to question_definition::prepare_simulated_post_data method and then have the appropriate prefix added.
Return values
arraysimulated post data

◆ process_action()

question_usage_by_activity::process_action (   $slot,
  $submitteddata,
  $timestamp = null 
)

Process a specific action on a specific question.

Parameters
int$slotthe number used to identify this question within this usage.
array$submitteddatathe submitted data that constitutes the action.
int | null$timestamp(optional) the timestamp to consider 'now'.

◆ process_all_actions()

question_usage_by_activity::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().

Parameters
int$timestampoptional, use this timestamp as 'now'.
array$postdataoptional, only intended for testing. Use this data instead of the data from $_POST.

◆ process_all_autosaves()

question_usage_by_activity::process_all_autosaves (   $timestamp = null,
  $postdata = null 
)

Process all the question autosave data 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().

Parameters
int$timestampoptional, use this timestamp as 'now'.
array$postdataoptional, only intended for testing. Use this data instead of the data from $_POST.

◆ process_autosave()

question_usage_by_activity::process_autosave (   $slot,
  $submitteddata,
  $timestamp = null 
)

Process an autosave action on a specific question.

Parameters
int$slotthe number used to identify this question within this usage.
array$submitteddatathe submitted data that constitutes the action.
int | null$timestamp(optional) the timestamp to consider 'now'.

◆ question_count()

question_usage_by_activity::question_count ( )
Return values
intthe number of questions that are currently in this usage.

◆ regrade_all_questions()

question_usage_by_activity::regrade_all_questions (   $finished = false)

Regrade all the questions in this usage (without changing their max mark).

Parameters
bool$finishedwhether each question should be forced to be finished after the regrade, or whether it may still be in progress (default false).

◆ regrade_question()

question_usage_by_activity::regrade_question (   $slot,
  $finished = false,
  $newmaxmark = null 
)

Regrade a question in this usage.

This replays the sequence of submitted actions to recompute the outcomes.

Parameters
int$slotthe number used to identify this question within this usage.
bool$finishedwhether 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.

◆ render_question()

question_usage_by_activity::render_question (   $slot,
  $options,
  $number = null 
)

Get the }, in collaboration with appropriate * qbehaviour_renderer} and qtype_renderer subclasses, to generate the HTML to display this question.

Parameters
int$slotthe number used to identify this question within this usage.
question_display_options$optionscontrols how the question is rendered.
string | null$numberThe question number to display. 'i' is a special value that gets displayed as Information. Null means no number is displayed.
Return values
stringHTML fragment representing the question.

◆ render_question_at_step()

question_usage_by_activity::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.

Parameters
int$slotthe number used to identify this question within this usage.
int$seqthe seq number of the past state to display.
question_display_options$optionscontrols how the question is rendered.
string | null$numberThe question number to display. 'i' is a special value that gets displayed as Information. Null means no number is displayed.
Return values
stringHTML fragment representing the question.

◆ render_question_head_html()

question_usage_by_activity::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.

Parameters
int$slotthe number used to identify this question within this usage.
Return values
stringHTML fragment.

◆ replace_loaded_question_attempt_info()

question_usage_by_activity::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.

Parameters
int$slotthe slot number of the question to replace.
question_attempt$qathe question attempt to put in that place.

◆ set_id_from_database()

question_usage_by_activity::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.

Parameters
int$idthe newly determined id for this usage.

◆ set_max_mark()

question_usage_by_activity::set_max_mark (   $slot,
  $maxmark 
)

Change the max mark for this question_attempt.

Parameters
int$slotthe slot number of the question of inerest.
float$maxmarkthe new max mark.

◆ set_observer()

question_usage_by_activity::set_observer (   $observer)

You should almost certainly not call this method from your code.

It is for internal use only.

Parameters
question_usage_observerthat should be used to tracking changes made to this usage.

◆ set_preferred_behaviour()

question_usage_by_activity::set_preferred_behaviour (   $behaviour)
Parameters
string$behaviourthe name of an archetypal behaviour, that should be used by questions in this usage if possible.

◆ set_question_attempt_metadata()

question_usage_by_activity::set_question_attempt_metadata (   $slot,
  $name,
  $value 
)

Set some metadata for a particular question attempt in this usage.

Parameters
int$slotthe slot number of the question of inerest.
string$namethe name of the metadata variable to return.
string$valuethe value to set that metadata variable to.

◆ start_all_questions()

question_usage_by_activity::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.

Parameters
question_variant_selection_strategyhow to pick which variant of each question to use.
int$timestampoptional, the timstamp to record for this action. Defaults to now.
int$useridoptional, the user to attribute this action to. Defaults to the current user.

◆ start_question()

question_usage_by_activity::start_question (   $slot,
  $variant = null,
  $timenow = null 
)

Start the attempt at a question that has been added to this usage.

Parameters
int$slotthe number used to identify this question within this usage.
int$variantwhich 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.
int | null$timenowoptional, the timstamp to record for this action. Defaults to now.

◆ start_question_based_on()

question_usage_by_activity::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.

Parameters
int$slotthe number used to identify this question within this usage.
question_attempt$oldqaa previous attempt at this quetsion that defines the starting point.

◆ update_question_flags()

question_usage_by_activity::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.

Parameters
array | null$postdataoptional, only intended for testing. Use this data instead of the data from $_POST.

◆ validate_sequence_number()

question_usage_by_activity::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.

Parameters
int$slotthe number used to identify this question within this usage.
array | null$postdata(optional) data to use in place of $_POST.
Return values
booltrue if the check variable is present and correct. False if it is missing. (Throws an exception if the check fails.)

Member Data Documentation

◆ $id

integer string question_usage_by_activity::$id = null
protected

the id for this usage.

If this usage was loaded from the database, then this is the database id. Otherwise a unique random string is used.


The documentation for this class was generated from the following file: