Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
|
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_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_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. | |
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. | |
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. | |
mod_quiz\quiz_attempt::__construct | ( | $attempt, | |
$quiz, | |||
$cm, | |||
$course, | |||
$loadquestions = true ) |
Constructor assuming we already have the necessary data loaded.
stdClass | $attempt | the row of the quiz_attempts table. |
stdClass | $quiz | the quiz object for this attempt and user. |
cm_info | $cm | the course_module object for this quiz. |
stdClass | $course | the 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. |
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.
int | $slot | the number used to identify this question within this attempt. |
question_attempt[] | the attempts. |
mod_quiz\quiz_attempt::attempt_page_title | ( | int | $page | ) |
Generates the title of the attempt page.
int | $page | the page number (starting with 0) in the attempt. |
string | attempt page title. |
mod_quiz\quiz_attempt::attempt_url | ( | $slot = null, | |
$page = -1, | |||
$thispage = -1 ) |
Get the URL of a particular page within this attempt.
int | null | $slot | if specified, the slot number of a specific question to link to. |
int | $page | if specified, a particular page to link to. If not given deduced from $slot, or goes to the first page. |
int | $thispage | if not -1, the current page. Will cause links to other things on this page to be output as only a fragment. |
moodle_url | the URL to continue this attempt. |
mod_quiz\quiz_attempt::can_navigate_to | ( | $slot | ) |
Checks whether a user may navigate to a particular slot.
int | $slot | the target slot (currently does not affect the answer). |
bool | true if the navigation should be allowed. |
mod_quiz\quiz_attempt::can_question_be_redone_now | ( | $slot | ) |
Is it possible for this question to be re-started within this attempt?
int | $slot | the number used to identify this question within this attempt. |
bool | whether the student should be given the option to restart this question now. |
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.
bool | $short | if true, return a shorter string. |
string | an appropriate message. |
mod_quiz\quiz_attempt::check_file_access | ( | $slot, | |
$reviewing, | |||
$contextid, | |||
$component, | |||
$filearea, | |||
$args, | |||
$forcedownload ) |
Check whether access should be allowed to a particular file.
int | $slot | the slot of a question in this quiz attempt. |
bool | $reviewing | is the being printed on an attempt or a review page. |
int | $contextid | the file context id from the request. |
string | $component | the file component from the request. |
string | $filearea | the file area from the request. |
array | $args | extra part components from the request. |
bool | $forcedownload | whether to force download. |
bool | true if the file can be accessed. |
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.
int | $page | page number. |
bool | $allownext | in case of a sequential navigation, can we go to next page ? |
boolean | false is an out of sequence access, true otherwise. |
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.
|
static |
Static function to create a new quiz_attempt object given an attemptid.
int | $attemptid | the attempt id. |
quiz_attempt | the new quiz_attempt object |
|
static |
Static function to create a new quiz_attempt object given a usage id.
int | $usageid | the attempt usage id. |
quiz_attempt | the new quiz_attempt object |
|
staticprotected |
Used by {create()} and {create_from_usage_id()}.
array | $conditions | passed to $DB->get_record('quiz_attempts', $conditions). |
quiz_attempt | the desired instance of this class. |
mod_quiz\quiz_attempt::fire_attempt_autosaved_event | ( | ) |
Trigger the attempt_autosaved event.
void |
mod_quiz\quiz_attempt::fire_attempt_question_restarted_event | ( | int | $slot, |
int | $newquestionid ) |
Trigger the attempt_question_restarted event.
int | $slot | Slot number |
int | $newquestionid | New question id. |
void |
mod_quiz\quiz_attempt::fire_attempt_reviewed_event | ( | ) |
Trigger the attempt_reviewed event.
mod_quiz\quiz_attempt::fire_attempt_summary_viewed_event | ( | ) |
Trigger the attempt_summary_viewed event.
mod_quiz\quiz_attempt::fire_attempt_updated_event | ( | ) |
Trigger the attempt_updated event.
void |
mod_quiz\quiz_attempt::fire_attempt_viewed_event | ( | ) |
Trigger the attempt_viewed event.
|
protected |
Fire a state transition event.
string | $eventclass | the event class name. |
int | $timestamp | the timestamp to include in the event. |
bool | $studentisonline | is the student currently interacting with Moodle? |
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).
int | $page | the requested page number. |
int | a safe page number to use. |
mod_quiz\quiz_attempt::get_access_manager | ( | $timenow | ) |
Get the access_manager for this quiz attempt.
int | $timenow | the current time as a unix timestamp. |
access_manager | and instance of the access_manager class for this quiz at this time. |
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.
mixed | $page | string 'all' or integer page number. |
array | the requested list of slot numbers. |
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.
question_display_options | $options | the display options for this quiz attempt at this time. |
array | as described above. |
mod_quiz\quiz_attempt::get_attempt | ( | ) |
Get the raw quiz attempt object.
stdClass | the row from the quiz_attempts table. |
mod_quiz\quiz_attempt::get_attempt_number | ( | ) |
Get the attempt number.
int | the number of this attempt (is it this user's first, second, ... attempt). |
mod_quiz\quiz_attempt::get_attempt_state | ( | ) |
Get where we are time-wise in relation to this attempt and the quiz settings.
int | one of { |
mod_quiz\quiz_attempt::get_attemptid | ( | ) |
Get the id of this attempt.
int | the attempt id. |
mod_quiz\quiz_attempt::get_cm | ( | ) |
Get the course_module for this quiz.
cm_info | the course_module object. |
mod_quiz\quiz_attempt::get_cmid | ( | ) |
Get the course-module id.
int | the course_module id. |
mod_quiz\quiz_attempt::get_context | ( | ) |
Get the quiz context.
context_module | the context of the quiz this attempt belongs to. |
mod_quiz\quiz_attempt::get_course | ( | ) |
Get the course settings object.
stdClass | the course settings object. |
mod_quiz\quiz_attempt::get_courseid | ( | ) |
Git the id of the course this quiz belongs to.
int | the course id. |
mod_quiz\quiz_attempt::get_currentpage | ( | ) |
Get the current page of the attempt.
int | page number. |
mod_quiz\quiz_attempt::get_default_show_all | ( | $script | ) |
By default, should this script show all questions on one page for this attempt?
string | $script | the script name, e.g. 'attempt', 'summary', 'review'. |
bool | whether show all on one page should be on by default. |
mod_quiz\quiz_attempt::get_display_options | ( | $reviewing | ) |
Wrapper that the correct display_options for this quiz at the moment.
bool | $reviewing | true for options when reviewing, false for when attempting. |
question_display_options | the render options for this user on this attempt. |
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.
bool | $reviewing | true for review page, else attempt page. |
int | $slot | which question is being displayed. |
moodle_url | $thispageurl | to return to after the editing form is submitted or cancelled. If null, no edit link will be generated. |
question_display_options | the render options for this user on this attempt, with extra info to generate an edit link, if applicable. |
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.
int | timestamp by which the student needs to do something. |
mod_quiz\quiz_attempt::get_heading_before_slot | ( | $slot | ) |
If the section heading, if any, that should come just before this slot.
int | $slot | identifies a particular question in this attempt. |
string|null | the required heading, or null if there is not one here. |
mod_quiz\quiz_attempt::get_html_head_contributions | ( | $page = 'all', | |
$showall = false ) |
Initialise the JS etc.
required all the questions on a page.
int | string | $page | a page number, or 'all'. |
bool | $showall | if true, forces page number to all. |
string | HTML to output - mostly obsolete, will probably be an empty string. |
mod_quiz\quiz_attempt::get_navigation_method | ( | ) |
Get the quiz navigation method.
int | QUIZ_NAVMETHOD_FREE or QUIZ_NAVMETHOD_SEQ. |
mod_quiz\quiz_attempt::get_navigation_panel | ( | renderer | $output, |
$panelclass, | |||
$page, | |||
$showall = false ) |
Get the navigation panel object for this attempt.
renderer | $output | the quiz renderer to use to output things. |
string | $panelclass | The type of panel, navigation_panel_attempt\class or navigation_panel_review\class |
int | $page | the current page number. |
bool | $showall | whether we are showing the whole quiz on one page. (Used by review.php.) |
block_contents | the requested object. |
mod_quiz\quiz_attempt::get_num_attempts_allowed | ( | ) |
Get the number of attempts the user is allowed at this quiz.
int | the number of attempts allowed at this quiz (0 = infinite). |
mod_quiz\quiz_attempt::get_num_pages | ( | ) |
Get the number of quizzes in the quiz attempt.
int | number pages. |
mod_quiz\quiz_attempt::get_number_of_unanswered_questions | ( | ) |
Get the total number of unanswered questions in the attempt.
int |
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.
int | $slot | identifies a particular question in this attempt. |
int | the slot where this question was originally. |
mod_quiz\quiz_attempt::get_overall_feedback | ( | $grade | ) |
Get the overall feedback corresponding to a particular mark.
number | $grade | a particular grade. |
string | the feedback. |
mod_quiz\quiz_attempt::get_question_action_time | ( | $slot | ) |
Get the time of the most recent action performed on a question.
int | $slot | the number used to identify this question within this usage. |
int | timestamp. |
mod_quiz\quiz_attempt::get_question_attempt | ( | $slot | ) |
Get the question_attempt object for a particular question in this attempt.
int | $slot | the number used to identify this question within this attempt. |
question_attempt | the requested question_attempt. |
mod_quiz\quiz_attempt::get_question_html_head_contributions | ( | $slot | ) |
Initialise the JS etc.
required by one question.
int | $slot | the question slot number. |
string | HTML to output - but this is mostly obsolete. Will probably be an empty string. |
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.
int | $slot | the number used to identify this question within this attempt. |
string | the formatted grade, to the number of decimal places specified by the quiz. |
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.
int | $slot | the number used to identify this question within this attempt. |
string | the formatted grade, to the number of decimal places specified by the quiz. |
mod_quiz\quiz_attempt::get_question_number | ( | $slot | ) |
Get the displayed question number for a slot.
int | $slot | the number used to identify this question within this attempt. |
string | the displayed question number for the question in this slot. For example '1', '2', '3' or 'i'. |
mod_quiz\quiz_attempt::get_question_page | ( | $slot | ) |
Return the page of the quiz where this question appears.
int | $slot | the number used to identify this question within this attempt. |
int | the page of the quiz this question appears on. |
mod_quiz\quiz_attempt::get_question_state | ( | $slot | ) |
Return the {.
int | $slot | the number used to identify this question within this attempt. |
question_state | the state this question is in. |
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.
int | $slot | the number used to identify this question within this attempt. |
bool | $showcorrectness | Whether right/partial/wrong states should be distinguished. |
string | class name for this state. |
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.
int | $slot | the number used to identify this question within this attempt. |
bool | $showcorrectness | Whether right/partial/wrong states should be distinguished. |
string | the formatted grade, to the number of decimal places specified by the quiz. |
mod_quiz\quiz_attempt::get_question_type_name | ( | $slot | ) |
Return the question type name for a given slot within the current attempt.
int | $slot | the number used to identify this question within this attempt. |
string | the question type name. |
mod_quiz\quiz_attempt::get_question_usage | ( | ) |
Helper method for unit tests.
Get the underlying question usage object.
question_usage_by_activity | the usage. |
mod_quiz\quiz_attempt::get_quiz | ( | ) |
Get the raw quiz settings object.
stdClass |
mod_quiz\quiz_attempt::get_quiz_name | ( | ) |
Get the name of this quiz.
string | Quiz name, directly from the database (format_string must be called before output). |
mod_quiz\quiz_attempt::get_quizid | ( | ) |
Get the quiz id.
int | the quiz id. |
mod_quiz\quiz_attempt::get_quizobj | ( | ) |
Get the {.
quiz_settings |
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.
mixed | $page | string 'all' or integer page number. |
array | the requested list of slot numbers. |
mod_quiz\quiz_attempt::get_state | ( | ) |
Get the state of this attempt.
string | { |
mod_quiz\quiz_attempt::get_submitted_date | ( | ) |
Get the time when this attempt was submitted.
int | timestamp, or 0 if it has not been submitted yet. |
mod_quiz\quiz_attempt::get_sum_marks | ( | ) |
Get the total number of marks that the user had scored on all the questions.
float |
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.
int | $timenow | the time to consider as 'now'. |
int|false | the number of seconds remaining for this attempt. False if there is no limit. |
mod_quiz\quiz_attempt::get_uniqueid | ( | ) |
Get the question-usage id corresponding to this quiz attempt.
int | the attempt unique id. |
mod_quiz\quiz_attempt::get_userid | ( | ) |
Get the id of the user this attempt belongs to.
int | user id. |
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.
int | $timestamp | the timestamp that should be stored as the modified |
bool | $studentisonline | is the student currently interacting with Moodle? |
mod_quiz\quiz_attempt::has_capability | ( | $capability, | |
$userid = null, | |||
$doanything = true ) |
Wrapper round the has_capability function that automatically passes in the quiz context.
string | $capability | the name of the capability to check. For example mod/forum:view. |
int | null | $userid | A user id. If null checks the permissions of the current user. |
bool | $doanything | If false, ignore effect of admin role assignment. |
boolean | true if the user has this capability, otherwise false. |
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?
bool | true if we have saved a response for at least one graded 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.
int | $slot | the number used to identify this question within this attempt. |
bool | whether the previous question must have been completed before this one can be seen. |
mod_quiz\quiz_attempt::is_finished | ( | ) |
Has this attempt been finished?
States {
bool |
mod_quiz\quiz_attempt::is_last_page | ( | $page | ) |
Is a particular page the last one in the quiz?
int | $page | a page number |
bool | true if that is the last page of the quiz. |
mod_quiz\quiz_attempt::is_own_attempt | ( | ) |
Does this attempt belong to the current user?
bool | true => own attempt/preview. false => reviewing someone else's. |
mod_quiz\quiz_attempt::is_own_preview | ( | ) |
Is this attempt is a preview belonging to the current user.
bool | true if it is. |
mod_quiz\quiz_attempt::is_preview | ( | ) |
Is this attempt a preview?
bool | true if it is. |
mod_quiz\quiz_attempt::is_preview_user | ( | ) |
Is the current user is someone who previews the quiz, rather than attempting it?
bool | true user is a preview user. False, if they can do real attempts. |
mod_quiz\quiz_attempt::is_question_flagged | ( | $slot | ) |
Is a particular question in this attempt a real question, or something like a description.
int | $slot | the number used to identify this question within this attempt. |
bool | whether that question is a 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.
int | $slot | the number used to identify this question within this attempt. |
int | whether that question is a real question. Actually returns the question length, which could theoretically be greater than one. |
mod_quiz\quiz_attempt::is_review_allowed | ( | ) |
Is the current user allowed to review this attempt.
This applies when {
bool | whether the review should be allowed. |
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 {
moodle_url | $url | a URL. |
links_to_other_attempts|bool | containing array int => null|moodle_url. False if none. |
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 {
int | $slot | identifies a question in this attempt. |
moodle_url | $baseurl | the base URL to modify to generate each link. |
links_to_other_attempts|null | containing array int => null|moodle_url, or null if the question in this slot has not been redone. |
|
protected |
Create a fake question to be displayed in place of a question that is blocked until the previous question has been answered.
int | $slot | int slot number of the question to replace. |
question_attempt | the placeholder question attempt. |
|
protected |
Get a URL for a particular question on a particular page of the quiz.
Used by {
string | $script | e.g. 'attempt' or 'review'. Used in the URL like /mod/quiz/$script.php. |
int | $slot | identifies 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 | $showall | if true, return a URL with showall=1, and not page number. if null, then an intelligent default will be chosen. |
int | $thispage | the page we are currently on. Links to questions on this page will just be a fragment #q123. -1 to disable this. |
moodle_url | The requested URL. |
mod_quiz\quiz_attempt::process_abandon | ( | $timestamp, | |
$studentisonline ) |
Mark this attempt as abandoned.
int | $timestamp | the time to deem as now. |
bool | $studentisonline | is the student currently interacting with Moodle? |
mod_quiz\quiz_attempt::process_attempt | ( | $timenow, | |
$finishattempt, | |||
$timeup, | |||
$thispage ) |
Process responses during an attempt at a quiz.
int | $timenow | time when the processing started. |
bool | $finishattempt | whether to finish the attempt or not. |
bool | $timeup | true if form was submitted by timer. |
int | $thispage | current page number. |
string | the attempt state once the data has been processed. |
mod_quiz\quiz_attempt::process_auto_save | ( | $timestamp | ) |
Process all the autosaved data that was part of the current request.
int | $timestamp | the timestamp that should be stored as the modified. time in the database for these actions. If null, will use the current time. |
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).
int | $timestamp | the time to record as last modified time. |
bool | $processsubmitted | if 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). |
bool | $studentisonline | is the student currently interacting with Moodle? |
mod_quiz\quiz_attempt::process_going_overdue | ( | $timestamp, | |
$studentisonline ) |
Mark this attempt as now overdue.
int | $timestamp | the time to deem as now. |
bool | $studentisonline | is the student currently interacting with Moodle? |
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.
int | $slot | the question to restart. |
int | $timestamp | the timestamp to record for this action. |
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.
int | $timestamp | the time to deem as now. |
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.
int | $timestamp | the 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 | $simulatedresponses | If 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 { |
mod_quiz\quiz_attempt::processattempt_url | ( | ) |
Get the URL to which the attempt data should be submitted.
moodle_url | the URL of this quiz's summary page. |
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.
int | $slot | identifies the question in the attempt. |
bool | $reviewing | is the being printed on an attempt or a review page. |
renderer | $renderer | the quiz renderer. |
moodle_url | $thispageurl | the URL of the page this question is being printed on. |
string | HTML for the question in its current state. |
mod_quiz\quiz_attempt::render_question_at_step | ( | $slot, | |
$seq, | |||
$reviewing, | |||
renderer | $renderer, | ||
$thispageurl = null ) |
Like {.
int | $slot | the slot number of a question in this quiz attempt. |
int | $seq | the seq number of the past state to display. |
bool | $reviewing | is the being printed on an attempt or a review page. |
renderer | $renderer | the quiz renderer. |
moodle_url | $thispageurl | the URL of the page this question is being printed on. |
string | HTML for the question in its current state. |
mod_quiz\quiz_attempt::render_question_for_commenting | ( | $slot | ) |
Wrapper round print_question from lib/questionlib.php.
int | $slot | the id of a question in this quiz attempt. |
string | HTML of the question. |
|
protected |
Helper used by {.
int | $slot | identifies the question in the attempt. |
bool | $reviewing | is the being printed on an attempt or a review page. |
moodle_url | $thispageurl | the URL of the page this question is being printed on. |
renderer | $renderer | the quiz renderer. |
int | null | $seq | the seq number of the past state to display. |
string | HTML fragment. |
mod_quiz\quiz_attempt::require_capability | ( | $capability, | |
$userid = null, | |||
$doanything = true ) |
Wrapper round the require_capability function that automatically passes in the quiz context.
string | $capability | the name of the capability to check. For example mod/forum:view. |
int | null | $userid | A user id. If null checks the permissions of the current user. |
bool | $doanything | If false, ignore effect of admin role assignment. |
mod_quiz\quiz_attempt::requires_manual_grading | ( | ) |
Do any questions in this attempt need to be graded manually?
bool | True if we have at least one question still needs manual grading. |
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.
string | HTML for the button. |
mod_quiz\quiz_attempt::review_page_title | ( | int | $page, |
bool | $showall = false ) |
Generates the title of the review page.
int | $page | the page number (starting with 0) in the attempt. |
bool | $showall | whether the review page contains the entire attempt on one page. |
string | title of the review page. |
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.
int | null | $slot | indicates which question to link to. |
int | $page | if 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 | $showall | if 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 | $thispage | if not -1, the current page. Will cause links to other things on this page to be output as only a fragment. |
moodle_url | the URL to review this attempt. |
mod_quiz\quiz_attempt::set_currentpage | ( | $page | ) |
Update attempt page.
int | $page | page number. |
boolean | true if everything was ok, false otherwise (out of sequence access). |
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.
int | $time | time stamp. |
boolean | false if the field is not updated because web services aren't being used. |
mod_quiz\quiz_attempt::start_attempt_url | ( | $slot = null, | |
$page = -1 ) |
Get the URL to start or continue an attempt.
int | null | $slot | which question in the attempt to go to after starting (optional). |
int | $page | which page in the attempt to go to after starting. |
moodle_url | the URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter. |
|
static |
Get a human-readable name for one of the quiz attempt states.
string | $state | one of the state constants like IN_PROGRESS. |
string | the human-readable state name. |
mod_quiz\quiz_attempt::summary_page_title | ( | ) |
Generates the title of the summary page.
string | summary page title. |
mod_quiz\quiz_attempt::summary_url | ( | ) |
Get the URL of the summary page of this attempt.
moodle_url | the URL of this quiz's summary page. |
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.
mod_quiz\quiz_attempt::update_timecheckstate | ( | $time | ) |
Update this attempt timecheckstate if necessary.
int | null | $time | the timestamp to set. |
mod_quiz\quiz_attempt::view_url | ( | ) |
Get the URL of this quiz's view.php page.
moodle_url | quiz view url. |
|
protected |
slot => displayed question number for this slot.
(E.g. 1, 2, 3 or 'i'.)
|
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 {