Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
quiz_attempt Class Reference

This class extends the quiz class to hold data about the state of a particular attempt, in addition to the data about the quiz. More...

Public Member Functions

 __construct ($attempt, $quiz, $cm, $course, $loadquestions=true)
 Constructor assuming we already have the necessary data loaded. More...
 
 all_question_attempts_originally_in_slot ($slot)
 Get all the question_attempt objects that have ever appeared in a given slot. More...
 
 attempt_page_title (int $page)
 Generates the title of the attempt page. More...
 
 attempt_url ($slot=null, $page=-1, $thispage=-1)
 
 can_navigate_to ($slot)
 Checks whether a user may navigate to a particular slot. More...
 
 can_question_be_redone_now ($slot)
 Is it possible for this question to be re-started within this attempt? More...
 
 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. More...
 
 check_file_access ($slot, $reviewing, $contextid, $component, $filearea, $args, $forcedownload)
 Check wheter access should be allowed to a particular file. More...
 
 check_page_access ($page)
 Check a page access to see if is an out of sequence access. More...
 
 check_review_capability ()
 Check the appropriate capability to see whether this user may review their own attempt. More...
 
 fire_attempt_reviewed_event ()
 Trigger the attempt_reviewed event. More...
 
 fire_attempt_summary_viewed_event ()
 Trigger the attempt_summary_viewed event. More...
 
 fire_attempt_viewed_event ()
 Trigger the attempt_viewed event. More...
 
 force_page_number_into_range ($page)
 If the given page number is out of range (before the first page, or after the last page, chnage it to be within range). More...
 
 get_access_manager ($timenow)
 
 get_active_slots ($page='all')
 Return the list of slot numbers for either a given page of the quiz, or for the whole quiz. More...
 
 get_additional_summary_data (question_display_options $options)
 Get extra summary information about this attempt. More...
 
 get_attempt ()
 
 get_attempt_number ()
 
 get_attempt_state ()
 
 get_attemptid ()
 
 get_cm ()
 
 get_cmid ()
 Get the course-module id. More...
 
 get_course ()
 Get the course settings object. More...
 
 get_courseid ()
 
 get_currentpage ()
 
 get_default_show_all ($script)
 By default, should this script show all questions on one page for this attempt? More...
 
 get_display_options ($reviewing)
 Wrapper that the correct mod_quiz_display_options for this quiz at the moment. More...
 
 get_display_options_with_edit_link ($reviewing, $slot, $thispageurl)
 Wrapper that the correct mod_quiz_display_options for this quiz at the moment. More...
 
 get_due_date ()
 If the attempt is in an applicable state, work out the time by which the student should next do something. More...
 
 get_heading_before_slot ($slot)
 If the section heading, if any, that should come just before this slot. More...
 
 get_html_head_contributions ($page='all', $showall=false)
 Initialise the JS etc. More...
 
 get_navigation_method ()
 
 get_navigation_panel (mod_quiz_renderer $output, $panelclass, $page, $showall=false)
 Get the navigation panel object for this attempt. More...
 
 get_num_attempts_allowed ()
 
 get_num_pages ()
 
 get_original_slot ($slot)
 Given a slot in this attempt, which may or not be a redone question, return the original slot. More...
 
 get_overall_feedback ($grade)
 Get the overall feedback corresponding to a particular mark. More...
 
 get_question_action_time ($slot)
 Get the time of the most recent action performed on a question. More...
 
 get_question_attempt ($slot)
 Get the question_attempt object for a particular question in this attempt. More...
 
 get_question_html_head_contributions ($slot)
 Initialise the JS etc. More...
 
 get_question_mark ($slot)
 Return the grade obtained on a particular question. More...
 
 get_question_name ($slot)
 Return the grade obtained on a particular question, if the user is permitted to see it. More...
 
 get_question_number ($slot)
 Get the displayed question number for a slot. More...
 
 get_question_page ($slot)
 Return the page of the quiz where this question appears. More...
 
 get_question_state ($slot)
 Return the question_state that this question is in. More...
 
 get_question_state_class ($slot, $showcorrectness)
 Return the grade obtained on a particular question, if the user is permitted to see it. More...
 
 get_question_status ($slot, $showcorrectness)
 Return the grade obtained on a particular question, if the user is permitted to see it. More...
 
 get_question_type_name ($slot)
 Return the question type name for a given slot within the current attempt. More...
 
 get_question_usage ()
 Helper method for unit tests. More...
 
 get_quiz ()
 
 get_quiz_name ()
 
 get_quizid ()
 
 get_quizobj ()
 
 get_slots ($page='all')
 Return the list of slot numbers for either a given page of the quiz, or for the whole quiz. More...
 
 get_state ()
 
 get_submitted_date ()
 
 get_sum_marks ()
 
 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. More...
 
 get_uniqueid ()
 
 get_userid ()
 
 handle_if_time_expired ($timestamp, $studentisonline)
 Check this attempt, to see if there are any state transitions that should happen automatically. More...
 
 has_capability ($capability, $userid=null, $doanything=true)
 Wrapper round the has_capability funciton that automatically passes in the quiz context. More...
 
 has_response_to_at_least_one_graded_question ()
 Has the student, in this attempt, engaged with the quiz in a non-trivial way? More...
 
 is_blocked_by_previous_question ($slot)
 Checks whether the question in this slot requires the previous question to have been completed. More...
 
 is_finished ()
 
 is_last_page ($page)
 
 is_own_attempt ()
 Is this someone dealing with their own attempt or preview? More...
 
 is_own_preview ()
 
 is_preview ()
 
 is_preview_user ()
 
 is_question_flagged ($slot)
 Is a particular question in this attempt a real question, or something like a description. More...
 
 is_real_question ($slot)
 Is a particular question in this attempt a real question, or something like a description. More...
 
 is_review_allowed ()
 Is the current user allowed to review this attempt. More...
 
 links_to_other_attempts (moodle_url $url)
 Return an array of variant URLs to other attempts at this quiz. More...
 
 links_to_other_redos ($slot, moodle_url $baseurl)
 Return an array of variant URLs to other redos of the question in a particular slot. More...
 
 load_questions ()
 This method can be called later if the object was constructed with $loadqusetions = false.
 
 process_abandon ($timestamp, $studentisonline)
 Mark this attempt as abandoned. More...
 
 process_attempt ($timenow, $finishattempt, $timeup, $thispage)
 Process responses during an attempt at a quiz. More...
 
 process_auto_save ($timestamp)
 Process all the autosaved data that was part of the current request. More...
 
 process_finish ($timestamp, $processsubmitted, $timefinish=null)
 Submit the attempt. More...
 
 process_going_overdue ($timestamp, $studentisonline)
 Mark this attempt as now overdue. More...
 
 process_redo_question ($slot, $timestamp)
 Replace a question in an attempt with a new attempt at the same question. More...
 
 process_submitted_actions ($timestamp, $becomingoverdue=false, $simulatedresponses=null)
 Process all the actions that were submitted as part of the current request. More...
 
 processattempt_url ()
 
 render_question ($slot, $reviewing, mod_quiz_renderer $renderer, $thispageurl=null)
 Generate the HTML that displayes the question in its current state, with the appropriate display options. More...
 
 render_question_at_step ($slot, $seq, $reviewing, mod_quiz_renderer $renderer, $thispageurl=null)
 Like render_question() but displays the question at the past step indicated by $seq, rather than showing the latest step. More...
 
 render_question_for_commenting ($slot)
 Wrapper round print_question from lib/questionlib.php. More...
 
 require_capability ($capability, $userid=null, $doanything=true)
 Wrapper round the require_capability function that automatically passes in the quiz context. More...
 
 restart_preview_button ()
 Print the HTML for the start new preview button, if the current user is allowed to see one. More...
 
 review_page_title (int $page, bool $showall=false)
 Generates the title of the review page. More...
 
 review_url ($slot=null, $page=-1, $showall=null, $thispage=-1)
 
 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. More...
 
 set_offline_modified_time ($time)
 Update the timemodifiedoffline attempt field. More...
 
 start_attempt_url ($slot=null, $page=-1)
 Get the URL to start or continue an attempt. More...
 
 summary_page_title ()
 Generates the title of the summary page. More...
 
 summary_url ()
 
 update_timecheckstate ($time)
 Update this attempt timecheckstate if necessary. More...
 
 view_url ()
 

Static Public Member Functions

static create ($attemptid)
 Static function to create a new quiz_attempt object given an attemptid. More...
 
static create_from_usage_id ($usageid)
 Static function to create a new quiz_attempt object given a usage id. More...
 
static state_name ($state)
 

Public Attributes

string const ABANDONED = 'abandoned'
 to identify the abandoned state.
 
string const FINISHED = 'finished'
 to identify the finished state.
 
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 the represent the layout.
 
 fire_state_transition_event ($eventclass, $timestamp)
 Fire a state transition event. More...
 
 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. More...
 
 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. More...
 
 render_question_helper ($slot, $reviewing, $thispageurl, mod_quiz_renderer $renderer, $seq)
 Helper used by render_question() and render_question_at_step(). More...
 

Static Protected Member Functions

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

Protected Attributes

stdClass $attempt
 the quiz_attempts row.
 
array $pagelayout
 page no => array of slot numbers on the page in order.
 
question_usage_by_activity $quba
 the question usage for this quiz attempt.
 
array $questionnumbers
 slot => displayed question number for this slot. More...
 
array $questionpages
 slot => page number for this slot.
 
quiz $quizobj
 object containing the quiz settings.
 
mod_quiz_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. More...
 

Detailed Description

This class extends the quiz class to hold data about the state of a particular attempt, in addition to the data about the quiz.

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

Constructor & Destructor Documentation

◆ __construct()

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

Constructor assuming we already have the necessary data loaded.

Parameters
object$attemptthe row of the quiz_attempts table.
object$quizthe quiz object for this attempt and user.
object$cmthe course_module object for this quiz.
object$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()

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()

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()

quiz_attempt::attempt_url (   $slot = null,
  $page = -1,
  $thispage = -1 
)
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
stringthe URL to continue this attempt.

◆ can_navigate_to()

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()

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()

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()

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

Check wheter 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
stringHTML for the question in its current state.

◆ check_page_access()

quiz_attempt::check_page_access (   $page)

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

Parameters
int$pagepage number.
Return values
booleanfalse is is an out of sequence access, true otherwise.
Since
Moodle 3.1

◆ check_review_capability()

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 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 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 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_reviewed_event()

quiz_attempt::fire_attempt_reviewed_event ( )

Trigger the attempt_reviewed event.

Since
Moodle 3.1

◆ fire_attempt_summary_viewed_event()

quiz_attempt::fire_attempt_summary_viewed_event ( )

Trigger the attempt_summary_viewed event.

Since
Moodle 3.1

◆ fire_attempt_viewed_event()

quiz_attempt::fire_attempt_viewed_event ( )

Trigger the attempt_viewed event.

Since
Moodle 3.1

◆ fire_state_transition_event()

quiz_attempt::fire_state_transition_event (   $eventclass,
  $timestamp 
)
protected

Fire a state transition event.

Parameters
string$eventclassthe event class name.
int$timestampthe timestamp to include in the event.

◆ force_page_number_into_range()

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, chnage it to be within range).

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

◆ get_access_manager()

quiz_attempt::get_access_manager (   $timenow)
Parameters
int$timenowthe current time as a unix timestamp.
Return values
quiz_access_managerand instance of the quiz_access_manager class for this quiz at this time.

◆ get_active_slots()

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()

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 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$optionsthe display options for this quiz attempt at this time.
Return values
arrayas described above.

◆ get_attempt()

quiz_attempt::get_attempt ( )
Return values
objectthe row from the quiz_attempts table.

◆ get_attempt_number()

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

◆ get_attempt_state()

quiz_attempt::get_attempt_state ( )
Return values
intone of the mod_quiz_display_options::DURING, IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants.

◆ get_attemptid()

quiz_attempt::get_attemptid ( )
Return values
intthe attempt id.

◆ get_cm()

quiz_attempt::get_cm ( )
Return values
objectthe course_module object.

◆ get_cmid()

quiz_attempt::get_cmid ( )

Get the course-module id.

Return values
intthe course_module id.

◆ get_course()

quiz_attempt::get_course ( )

Get the course settings object.

Return values
stdClassthe course settings object.

◆ get_courseid()

quiz_attempt::get_courseid ( )
Return values
intthe course id.

◆ get_currentpage()

quiz_attempt::get_currentpage ( )
Return values
intthe current page of the attempt.

◆ get_default_show_all()

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()

quiz_attempt::get_display_options (   $reviewing)

Wrapper that the correct mod_quiz_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()

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

Wrapper that the correct mod_quiz_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()

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_heading_before_slot()

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
stringthe required heading, or null if there is not one here.

◆ get_html_head_contributions()

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()

quiz_attempt::get_navigation_method ( )
Return values
intthe quiz navigation method.

◆ get_navigation_panel()

quiz_attempt::get_navigation_panel ( mod_quiz_renderer  $output,
  $panelclass,
  $page,
  $showall = false 
)

Get the navigation panel object for this attempt.

Parameters
mod_quiz_renderer$outputthe quiz renderer to use to output things.
string$panelclassThe type of panel, quiz_attempt_nav_panel or quiz_review_nav_panel
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()

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

◆ get_num_pages()

quiz_attempt::get_num_pages ( )
Return values
intnumber fo pages in this quiz.

◆ get_original_slot()

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()

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()

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()

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()

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()

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()

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 formatted grade, to the number of decimal places specified by the quiz.

◆ get_question_number()

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()

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()

quiz_attempt::get_question_state (   $slot)

Return the 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()

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()

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()

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.
Since
Moodle 3.1

◆ get_question_usage()

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_name()

quiz_attempt::get_quiz_name ( )
Return values
stringthe name of this quiz.

◆ get_quizid()

quiz_attempt::get_quizid ( )
Return values
intthe quiz id.

◆ get_slots()

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()

quiz_attempt::get_state ( )
Return values
stringone of the quiz_attempt::IN_PROGRESS, FINISHED, OVERDUE or ABANDONED constants.

◆ get_submitted_date()

quiz_attempt::get_submitted_date ( )
Return values
intthe time when this attempt was submitted. 0 if it has not been submitted yet.

◆ get_time_left_display()

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()

quiz_attempt::get_uniqueid ( )
Return values
intthe attempt unique id.

◆ get_userid()

quiz_attempt::get_userid ( )
Return values
intthe id of the user this attempt belongs to.

◆ handle_if_time_expired()

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()

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

Wrapper round the has_capability funciton 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. By default (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()

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()

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()

quiz_attempt::is_finished ( )
Return values
boolwhether this attempt has been finished (true) or is still in progress (false). Be warned that this is not just state == self::FINISHED, it also includes self::ABANDONED.

◆ is_last_page()

quiz_attempt::is_last_page (   $page)
Parameters
int$pagepage number
Return values
booltrue if this is the last page of the quiz.

◆ is_own_attempt()

quiz_attempt::is_own_attempt ( )

Is this someone dealing with their own attempt or preview?

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

◆ is_own_preview()

quiz_attempt::is_own_preview ( )
Return values
boolwhether this attempt is a preview belonging to the current user.

◆ is_preview()

quiz_attempt::is_preview ( )
Return values
boolwhether this attempt is a preview attempt.

◆ is_preview_user()

quiz_attempt::is_preview_user ( )
Return values
boolwhether the current user is someone who previews the quiz, rather than attempting it.

◆ is_question_flagged()

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()

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()

quiz_attempt::is_review_allowed ( )

Is the current user allowed to review this attempt.

This applies when is_own_attempt() returns false.

Return values
boolwhether the review should be allowed.

◆ links_to_other_attempts()

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 mod_quiz_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
mod_quiz_links_to_other_attempts|boolcontaining array int => null|moodle_url. False if none.

◆ links_to_other_redos()

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 mod_quiz_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
mod_quiz_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()

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()

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 attempt_url() and review_url().

Parameters
string$script,.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()

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()

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()

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()

quiz_attempt::process_finish (   $timestamp,
  $processsubmitted,
  $timefinish = null 
)

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$timefinish if set, use this as the finish time for the attempt. (otherwise use $timestamp as the finish time as well).

◆ process_going_overdue()

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()

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 randomised selection.

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

◆ process_submitted_actions()

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 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()

quiz_attempt::processattempt_url ( )
Return values
moodle_urlthe URL of this quiz's summary page.

◆ render_question()

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

Generate the HTML that displayes 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.
mod_quiz_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()

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

Like 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.
mod_quiz_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()

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()

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

Helper used by 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.
mod_quiz_renderer$rendererthe quiz renderer.
int | null$seqthe seq number of the past state to display.
Return values
stringHTML fragment.

◆ require_capability()

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. By default (null) checks the permissions of the current user.
bool$doanythingIf false, ignore effect of admin role assignment.

◆ restart_preview_button()

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()

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()

quiz_attempt::review_url (   $slot = null,
  $page = -1,
  $showall = null,
  $thispage = -1 
)
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
stringthe URL to review this attempt.

◆ set_currentpage()

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_offline_modified_time()

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()

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
stringthe URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter.

◆ state_name()

static quiz_attempt::state_name (   $state)
static
Parameters
string$stateone of the state constants like IN_PROGRESS.
Return values
stringthe human-readable state name.

◆ summary_page_title()

quiz_attempt::summary_page_title ( )

Generates the title of the summary page.

Return values
stringsummary page title.

◆ summary_url()

quiz_attempt::summary_url ( )
Return values
moodle_urlthe URL of this quiz's summary page.

◆ update_timecheckstate()

quiz_attempt::update_timecheckstate (   $time)

Update this attempt timecheckstate if necessary.

Parameters
int | null$timethe timestamp to set.

◆ view_url()

quiz_attempt::view_url ( )
Return values
stringquiz view url.

Member Data Documentation

◆ $questionnumbers

array quiz_attempt::$questionnumbers
protected

slot => displayed question number for this slot.

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

◆ $slots

array quiz_attempt::$slots
protected

of slot information.

These objects contain ->slot (int), ->requireprevious (bool), ->questionids (int) the original question for random questions, ->firstinsection (bool), ->section (stdClass from $this->sections). This does not contain page - get that from get_question_page() - or maxmark - get that from $this->quba.


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