Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
Public Member Functions | |
__construct (quiz_settings $quizobj, int $timenow, bool $canignoretimelimits) | |
Create an instance for a particular quiz. | |
attempt_must_be_in_popup () | |
Is this quiz required to be shown in a popup window? | |
back_to_view_page (renderer $output, string $message='') | |
Send the user back to the quiz view page. | |
current_attempt_finished () | |
Inform the rules that the current attempt is finished. | |
describe_rules () | |
Provide a description of the rules that apply to this quiz, such as is shown at the top of the quiz view page. | |
get_active_rule_names () | |
Get an array of the class names of all the active rules. | |
get_end_time (stdClass $attempt) | |
Compute when the attempt must be submitted. | |
get_popup_options () | |
Get options required for opening the attempt in a popup window. | |
get_preflight_check_form (moodle_url $url, ?int $attemptid) | |
Build the form required to do the pre-flight checks. | |
get_time_left_display (stdClass $attempt, int $timenow) | |
Compute what should be displayed to the user for time remaining in this attempt. | |
is_finished (int $numprevattempts, $lastattempt) | |
Do any of the rules mean that this student will no be allowed any further attempts at this quiz. | |
is_preflight_check_required (?int $attemptid) | |
Is a UI check is required before the user starts/continues their attempt. | |
make_review_link (stdClass $attempt, $nolongerused, renderer $output) | |
Make some text into a link to review the quiz, if that is appropriate. | |
notify_preflight_check_passed (?int $attemptid) | |
The pre-flight check has passed. | |
prevent_access () | |
Whether the user should be blocked from starting a new attempt or continuing an attempt now. | |
prevent_new_attempt (int $numprevattempts, $lastattempt) | |
Whether a user should be allowed to start a new attempt at this quiz now. | |
setup_attempt_page (moodle_page $page) | |
Sets up the attempt (review or summary) page with any properties required by the access rules. | |
validate_preflight_check (array $data, array $files, ?int $attemptid) | |
Run the preflight checks using the given data in all the rules supporting them. | |
Static Public Member Functions | |
static | add_settings_form_fields (mod_quiz_mod_form $quizform, MoodleQuickForm $mform) |
Add any form fields that the access rules require to the settings form. | |
static | delete_settings (stdClass $quiz) |
Delete any rule-specific settings when the quiz is deleted. | |
static | get_browser_security_choices () |
The the options for the Browser security settings menu. | |
static | load_quiz_and_settings (int $quizid) |
Load the quiz settings and any settings required by the access rules. | |
static | load_settings (int $quizid) |
Load any settings required by the access rules. | |
static | save_settings (stdClass $quiz) |
Save any submitted settings when the quiz settings form is submitted. | |
static | validate_settings_form_fields (array $errors, array $data, array $files, mod_quiz_mod_form $quizform) |
Validate the data from any form fields added using {. | |
Protected Member Functions | |
accumulate_messages (array $messages, $new) | |
Accumulates an array of messages. | |
make_rules (quiz_settings $quizobj, int $timenow, bool $canignoretimelimits) | |
Make all the rules relevant to a particular quiz. | |
Static Protected Member Functions | |
static | get_load_sql (int $quizid, array $rules, string $basefields) |
Build the SQL for loading all the access settings in one go. | |
static | get_rule_classes () |
Get that names of all the installed rule classes. | |
Protected Attributes | |
quiz_settings | $quizobj |
the quiz settings object. | |
access_rule_base | $rules = [] |
instances of the active rules for this quiz. | |
int | $timenow |
the time to be considered as 'now'. | |
mod_quiz\access_manager::__construct | ( | quiz_settings | $quizobj, |
int | $timenow, | ||
bool | $canignoretimelimits ) |
Create an instance for a particular quiz.
quiz_settings | $quizobj | the quiz settings. The quiz we will be controlling access to. |
int | $timenow | The time to use as 'now'. |
bool | $canignoretimelimits | Whether this user is exempt from time limits (has_capability('mod/quiz:ignoretimelimits', ...)). |
|
protected |
Accumulates an array of messages.
array | $messages | the current list of messages. |
string | array | $new | the new messages or messages. |
array | the updated array of messages. |
|
static |
Add any form fields that the access rules require to the settings form.
Note that the standard plugins do not use this mechanism, becuase all their settings are stored in the quiz table.
mod_quiz_mod_form | $quizform | the quiz settings form that is being built. |
MoodleQuickForm | $mform | the wrapped MoodleQuickForm. |
mod_quiz\access_manager::attempt_must_be_in_popup | ( | ) |
Is this quiz required to be shown in a popup window?
bool | true if a popup is required. |
mod_quiz\access_manager::back_to_view_page | ( | renderer | $output, |
string | $message = '' ) |
Send the user back to the quiz view page.
Normally this is just a redirect, but If we were in a secure window, we close this window, and reload the view window we came from.
This method does not return;
renderer | $output | the quiz renderer. |
string | $message | optional message to output while redirecting. |
mod_quiz\access_manager::current_attempt_finished | ( | ) |
Inform the rules that the current attempt is finished.
This is use, for example by the password rule, to clear the flag in the session.
|
static |
Delete any rule-specific settings when the quiz is deleted.
Note that the standard plugins do not use this mechanism because their settings are stored in the quiz table.
stdClass | $quiz | the data from the database, including $quiz->id which is the id of the quiz being deleted. |
mod_quiz\access_manager::describe_rules | ( | ) |
Provide a description of the rules that apply to this quiz, such as is shown at the top of the quiz view page.
Note that not all rules consider themselves important enough to output a description.
array | an array of description messages which may be empty. It would be sensible to output each one surrounded by <p> tags. |
mod_quiz\access_manager::get_active_rule_names | ( | ) |
Get an array of the class names of all the active rules.
Mainly useful for debugging.
array |
|
static |
The the options for the Browser security settings menu.
array | key => lang string. |
mod_quiz\access_manager::get_end_time | ( | stdClass | $attempt | ) |
Compute when the attempt must be submitted.
stdClass | $attempt | the data from the relevant quiz_attempts row. |
int|false | the attempt close time. False if there is no limit. |
|
staticprotected |
Build the SQL for loading all the access settings in one go.
int | $quizid | the quiz id. |
array | $rules | list of rule plugins, from { |
string | $basefields | initial part of the select list. |
array | with two elements, the sql and the placeholder values. If $basefields is '' then you must allow for the possibility that there is no data to load, in which case this method returns $sql = ''. |
mod_quiz\access_manager::get_popup_options | ( | ) |
Get options required for opening the attempt in a popup window.
array | any options that are required for showing the attempt page in a popup window. |
mod_quiz\access_manager::get_preflight_check_form | ( | moodle_url | $url, |
?int | $attemptid ) |
Build the form required to do the pre-flight checks.
moodle_url | $url | the form action URL. |
int | null | $attemptid | the id of the current attempt, if there is one, otherwise null. |
preflight_check_form | the form. |
|
staticprotected |
Get that names of all the installed rule classes.
array | of class names. |
mod_quiz\access_manager::get_time_left_display | ( | stdClass | $attempt, |
int | $timenow ) |
Compute what should be displayed to the user for time remaining in this attempt.
stdClass | $attempt | the data from the relevant quiz_attempts row. |
int | $timenow | the time to consider as 'now'. |
int|false | the number of seconds remaining for this attempt. False if no limit should be displayed. |
mod_quiz\access_manager::is_finished | ( | int | $numprevattempts, |
$lastattempt ) |
Do any of the rules mean that this student will no be allowed any further attempts at this quiz.
Used, for example, to change the label by the grade displayed on the view page from 'your current grade is' to 'your final grade is'.
int | $numprevattempts | the number of previous attempts this user has made. |
stdClass | false | $lastattempt | information about the user's last completed attempt. |
bool | true if there is no way the user will ever be allowed to attempt this quiz again. |
mod_quiz\access_manager::is_preflight_check_required | ( | ?int | $attemptid | ) |
Is a UI check is required before the user starts/continues their attempt.
int | null | $attemptid | the id of the current attempt, if there is one, otherwise null. |
bool | whether a check is required. |
|
static |
Load the quiz settings and any settings required by the access rules.
We try to do this with a single DB query.
Note that the standard plugins do not use this mechanism, becuase all their settings are stored in the quiz table.
int | $quizid | the quiz id. |
stdClass | mdl_quiz row with extra fields. |
|
static |
Load any settings required by the access rules.
We try to do this with a single DB query.
Note that the standard plugins do not use this mechanism, becuase all their settings are stored in the quiz table.
int | $quizid | the quiz id. |
array | setting value name => value. The value names should all start with the name of the corresponding plugin to avoid collisions. |
mod_quiz\access_manager::make_review_link | ( | stdClass | $attempt, |
$nolongerused, | |||
renderer | $output ) |
Make some text into a link to review the quiz, if that is appropriate.
stdClass | $attempt | the attempt object |
mixed | $nolongerused | not used any more. |
renderer | $output | quiz renderer instance. |
string | some HTML, the $linktext either unmodified or wrapped in a link to the review page. |
|
protected |
Make all the rules relevant to a particular quiz.
quiz_settings | $quizobj | information about the quiz in question. |
int | $timenow | the time that should be considered as 'now'. |
bool | $canignoretimelimits | whether the current user is exempt from time limits by the mod/quiz:ignoretimelimits capability. |
access_rule_base[] | rules that apply to this quiz. |
mod_quiz\access_manager::notify_preflight_check_passed | ( | ?int | $attemptid | ) |
The pre-flight check has passed.
This is a chance to record that fact in some way.
int | null | $attemptid | the id of the current attempt, if there is one, otherwise null. |
mod_quiz\access_manager::prevent_access | ( | ) |
Whether the user should be blocked from starting a new attempt or continuing an attempt now.
If there are any restrictions in force now, return an array of reasons why access should be blocked. If access is OK, return false.
array | An array of reason why access is not allowed, or an empty array (== false) if access should be allowed. |
mod_quiz\access_manager::prevent_new_attempt | ( | int | $numprevattempts, |
$lastattempt ) |
Whether a user should be allowed to start a new attempt at this quiz now.
If there are any restrictions in force now, return an array of reasons why access should be blocked. If access is OK, return false.
int | $numprevattempts | the number of previous attempts this user has made. |
stdClass | false | $lastattempt | information about the user's last completed attempt. if there is not a previous attempt, the false is passed. |
array | an array of reason why access is not allowed. An empty array (== false) if access should be allowed. |
|
static |
Save any submitted settings when the quiz settings form is submitted.
Note that the standard plugins do not use this mechanism because their settings are stored in the quiz table.
stdClass | $quiz | the data from the quiz form, including $quiz->id which is the id of the quiz being saved. |
mod_quiz\access_manager::setup_attempt_page | ( | moodle_page | $page | ) |
Sets up the attempt (review or summary) page with any properties required by the access rules.
moodle_page | $page | the page object to initialise. |
mod_quiz\access_manager::validate_preflight_check | ( | array | $data, |
array | $files, | ||
?int | $attemptid ) |
Run the preflight checks using the given data in all the rules supporting them.
array | $data | passed data for validation |
array | $files | un-used, Moodle seems to not support it anymore |
int | null | $attemptid | the id of the current attempt, if there is one, otherwise null. |
array | of errors, empty array means no errors |
|
static |
Validate the data from any form fields added using {.
array | $errors | the errors found so far. |
array | $data | the submitted form data. |
array | $files | information about any uploaded files. |
mod_quiz_mod_form | $quizform | the quiz form object. |
array\$errors | the updated $errors array. |