Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
mod_quiz\quiz_attempt Class Reference

Public Member Functions

 __construct ($attempt, $quiz, $cm, $course, $loadquestions=true)
 Constructor assuming we already have the necessary data loaded.
 
 all_question_attempts_originally_in_slot ($slot)
 Get all the question_attempt objects that have ever appeared in a given slot.
 
 attempt_page_title (int $page)
 Generates the title of the attempt page.
 
 attempt_url ($slot=null, $page=-1, $thispage=-1)
 Get the URL of a particular page within this attempt.
 
 can_navigate_to ($slot)
 Checks whether a user may navigate to a particular slot.
 
 can_question_be_redone_now ($slot)
 Is it possible for this question to be re-started within this attempt?
 
 cannot_review_message ($short=false)
 If $reviewoptions->attempt is false, meaning that students can't review this attempt at the moment, return an appropriate string explaining why.
 
 check_file_access ($slot, $reviewing, $contextid, $component, $filearea, $args, $forcedownload)
 Check whether access should be allowed to a particular file.
 
 check_page_access (int $page, bool $allownext=true)
 Check a page read access to see if is an out of sequence access.
 
 check_review_capability ()
 Check the appropriate capability to see whether this user may review their own attempt.
 
 fire_attempt_autosaved_event ()
 Trigger the attempt_autosaved event.
 
 fire_attempt_manual_grading_completed_event ()
 Trigger the attempt manual grading completed event.
 
 fire_attempt_question_restarted_event (int $slot, int $newquestionid)
 Trigger the attempt_question_restarted event.
 
 fire_attempt_reviewed_event ()
 Trigger the attempt_reviewed event.
 
 fire_attempt_summary_viewed_event ()
 Trigger the attempt_summary_viewed event.
 
 fire_attempt_updated_event ()
 Trigger the attempt_updated event.
 
 fire_attempt_viewed_event ()
 Trigger the attempt_viewed event.
 
 force_page_number_into_range ($page)
 If the given page number is out of range (before the first page, or after the last page, change it to be within range).
 
 get_access_manager ($timenow)
 Get the access_manager for this quiz attempt.
 
 get_active_slots ($page='all')
 Return the list of slot numbers for either a given page of the quiz, or for the whole quiz.
 
 get_additional_summary_data (question_display_options $options)
 Get extra summary information about this attempt.
 
 get_attempt ()
 Get the raw quiz attempt object.
 
 get_attempt_number ()
 Get the attempt number.
 
 get_attempt_state ()
 Get where we are time-wise in relation to this attempt and the quiz settings.
 
 get_attemptid ()
 Get the id of this attempt.
 
 get_cm ()
 Get the course_module for this quiz.
 
 get_cmid ()
 Get the course-module id.
 
 get_context ()
 Get the quiz context.
 
 get_course ()
 Get the course settings object.
 
 get_courseid ()
 Git the id of the course this quiz belongs to.
 
 get_currentpage ()
 Get the current page of the attempt.
 
 get_default_show_all ($script)
 By default, should this script show all questions on one page for this attempt?
 
 get_display_options ($reviewing)
 Wrapper that the correct display_options for this quiz at the moment.
 
 get_display_options_with_edit_link ($reviewing, $slot, $thispageurl)
 Wrapper that the correct display_options for this quiz at the moment.
 
 get_due_date ()
 If the attempt is in an applicable state, work out the time by which the student should next do something.
 
 get_grade_item_totals ()
 Compute the grade and maximum grade for each grade item, for this attempt.
 
 get_heading_before_slot ($slot)
 If the section heading, if any, that should come just before this slot.
 
 get_html_head_contributions ($page='all', $showall=false)
 Initialise the JS etc.
 
 get_navigation_method ()
 Get the quiz navigation method.
 
 get_navigation_panel (renderer $output, $panelclass, $page, $showall=false)
 Get the navigation panel object for this attempt.
 
 get_num_attempts_allowed ()
 Get the number of attempts the user is allowed at this quiz.
 
 get_num_pages ()
 Get the number of quizzes in the quiz attempt.
 
 get_number_of_unanswered_questions ()
 Get the total number of unanswered questions in the attempt.
 
 get_original_slot ($slot)
 Given a slot in this attempt, which may or not be a redone question, return the original slot.
 
 get_overall_feedback ($grade)
 Get the overall feedback corresponding to a particular mark.
 
 get_question_action_time ($slot)
 Get the time of the most recent action performed on a question.
 
 get_question_attempt ($slot)
 Get the question_attempt object for a particular question in this attempt.
 
 get_question_html_head_contributions ($slot)
 Initialise the JS etc.
 
 get_question_mark ($slot)
 Return the grade obtained on a particular question.
 
 get_question_name ($slot)
 Return the grade obtained on a particular question, if the user is permitted to see it.
 
 get_question_number ($slot)
 Get the displayed question number for a slot.
 
 get_question_page ($slot)
 Return the page of the quiz where this question appears.
 
 get_question_state ($slot)
 Return the {.
 
 get_question_state_class ($slot, $showcorrectness)
 Return the grade obtained on a particular question, if the user is permitted to see it.
 
 get_question_status ($slot, $showcorrectness)
 Return the grade obtained on a particular question, if the user is permitted to see it.
 
 get_question_type_name ($slot)
 Return the question type name for a given slot within the current attempt.
 
 get_question_usage ()
 Helper method for unit tests.
 
 get_quiz ()
 Get the raw quiz settings object.
 
 get_quiz_name ()
 Get the name of this quiz.
 
 get_quizid ()
 Get the quiz id.
 
 get_quizobj ()
 Get the {.
 
 get_slots ($page='all')
 Return the list of slot numbers for either a given page of the quiz, or for the whole quiz.
 
 get_state ()
 Get the state of this attempt.
 
 get_submitted_date ()
 Get the time when this attempt was submitted.
 
 get_sum_marks ()
 Get the total number of marks that the user had scored on all the questions.
 
 get_time_left_display ($timenow)
 Get the time remaining for an in-progress attempt, if the time is short enough that it would be worth showing a timer.
 
 get_uniqueid ()
 Get the question-usage id corresponding to this quiz attempt.
 
 get_userid ()
 Get the id of the user this attempt belongs to.
 
 handle_if_time_expired ($timestamp, $studentisonline)
 Check this attempt, to see if there are any state transitions that should happen automatically.
 
 has_capability ($capability, $userid=null, $doanything=true)
 Wrapper round the has_capability function that automatically passes in the quiz context.
 
 has_response_to_at_least_one_graded_question ()
 Has the student, in this attempt, engaged with the quiz in a non-trivial way?
 
 is_blocked_by_previous_question ($slot)
 Checks whether the question in this slot requires the previous question to have been completed.
 
 is_finished ()
 Has this attempt been finished?
 
 is_last_page ($page)
 Is a particular page the last one in the quiz?
 
 is_own_attempt ()
 Does this attempt belong to the current user?
 
 is_own_preview ()
 Is this attempt is a preview belonging to the current user.
 
 is_preview ()
 Is this attempt a preview?
 
 is_preview_user ()
 Is the current user is someone who previews the quiz, rather than attempting it?
 
 is_question_flagged ($slot)
 Is a particular question in this attempt a real question, or something like a description.
 
 is_real_question ($slot)
 Is a particular question in this attempt a real question, or something like a description.
 
 is_review_allowed ()
 Is the current user allowed to review this attempt.
 
 links_to_other_attempts (moodle_url $url)
 Return an array of variant URLs to other attempts at this quiz.
 
 links_to_other_redos ($slot, moodle_url $baseurl)
 Return an array of variant URLs to other redos of the question in a particular slot.
 
 load_questions ()
 This method can be called later if the object was constructed with $loadquestions = false.
 
 preload_all_attempt_step_users ()
 Preload all attempt step users to show in Response history.
 
 process_abandon ($timestamp, $studentisonline)
 Mark this attempt as abandoned.
 
 process_attempt ($timenow, $finishattempt, $timeup, $thispage)
 Process responses during an attempt at a quiz.
 
 process_auto_save ($timestamp)
 Process all the autosaved data that was part of the current request.
 
 process_finish ($timestamp, $processsubmitted, $timefinish=null, $studentisonline=false)
 Submit the attempt.
 
 process_going_overdue ($timestamp, $studentisonline)
 Mark this attempt as now overdue.
 
 process_redo_question ($slot, $timestamp)
 Replace a question in an attempt with a new attempt at the same question.
 
 process_reopen_abandoned ($timestamp)
 This method takes an attempt in the 'Never submitted' state, and reopens it.
 
 process_submitted_actions ($timestamp, $becomingoverdue=false, $simulatedresponses=null)
 Process all the actions that were submitted as part of the current request.
 
 processattempt_url ()
 Get the URL to which the attempt data should be submitted.
 
 render_question ($slot, $reviewing, renderer $renderer, $thispageurl=null)
 Generate the HTML that displays the question in its current state, with the appropriate display options.
 
 render_question_at_step ($slot, $seq, $reviewing, renderer $renderer, $thispageurl=null)
 Like {.
 
 render_question_for_commenting ($slot)
 Wrapper round print_question from lib/questionlib.php.
 
 require_capability ($capability, $userid=null, $doanything=true)
 Wrapper round the require_capability function that automatically passes in the quiz context.
 
 requires_manual_grading ()
 Do any questions in this attempt need to be graded manually?
 
 restart_preview_button ()
 Print the HTML for the start new preview button, if the current user is allowed to see one.
 
 review_page_title (int $page, bool $showall=false)
 Generates the title of the review page.
 
 review_url ($slot=null, $page=-1, $showall=null, $thispage=-1)
 Get the URL of a particular page in the review of this attempt.
 
 save_question_flags ()
 Update the flagged state for all question_attempts in this usage, if their flagged state was changed in the request.
 
 set_currentpage ($page)
 Update attempt page.
 
 set_grade_item_totals (array $grades)
 Set the total grade for each grade_item for this quiz.
 
 set_offline_modified_time ($time)
 Update the timemodifiedoffline attempt field.
 
 start_attempt_url ($slot=null, $page=-1)
 Get the URL to start or continue an attempt.
 
 summary_page_title ()
 Generates the title of the summary page.
 
 summary_url ()
 Get the URL of the summary page of this attempt.
 
 update_questions_to_new_version_if_changed ()
 If any questions in this attempt have changed, update the attempts.
 
 update_timecheckstate ($time)
 Update this attempt timecheckstate if necessary.
 
 view_url ()
 Get the URL of this quiz's view.php page.
 

Static Public Member Functions

static create ($attemptid)
 Static function to create a new quiz_attempt object given an attemptid.
 
static create_from_usage_id ($usageid)
 Static function to create a new quiz_attempt object given a usage id.
 
static state_name ($state)
 Get a human-readable name for one of the quiz attempt states.
 

Public Attributes

string const ABANDONED = 'abandoned'
 to identify the abandoned state.
 
string const FINISHED = 'finished'
 to identify the finished state.
 
int const IMMEDIATELY_AFTER_PERIOD = 2 * MINSECS
 amount of time considered 'immedately after the attempt', in seconds.
 
string const IN_PROGRESS = 'inprogress'
 to identify the in progress state.
 
int const MAX_SLOTS_FOR_DEFAULT_REVIEW_SHOW_ALL = 50
 maximum number of slots in the quiz for the review page to default to show all.
 
string const OVERDUE = 'overdue'
 to identify the overdue state.
 

Protected Member Functions

 determine_layout ()
 Parse attempt->layout to populate the other arrays that represent the layout.
 
 fire_state_transition_event ($eventclass, $timestamp, $studentisonline)
 Fire a state transition event.
 
 link_sections_and_slots ()
 Let each slot know which section it is part of.
 
 make_blocked_question_placeholder ($slot)
 Create a fake question to be displayed in place of a question that is blocked until the previous question has been answered.
 
 number_questions ()
 Work out the number to display for each question/slot.
 
 page_and_question_url ($script, $slot, $page, $showall, $thispage)
 Get a URL for a particular question on a particular page of the quiz.
 
 recompute_final_grade ()
 Needs to be called after this attempt's grade is changed, to update the overall quiz grade.
 
 render_question_helper ($slot, $reviewing, $thispageurl, renderer $renderer, $seq)
 Helper used by {.
 

Static Protected Member Functions

static create_helper ($conditions)
 Used by {create()} and {create_from_usage_id()}.
 

Protected Attributes

stdClass $attempt
 the quiz_attempts row.
 
grade_calculator grade_calculator $gradecalculator
 instance for this quiz.
 
grade_out_of[] null array $gradeitemmarks = null
 can be used to store the total grade for each section.
 
array $pagelayout
 page no => array of slot numbers on the page in order.
 
question_usage_by_activity null question_usage_by_activity $quba = null
 the question usage for this quiz attempt.
 
array $questionnumbers
 slot => displayed question number for this slot.
 
array $questionpages
 slot => page number for this slot.
 
quiz_settings $quizobj
 object containing the quiz settings.
 
display_options $reviewoptions = null
 cache for the appropriate review options.
 
array $sections
 of quiz_sections rows, with a ->lastslot field added.
 
array $slots
 of slot information.
 

Constructor & Destructor Documentation

◆ __construct()

mod_quiz\quiz_attempt::__construct ( $attempt,
$quiz,
$cm,
$course,
$loadquestions = true )

Constructor assuming we already have the necessary data loaded.

Parameters
stdClass$attemptthe row of the quiz_attempts table.
stdClass$quizthe quiz object for this attempt and user.
cm_info$cmthe course_module object for this quiz.
stdClass$coursethe row from the course table for the course we belong to.
bool$loadquestions(optional) if true, the default, load all the details of the state of each question. Else just set up the basic details of the attempt.

Member Function Documentation

◆ all_question_attempts_originally_in_slot()

mod_quiz\quiz_attempt::all_question_attempts_originally_in_slot ( $slot)

Get all the question_attempt objects that have ever appeared in a given slot.

This relates to the 'Try another question like this one' feature.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
question_attempt[]the attempts.

◆ attempt_page_title()

mod_quiz\quiz_attempt::attempt_page_title ( int $page)

Generates the title of the attempt page.

Parameters
int$pagethe page number (starting with 0) in the attempt.
Return values
stringattempt page title.

◆ attempt_url()

mod_quiz\quiz_attempt::attempt_url ( $slot = null,
$page = -1,
$thispage = -1 )

Get the URL of a particular page within this attempt.

Parameters
int | null$slotif specified, the slot number of a specific question to link to.
int$pageif specified, a particular page to link to. If not given deduced from $slot, or goes to the first page.
int$thispageif not -1, the current page. Will cause links to other things on this page to be output as only a fragment.
Return values
moodle_urlthe URL to continue this attempt.

◆ can_navigate_to()

mod_quiz\quiz_attempt::can_navigate_to ( $slot)

Checks whether a user may navigate to a particular slot.

Parameters
int$slotthe target slot (currently does not affect the answer).
Return values
booltrue if the navigation should be allowed.

◆ can_question_be_redone_now()

mod_quiz\quiz_attempt::can_question_be_redone_now ( $slot)

Is it possible for this question to be re-started within this attempt?

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
boolwhether the student should be given the option to restart this question now.

◆ cannot_review_message()

mod_quiz\quiz_attempt::cannot_review_message ( $short = false)

If $reviewoptions->attempt is false, meaning that students can't review this attempt at the moment, return an appropriate string explaining why.

Parameters
bool$shortif true, return a shorter string.
Return values
stringan appropriate message.

◆ check_file_access()

mod_quiz\quiz_attempt::check_file_access ( $slot,
$reviewing,
$contextid,
$component,
$filearea,
$args,
$forcedownload )

Check whether access should be allowed to a particular file.

Parameters
int$slotthe slot of a question in this quiz attempt.
bool$reviewingis the being printed on an attempt or a review page.
int$contextidthe file context id from the request.
string$componentthe file component from the request.
string$fileareathe file area from the request.
array$argsextra part components from the request.
bool$forcedownloadwhether to force download.
Return values
booltrue if the file can be accessed.

◆ check_page_access()

mod_quiz\quiz_attempt::check_page_access ( int $page,
bool $allownext = true )

Check a page read access to see if is an out of sequence access.

If allownext is set then we also check whether access to the page after the current one should be permitted.

Parameters
int$pagepage number.
bool$allownextin case of a sequential navigation, can we go to next page ?
Return values
booleanfalse is an out of sequence access, true otherwise.
Since
Moodle 3.1

◆ check_review_capability()

mod_quiz\quiz_attempt::check_review_capability ( )

Check the appropriate capability to see whether this user may review their own attempt.

If not, prints an error.

◆ create()

static mod_quiz\quiz_attempt::create ( $attemptid)
static

Static function to create a new quiz_attempt object given an attemptid.

Parameters
int$attemptidthe attempt id.
Return values
quiz_attemptthe new quiz_attempt object

◆ create_from_usage_id()

static mod_quiz\quiz_attempt::create_from_usage_id ( $usageid)
static

Static function to create a new quiz_attempt object given a usage id.

Parameters
int$usageidthe attempt usage id.
Return values
quiz_attemptthe new quiz_attempt object

◆ create_helper()

static mod_quiz\quiz_attempt::create_helper ( $conditions)
staticprotected

Used by {create()} and {create_from_usage_id()}.

Parameters
array$conditionspassed to $DB->get_record('quiz_attempts', $conditions).
Return values
quiz_attemptthe desired instance of this class.

◆ fire_attempt_autosaved_event()

mod_quiz\quiz_attempt::fire_attempt_autosaved_event ( )

Trigger the attempt_autosaved event.

Return values
void

◆ fire_attempt_question_restarted_event()

mod_quiz\quiz_attempt::fire_attempt_question_restarted_event ( int $slot,
int $newquestionid )

Trigger the attempt_question_restarted event.

Parameters
int$slotSlot number
int$newquestionidNew question id.
Return values
void

◆ fire_attempt_reviewed_event()

mod_quiz\quiz_attempt::fire_attempt_reviewed_event ( )

Trigger the attempt_reviewed event.

Since
Moodle 3.1

◆ fire_attempt_summary_viewed_event()

mod_quiz\quiz_attempt::fire_attempt_summary_viewed_event ( )

Trigger the attempt_summary_viewed event.

Since
Moodle 3.1

◆ fire_attempt_updated_event()

mod_quiz\quiz_attempt::fire_attempt_updated_event ( )

Trigger the attempt_updated event.

Return values
void

◆ fire_attempt_viewed_event()

mod_quiz\quiz_attempt::fire_attempt_viewed_event ( )

Trigger the attempt_viewed event.

Since
Moodle 3.1

◆ fire_state_transition_event()

mod_quiz\quiz_attempt::fire_state_transition_event ( $eventclass,
$timestamp,
$studentisonline )
protected

Fire a state transition event.

Parameters
string$eventclassthe event class name.
int$timestampthe timestamp to include in the event.
bool$studentisonlineis the student currently interacting with Moodle?

◆ force_page_number_into_range()

mod_quiz\quiz_attempt::force_page_number_into_range ( $page)

If the given page number is out of range (before the first page, or after the last page, change it to be within range).

Parameters
int$pagethe requested page number.
Return values
inta safe page number to use.

◆ get_access_manager()

mod_quiz\quiz_attempt::get_access_manager ( $timenow)

Get the access_manager for this quiz attempt.

Parameters
int$timenowthe current time as a unix timestamp.
Return values
access_managerand instance of the access_manager class for this quiz at this time.

◆ get_active_slots()

mod_quiz\quiz_attempt::get_active_slots ( $page = 'all')

Return the list of slot numbers for either a given page of the quiz, or for the whole quiz.

Parameters
mixed$pagestring 'all' or integer page number.
Return values
arraythe requested list of slot numbers.

◆ get_additional_summary_data()

mod_quiz\quiz_attempt::get_additional_summary_data ( question_display_options $options)

Get extra summary information about this attempt.

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

If this method is called before load_questions() is called, then an empty array is returned.

Parameters
question_display_options$optionsthe display options for this quiz attempt at this time.
Return values
arrayas described above.

◆ get_attempt()

mod_quiz\quiz_attempt::get_attempt ( )

Get the raw quiz attempt object.

Return values
stdClassthe row from the quiz_attempts table.

◆ get_attempt_number()

mod_quiz\quiz_attempt::get_attempt_number ( )

Get the attempt number.

Return values
intthe number of this attempt (is it this user's first, second, ... attempt).

◆ get_attempt_state()

mod_quiz\quiz_attempt::get_attempt_state ( )

Get where we are time-wise in relation to this attempt and the quiz settings.

Return values
intone of {
See also
display_options\DURING}, {
display_options\IMMEDIATELY_AFTER}, {
display_options\LATER_WHILE_OPEN} or {
display_options\AFTER_CLOSE}.

◆ get_attemptid()

mod_quiz\quiz_attempt::get_attemptid ( )

Get the id of this attempt.

Return values
intthe attempt id.

◆ get_cm()

mod_quiz\quiz_attempt::get_cm ( )

Get the course_module for this quiz.

Return values
cm_infothe course_module object.

◆ get_cmid()

mod_quiz\quiz_attempt::get_cmid ( )

Get the course-module id.

Return values
intthe course_module id.

◆ get_context()

mod_quiz\quiz_attempt::get_context ( )

Get the quiz context.

Return values
context_modulethe context of the quiz this attempt belongs to.

◆ get_course()

mod_quiz\quiz_attempt::get_course ( )

Get the course settings object.

Return values
stdClassthe course settings object.

◆ get_courseid()

mod_quiz\quiz_attempt::get_courseid ( )

Git the id of the course this quiz belongs to.

Return values
intthe course id.

◆ get_currentpage()

mod_quiz\quiz_attempt::get_currentpage ( )

Get the current page of the attempt.

Return values
intpage number.

◆ get_default_show_all()

mod_quiz\quiz_attempt::get_default_show_all ( $script)

By default, should this script show all questions on one page for this attempt?

Parameters
string$scriptthe script name, e.g. 'attempt', 'summary', 'review'.
Return values
boolwhether show all on one page should be on by default.

◆ get_display_options()

mod_quiz\quiz_attempt::get_display_options ( $reviewing)

Wrapper that the correct display_options for this quiz at the moment.

Parameters
bool$reviewingtrue for options when reviewing, false for when attempting.
Return values
question_display_optionsthe render options for this user on this attempt.

◆ get_display_options_with_edit_link()

mod_quiz\quiz_attempt::get_display_options_with_edit_link ( $reviewing,
$slot,
$thispageurl )

Wrapper that the correct display_options for this quiz at the moment.

Parameters
bool$reviewingtrue for review page, else attempt page.
int$slotwhich question is being displayed.
moodle_url$thispageurlto return to after the editing form is submitted or cancelled. If null, no edit link will be generated.
Return values
question_display_optionsthe render options for this user on this attempt, with extra info to generate an edit link, if applicable.

◆ get_due_date()

mod_quiz\quiz_attempt::get_due_date ( )

If the attempt is in an applicable state, work out the time by which the student should next do something.

Return values
inttimestamp by which the student needs to do something.

◆ get_grade_item_totals()

mod_quiz\quiz_attempt::get_grade_item_totals ( )

Compute the grade and maximum grade for each grade item, for this attempt.

Return values
grade_out_of[]the grade for each item where the total grade is not zero. ->name will be set to the grade item name. Must be output through {
See also
format_string()}.

◆ get_heading_before_slot()

mod_quiz\quiz_attempt::get_heading_before_slot ( $slot)

If the section heading, if any, that should come just before this slot.

Parameters
int$slotidentifies a particular question in this attempt.
Return values
string|nullthe required heading, or null if there is not one here.

◆ get_html_head_contributions()

mod_quiz\quiz_attempt::get_html_head_contributions ( $page = 'all',
$showall = false )

Initialise the JS etc.

required all the questions on a page.

Parameters
int | string$pagea page number, or 'all'.
bool$showallif true, forces page number to all.
Return values
stringHTML to output - mostly obsolete, will probably be an empty string.

◆ get_navigation_method()

mod_quiz\quiz_attempt::get_navigation_method ( )

Get the quiz navigation method.

Return values
intQUIZ_NAVMETHOD_FREE or QUIZ_NAVMETHOD_SEQ.

◆ get_navigation_panel()

mod_quiz\quiz_attempt::get_navigation_panel ( renderer $output,
$panelclass,
$page,
$showall = false )

Get the navigation panel object for this attempt.

Parameters
renderer$outputthe quiz renderer to use to output things.
string$panelclassThe type of panel, navigation_panel_attempt\class or navigation_panel_review\class
int$pagethe current page number.
bool$showallwhether we are showing the whole quiz on one page. (Used by review.php.)
Return values
block_contentsthe requested object.

◆ get_num_attempts_allowed()

mod_quiz\quiz_attempt::get_num_attempts_allowed ( )

Get the number of attempts the user is allowed at this quiz.

Return values
intthe number of attempts allowed at this quiz (0 = infinite).

◆ get_num_pages()

mod_quiz\quiz_attempt::get_num_pages ( )

Get the number of quizzes in the quiz attempt.

Return values
intnumber pages.

◆ get_number_of_unanswered_questions()

mod_quiz\quiz_attempt::get_number_of_unanswered_questions ( )

Get the total number of unanswered questions in the attempt.

Return values
int

◆ get_original_slot()

mod_quiz\quiz_attempt::get_original_slot ( $slot)

Given a slot in this attempt, which may or not be a redone question, return the original slot.

Parameters
int$slotidentifies a particular question in this attempt.
Return values
intthe slot where this question was originally.

◆ get_overall_feedback()

mod_quiz\quiz_attempt::get_overall_feedback ( $grade)

Get the overall feedback corresponding to a particular mark.

Parameters
number$gradea particular grade.
Return values
stringthe feedback.

◆ get_question_action_time()

mod_quiz\quiz_attempt::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()

mod_quiz\quiz_attempt::get_question_attempt ( $slot)

Get the question_attempt object for a particular question in this attempt.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
question_attemptthe requested question_attempt.

◆ get_question_html_head_contributions()

mod_quiz\quiz_attempt::get_question_html_head_contributions ( $slot)

Initialise the JS etc.

required by one question.

Parameters
int$slotthe question slot number.
Return values
stringHTML to output - but this is mostly obsolete. Will probably be an empty string.

◆ get_question_mark()

mod_quiz\quiz_attempt::get_question_mark ( $slot)

Return the grade obtained on a particular question.

You must previously have called load_question_states to load the state data about this question.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
stringthe formatted grade, to the number of decimal places specified by the quiz.

◆ get_question_name()

mod_quiz\quiz_attempt::get_question_name ( $slot)

Return the grade obtained on a particular question, if the user is permitted to see it.

You must previously have called load_question_states to load the state data about this question.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
stringthe name of the question. Must be output through format_string.

◆ get_question_number()

mod_quiz\quiz_attempt::get_question_number ( $slot)

Get the displayed question number for a slot.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
stringthe displayed question number for the question in this slot. For example '1', '2', '3' or 'i'.

◆ get_question_page()

mod_quiz\quiz_attempt::get_question_page ( $slot)

Return the page of the quiz where this question appears.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
intthe page of the quiz this question appears on.

◆ get_question_state()

mod_quiz\quiz_attempt::get_question_state ( $slot)

Return the {.

See also
question_state} that this question is in.
Parameters
int$slotthe number used to identify this question within this attempt.
Return values
question_statethe state this question is in.

◆ get_question_state_class()

mod_quiz\quiz_attempt::get_question_state_class ( $slot,
$showcorrectness )

Return the grade obtained on a particular question, if the user is permitted to see it.

You must previously have called load_question_states to load the state data about this question.

Parameters
int$slotthe number used to identify this question within this attempt.
bool$showcorrectnessWhether right/partial/wrong states should be distinguished.
Return values
stringclass name for this state.

◆ get_question_status()

mod_quiz\quiz_attempt::get_question_status ( $slot,
$showcorrectness )

Return the grade obtained on a particular question, if the user is permitted to see it.

You must previously have called load_question_states to load the state data about this question.

Parameters
int$slotthe number used to identify this question within this attempt.
bool$showcorrectnessWhether right/partial/wrong states should be distinguished.
Return values
stringthe formatted grade, to the number of decimal places specified by the quiz.

◆ get_question_type_name()

mod_quiz\quiz_attempt::get_question_type_name ( $slot)

Return the question type name for a given slot within the current attempt.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
stringthe question type name.

◆ get_question_usage()

mod_quiz\quiz_attempt::get_question_usage ( )

Helper method for unit tests.

Get the underlying question usage object.

Return values
question_usage_by_activitythe usage.

◆ get_quiz()

mod_quiz\quiz_attempt::get_quiz ( )

Get the raw quiz settings object.

Return values
stdClass

◆ get_quiz_name()

mod_quiz\quiz_attempt::get_quiz_name ( )

Get the name of this quiz.

Return values
stringQuiz name, directly from the database (format_string must be called before output).

◆ get_quizid()

mod_quiz\quiz_attempt::get_quizid ( )

Get the quiz id.

Return values
intthe quiz id.

◆ get_quizobj()

mod_quiz\quiz_attempt::get_quizobj ( )

Get the {.

See also
seb_quiz_settings} object for this quiz.
Return values
quiz_settings

◆ get_slots()

mod_quiz\quiz_attempt::get_slots ( $page = 'all')

Return the list of slot numbers for either a given page of the quiz, or for the whole quiz.

Parameters
mixed$pagestring 'all' or integer page number.
Return values
arraythe requested list of slot numbers.

◆ get_state()

mod_quiz\quiz_attempt::get_state ( )

Get the state of this attempt.

Return values
string{
See also
IN_PROGRESS}, {
FINISHED}, {
OVERDUE} or {
ABANDONED}.

◆ get_submitted_date()

mod_quiz\quiz_attempt::get_submitted_date ( )

Get the time when this attempt was submitted.

Return values
inttimestamp, or 0 if it has not been submitted yet.

◆ get_sum_marks()

mod_quiz\quiz_attempt::get_sum_marks ( )

Get the total number of marks that the user had scored on all the questions.

Return values
float

◆ get_time_left_display()

mod_quiz\quiz_attempt::get_time_left_display ( $timenow)

Get the time remaining for an in-progress attempt, if the time is short enough that it would be worth showing a timer.

Parameters
int$timenowthe time to consider as 'now'.
Return values
int|falsethe number of seconds remaining for this attempt. False if there is no limit.

◆ get_uniqueid()

mod_quiz\quiz_attempt::get_uniqueid ( )

Get the question-usage id corresponding to this quiz attempt.

Return values
intthe attempt unique id.

◆ get_userid()

mod_quiz\quiz_attempt::get_userid ( )

Get the id of the user this attempt belongs to.

Return values
intuser id.

◆ handle_if_time_expired()

mod_quiz\quiz_attempt::handle_if_time_expired ( $timestamp,
$studentisonline )

Check this attempt, to see if there are any state transitions that should happen automatically.

This function will update the attempt checkstatetime.

Parameters
int$timestampthe timestamp that should be stored as the modified
bool$studentisonlineis the student currently interacting with Moodle?

◆ has_capability()

mod_quiz\quiz_attempt::has_capability ( $capability,
$userid = null,
$doanything = true )

Wrapper round the has_capability function that automatically passes in the quiz context.

Parameters
string$capabilitythe name of the capability to check. For example mod/forum:view.
int | null$useridA user id. If null checks the permissions of the current user.
bool$doanythingIf false, ignore effect of admin role assignment.
Return values
booleantrue if the user has this capability, otherwise false.

◆ has_response_to_at_least_one_graded_question()

mod_quiz\quiz_attempt::has_response_to_at_least_one_graded_question ( )

Has the student, in this attempt, engaged with the quiz in a non-trivial way?

That is, is there any question worth a non-zero number of marks, where the student has made some response that we have saved?

Return values
booltrue if we have saved a response for at least one graded question.

◆ is_blocked_by_previous_question()

mod_quiz\quiz_attempt::is_blocked_by_previous_question ( $slot)

Checks whether the question in this slot requires the previous question to have been completed.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
boolwhether the previous question must have been completed before this one can be seen.

◆ is_finished()

mod_quiz\quiz_attempt::is_finished ( )

Has this attempt been finished?

States {

See also
FINISHED} and {
ABANDONED} are both considered finished in this state. Other states are not.
Return values
bool

◆ is_last_page()

mod_quiz\quiz_attempt::is_last_page ( $page)

Is a particular page the last one in the quiz?

Parameters
int$pagea page number
Return values
booltrue if that is the last page of the quiz.

◆ is_own_attempt()

mod_quiz\quiz_attempt::is_own_attempt ( )

Does this attempt belong to the current user?

Return values
booltrue => own attempt/preview. false => reviewing someone else's.

◆ is_own_preview()

mod_quiz\quiz_attempt::is_own_preview ( )

Is this attempt is a preview belonging to the current user.

Return values
booltrue if it is.

◆ is_preview()

mod_quiz\quiz_attempt::is_preview ( )

Is this attempt a preview?

Return values
booltrue if it is.

◆ is_preview_user()

mod_quiz\quiz_attempt::is_preview_user ( )

Is the current user is someone who previews the quiz, rather than attempting it?

Return values
booltrue user is a preview user. False, if they can do real attempts.

◆ is_question_flagged()

mod_quiz\quiz_attempt::is_question_flagged ( $slot)

Is a particular question in this attempt a real question, or something like a description.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
boolwhether that question is a real question.

◆ is_real_question()

mod_quiz\quiz_attempt::is_real_question ( $slot)

Is a particular question in this attempt a real question, or something like a description.

Parameters
int$slotthe number used to identify this question within this attempt.
Return values
intwhether that question is a real question. Actually returns the question length, which could theoretically be greater than one.

◆ is_review_allowed()

mod_quiz\quiz_attempt::is_review_allowed ( )

Is the current user allowed to review this attempt.

This applies when {

See also
is_own_attempt()} returns false.
Return values
boolwhether the review should be allowed.

◆ links_to_other_attempts()

mod_quiz\quiz_attempt::links_to_other_attempts ( moodle_url $url)

Return an array of variant URLs to other attempts at this quiz.

The $url passed in must contain an attempt parameter.

The {

See also
links_to_other_attempts} object returned contains an array with keys that are the attempt number, 1, 2, 3. The array values are either a {
moodle_url} with the attempt parameter updated to point to the attempt id of the other attempt, or null corresponding to the current attempt number.
Parameters
moodle_url$urla URL.
Return values
links_to_other_attempts|boolcontaining array int => null|moodle_url. False if none.

◆ links_to_other_redos()

mod_quiz\quiz_attempt::links_to_other_redos ( $slot,
moodle_url $baseurl )

Return an array of variant URLs to other redos of the question in a particular slot.

The $url passed in must contain a slot parameter.

The {

See also
links_to_other_attempts} object returned contains an array with keys that are the redo number, 1, 2, 3. The array values are either a {
moodle_url} with the slot parameter updated to point to the slot that has that redo of this question; or null corresponding to the redo identified by $slot.
Parameters
int$slotidentifies a question in this attempt.
moodle_url$baseurlthe base URL to modify to generate each link.
Return values
links_to_other_attempts|nullcontaining array int => null|moodle_url, or null if the question in this slot has not been redone.

◆ make_blocked_question_placeholder()

mod_quiz\quiz_attempt::make_blocked_question_placeholder ( $slot)
protected

Create a fake question to be displayed in place of a question that is blocked until the previous question has been answered.

Parameters
int$slotint slot number of the question to replace.
Return values
question_attemptthe placeholder question attempt.

◆ page_and_question_url()

mod_quiz\quiz_attempt::page_and_question_url ( $script,
$slot,
$page,
$showall,
$thispage )
protected

Get a URL for a particular question on a particular page of the quiz.

Used by {

See also
attempt_url()} and {
review_url()}.
Parameters
string$scripte.g. 'attempt' or 'review'. Used in the URL like /mod/quiz/$script.php.
int$slotidentifies the specific question on the page to jump to. 0 to just use the $page parameter.
int$page-1 to look up the page number from the slot, otherwise the page number to go to.
bool | null$showallif true, return a URL with showall=1, and not page number. if null, then an intelligent default will be chosen.
int$thispagethe page we are currently on. Links to questions on this page will just be a fragment #q123. -1 to disable this.
Return values
moodle_urlThe requested URL.

◆ process_abandon()

mod_quiz\quiz_attempt::process_abandon ( $timestamp,
$studentisonline )

Mark this attempt as abandoned.

Parameters
int$timestampthe time to deem as now.
bool$studentisonlineis the student currently interacting with Moodle?

◆ process_attempt()

mod_quiz\quiz_attempt::process_attempt ( $timenow,
$finishattempt,
$timeup,
$thispage )

Process responses during an attempt at a quiz.

Parameters
int$timenowtime when the processing started.
bool$finishattemptwhether to finish the attempt or not.
bool$timeuptrue if form was submitted by timer.
int$thispagecurrent page number.
Return values
stringthe attempt state once the data has been processed.
Since
Moodle 3.1

◆ process_auto_save()

mod_quiz\quiz_attempt::process_auto_save ( $timestamp)

Process all the autosaved data that was part of the current request.

Parameters
int$timestampthe timestamp that should be stored as the modified. time in the database for these actions. If null, will use the current time.

◆ process_finish()

mod_quiz\quiz_attempt::process_finish ( $timestamp,
$processsubmitted,
$timefinish = null,
$studentisonline = false )

Submit the attempt.

The separate $timefinish argument should be used when the quiz attempt is being processed asynchronously (for example when cron is submitting attempts where the time has expired).

Parameters
int$timestampthe time to record as last modified time.
bool$processsubmittedif true, and question responses in the current POST request are stored to be graded, before the attempt is finished.
?int$timefinishif set, use this as the finish time for the attempt. (otherwise use $timestamp as the finish time as well).
bool$studentisonlineis the student currently interacting with Moodle?

◆ process_going_overdue()

mod_quiz\quiz_attempt::process_going_overdue ( $timestamp,
$studentisonline )

Mark this attempt as now overdue.

Parameters
int$timestampthe time to deem as now.
bool$studentisonlineis the student currently interacting with Moodle?

◆ process_redo_question()

mod_quiz\quiz_attempt::process_redo_question ( $slot,
$timestamp )

Replace a question in an attempt with a new attempt at the same question.

Well, for randomised questions, it won't be the same question, it will be a different randomly selected pick from the available question.

Parameters
int$slotthe question to restart.
int$timestampthe timestamp to record for this action.

◆ process_reopen_abandoned()

mod_quiz\quiz_attempt::process_reopen_abandoned ( $timestamp)

This method takes an attempt in the 'Never submitted' state, and reopens it.

If, for this student, time has not expired (perhaps, because an override has been added, then the attempt is left open. Otherwise, it is immediately submitted for grading.

Parameters
int$timestampthe time to deem as now.

◆ process_submitted_actions()

mod_quiz\quiz_attempt::process_submitted_actions ( $timestamp,
$becomingoverdue = false,
$simulatedresponses = null )

Process all the actions that were submitted as part of the current request.

Parameters
int$timestampthe timestamp that should be stored as the modified. time in the database for these actions. If null, will use the current time.
bool$becomingoverdue
array | null$simulatedresponsesIf not null, then we are testing, and this is an array of simulated data. There are two formats supported here, for historical reasons. The newer approach is to pass an array created by {
See also
core_question_generator\get_simulated_post_data_for_questions_in_usage()}. the second is to pass an array slot no => contains arrays representing student responses which will be passed to {
question_definition\prepare_simulated_post_data()}. This second method will probably get deprecated one day.

◆ processattempt_url()

mod_quiz\quiz_attempt::processattempt_url ( )

Get the URL to which the attempt data should be submitted.

Return values
moodle_urlthe URL of this quiz's summary page.

◆ render_question()

mod_quiz\quiz_attempt::render_question ( $slot,
$reviewing,
renderer $renderer,
$thispageurl = null )

Generate the HTML that displays the question in its current state, with the appropriate display options.

Parameters
int$slotidentifies the question in the attempt.
bool$reviewingis the being printed on an attempt or a review page.
renderer$rendererthe quiz renderer.
moodle_url$thispageurlthe URL of the page this question is being printed on.
Return values
stringHTML for the question in its current state.

◆ render_question_at_step()

mod_quiz\quiz_attempt::render_question_at_step ( $slot,
$seq,
$reviewing,
renderer $renderer,
$thispageurl = null )

Like {.

See also
render_question()} but displays the question at the past step indicated by $seq, rather than showing the latest step.
Parameters
int$slotthe slot number of a question in this quiz attempt.
int$seqthe seq number of the past state to display.
bool$reviewingis the being printed on an attempt or a review page.
renderer$rendererthe quiz renderer.
moodle_url$thispageurlthe URL of the page this question is being printed on.
Return values
stringHTML for the question in its current state.

◆ render_question_for_commenting()

mod_quiz\quiz_attempt::render_question_for_commenting ( $slot)

Wrapper round print_question from lib/questionlib.php.

Parameters
int$slotthe id of a question in this quiz attempt.
Return values
stringHTML of the question.

◆ render_question_helper()

mod_quiz\quiz_attempt::render_question_helper ( $slot,
$reviewing,
$thispageurl,
renderer $renderer,
$seq )
protected

Helper used by {.

See also
render_question()} and {
render_question_at_step()}.
Parameters
int$slotidentifies the question in the attempt.
bool$reviewingis the being printed on an attempt or a review page.
moodle_url$thispageurlthe URL of the page this question is being printed on.
renderer$rendererthe quiz renderer.
int | null$seqthe seq number of the past state to display.
Return values
stringHTML fragment.

◆ require_capability()

mod_quiz\quiz_attempt::require_capability ( $capability,
$userid = null,
$doanything = true )

Wrapper round the require_capability function that automatically passes in the quiz context.

Parameters
string$capabilitythe name of the capability to check. For example mod/forum:view.
int | null$useridA user id. If null checks the permissions of the current user.
bool$doanythingIf false, ignore effect of admin role assignment.

◆ requires_manual_grading()

mod_quiz\quiz_attempt::requires_manual_grading ( )

Do any questions in this attempt need to be graded manually?

Return values
boolTrue if we have at least one question still needs manual grading.

◆ restart_preview_button()

mod_quiz\quiz_attempt::restart_preview_button ( )

Print the HTML for the start new preview button, if the current user is allowed to see one.

Return values
stringHTML for the button.

◆ review_page_title()

mod_quiz\quiz_attempt::review_page_title ( int $page,
bool $showall = false )

Generates the title of the review page.

Parameters
int$pagethe page number (starting with 0) in the attempt.
bool$showallwhether the review page contains the entire attempt on one page.
Return values
stringtitle of the review page.

◆ review_url()

mod_quiz\quiz_attempt::review_url ( $slot = null,
$page = -1,
$showall = null,
$thispage = -1 )

Get the URL of a particular page in the review of this attempt.

Parameters
int | null$slotindicates which question to link to.
int$pageif specified, the URL of this particular page of the attempt, otherwise the URL will go to the first page. If -1, deduce $page from $slot.
bool | null$showallif true, the URL will be to review the entire attempt on one page, and $page will be ignored. If null, a sensible default will be chosen.
int$thispageif not -1, the current page. Will cause links to other things on this page to be output as only a fragment.
Return values
moodle_urlthe URL to review this attempt.

◆ set_currentpage()

mod_quiz\quiz_attempt::set_currentpage ( $page)

Update attempt page.

Parameters
int$pagepage number.
Return values
booleantrue if everything was ok, false otherwise (out of sequence access).
Since
Moodle 3.1

◆ set_grade_item_totals()

mod_quiz\quiz_attempt::set_grade_item_totals ( array $grades)

Set the total grade for each grade_item for this quiz.

You only need to do this if the instance of this class was created with $loadquestions false. Typically, you will have got the grades from {

See also
grade_calculator\compute_grade_item_totals_for_attempts()}.
Parameters
grade_out_of[]$gradessame form as {
See also
grade_calculator\compute_grade_item_totals()} would return.

◆ set_offline_modified_time()

mod_quiz\quiz_attempt::set_offline_modified_time ( $time)

Update the timemodifiedoffline attempt field.

This function should be used only when web services are being used.

Parameters
int$timetime stamp.
Return values
booleanfalse if the field is not updated because web services aren't being used.
Since
Moodle 3.2

◆ start_attempt_url()

mod_quiz\quiz_attempt::start_attempt_url ( $slot = null,
$page = -1 )

Get the URL to start or continue an attempt.

Parameters
int | null$slotwhich question in the attempt to go to after starting (optional).
int$pagewhich page in the attempt to go to after starting.
Return values
moodle_urlthe URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter.

◆ state_name()

static mod_quiz\quiz_attempt::state_name ( $state)
static

Get a human-readable name for one of the quiz attempt states.

Parameters
string$stateone of the state constants like IN_PROGRESS.
Return values
stringthe human-readable state name.

◆ summary_page_title()

mod_quiz\quiz_attempt::summary_page_title ( )

Generates the title of the summary page.

Return values
stringsummary page title.

◆ summary_url()

mod_quiz\quiz_attempt::summary_url ( )

Get the URL of the summary page of this attempt.

Return values
moodle_urlthe URL of this quiz's summary page.

◆ update_questions_to_new_version_if_changed()

mod_quiz\quiz_attempt::update_questions_to_new_version_if_changed ( )

If any questions in this attempt have changed, update the attempts.

For now, this should only be done for previews.

When we update the question, we keep the same question (in the case of random questions) and the same variant (if this question has variants). If possible, we use regrade to preserve any interaction that has been had with this question (e.g. a saved answer) but if that is not possible, we put in a newly started attempt.

◆ update_timecheckstate()

mod_quiz\quiz_attempt::update_timecheckstate ( $time)

Update this attempt timecheckstate if necessary.

Parameters
int | null$timethe timestamp to set.

◆ view_url()

mod_quiz\quiz_attempt::view_url ( )

Get the URL of this quiz's view.php page.

Return values
moodle_urlquiz view url.

Member Data Documentation

◆ $gradeitemmarks

grade_out_of [] null array mod_quiz\quiz_attempt::$gradeitemmarks = null
protected

can be used to store the total grade for each section.

This is typically done when one or more attempts are created without load_questions. This lets the mark totals be passed in and later used. Format of this array should match what {

See also
grade_calculator\compute_grade_item_totals()} would return.

◆ $quba

question_usage_by_activity null question_usage_by_activity mod_quiz\quiz_attempt::$quba = null
protected

the question usage for this quiz attempt.

Only available after load_questions is called, e.g. if the class is constructed with $loadquestions true (the default).

◆ $questionnumbers

array mod_quiz\quiz_attempt::$questionnumbers
protected

slot => displayed question number for this slot.

(E.g. 1, 2, 3 or 'i'.)

◆ $slots

array mod_quiz\quiz_attempt::$slots
protected

of slot information.

These objects contain ->id (int), ->slot (int), ->requireprevious (bool), ->displaynumber (string) and quizgradeitemid (int) from the DB. They do not contain page - get that from {

See also
get_question_page()} - or maxmark - get that from $this->quba. It is augmented with ->firstinsection (bool), ->section (stdClass from $this->sections).

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