Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
mod_quiz\access_manager Class Reference

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

Constructor & Destructor Documentation

◆ __construct()

mod_quiz\access_manager::__construct ( quiz_settings $quizobj,
int $timenow,
bool $canignoretimelimits )

Create an instance for a particular quiz.

Parameters
quiz_settings$quizobjthe quiz settings. The quiz we will be controlling access to.
int$timenowThe time to use as 'now'.
bool$canignoretimelimitsWhether this user is exempt from time limits (has_capability('mod/quiz:ignoretimelimits', ...)).

Member Function Documentation

◆ accumulate_messages()

mod_quiz\access_manager::accumulate_messages ( array $messages,
$new )
protected

Accumulates an array of messages.

Parameters
array$messagesthe current list of messages.
string | array$newthe new messages or messages.
Return values
arraythe updated array of messages.

◆ add_settings_form_fields()

static mod_quiz\access_manager::add_settings_form_fields ( mod_quiz_mod_form $quizform,
MoodleQuickForm $mform )
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.

Parameters
mod_quiz_mod_form$quizformthe quiz settings form that is being built.
MoodleQuickForm$mformthe wrapped MoodleQuickForm.

◆ attempt_must_be_in_popup()

mod_quiz\access_manager::attempt_must_be_in_popup ( )

Is this quiz required to be shown in a popup window?

Return values
booltrue if a popup is required.

◆ back_to_view_page()

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;

Parameters
renderer$outputthe quiz renderer.
string$messageoptional message to output while redirecting.

◆ current_attempt_finished()

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.

◆ delete_settings()

static mod_quiz\access_manager::delete_settings ( stdClass $quiz)
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.

Parameters
stdClass$quizthe data from the database, including $quiz->id which is the id of the quiz being deleted.
Since
Moodle 2.7.1, 2.6.4, 2.5.7

◆ describe_rules()

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.

Return values
arrayan array of description messages which may be empty. It would be sensible to output each one surrounded by <p> tags.

◆ get_active_rule_names()

mod_quiz\access_manager::get_active_rule_names ( )

Get an array of the class names of all the active rules.

Mainly useful for debugging.

Return values
array

◆ get_browser_security_choices()

static mod_quiz\access_manager::get_browser_security_choices ( )
static

The the options for the Browser security settings menu.

Return values
arraykey => lang string.

◆ get_end_time()

mod_quiz\access_manager::get_end_time ( stdClass $attempt)

Compute when the attempt must be submitted.

Parameters
stdClass$attemptthe data from the relevant quiz_attempts row.
Return values
int|falsethe attempt close time. False if there is no limit.

◆ get_load_sql()

static mod_quiz\access_manager::get_load_sql ( int $quizid,
array $rules,
string $basefields )
staticprotected

Build the SQL for loading all the access settings in one go.

Parameters
int$quizidthe quiz id.
array$ruleslist of rule plugins, from {
See also
get_rule_classes()}.
Parameters
string$basefieldsinitial part of the select list.
Return values
arraywith 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 = ''.

◆ get_popup_options()

mod_quiz\access_manager::get_popup_options ( )

Get options required for opening the attempt in a popup window.

Return values
arrayany options that are required for showing the attempt page in a popup window.

◆ get_preflight_check_form()

mod_quiz\access_manager::get_preflight_check_form ( moodle_url $url,
?int $attemptid )

Build the form required to do the pre-flight checks.

Parameters
moodle_url$urlthe form action URL.
int | null$attemptidthe id of the current attempt, if there is one, otherwise null.
Return values
preflight_check_formthe form.

◆ get_rule_classes()

static mod_quiz\access_manager::get_rule_classes ( )
staticprotected

Get that names of all the installed rule classes.

Return values
arrayof class names.

◆ get_time_left_display()

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.

Parameters
stdClass$attemptthe data from the relevant quiz_attempts row.
int$timenowthe time to consider as 'now'.
Return values
int|falsethe number of seconds remaining for this attempt. False if no limit should be displayed.

◆ is_finished()

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

Parameters
int$numprevattemptsthe number of previous attempts this user has made.
stdClass | false$lastattemptinformation about the user's last completed attempt.
Return values
booltrue if there is no way the user will ever be allowed to attempt this quiz again.

◆ is_preflight_check_required()

mod_quiz\access_manager::is_preflight_check_required ( ?int $attemptid)

Is a UI check is required before the user starts/continues their attempt.

Parameters
int | null$attemptidthe id of the current attempt, if there is one, otherwise null.
Return values
boolwhether a check is required.

◆ load_quiz_and_settings()

static mod_quiz\access_manager::load_quiz_and_settings ( int $quizid)
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.

Parameters
int$quizidthe quiz id.
Return values
stdClassmdl_quiz row with extra fields.

◆ load_settings()

static mod_quiz\access_manager::load_settings ( int $quizid)
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.

Parameters
int$quizidthe quiz id.
Return values
arraysetting value name => value. The value names should all start with the name of the corresponding plugin to avoid collisions.

◆ make_review_link()

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.

Parameters
stdClass$attemptthe attempt object
mixed$nolongerusednot used any more.
renderer$outputquiz renderer instance.
Return values
stringsome HTML, the $linktext either unmodified or wrapped in a link to the review page.

◆ make_rules()

mod_quiz\access_manager::make_rules ( quiz_settings $quizobj,
int $timenow,
bool $canignoretimelimits )
protected

Make all the rules relevant to a particular quiz.

Parameters
quiz_settings$quizobjinformation about the quiz in question.
int$timenowthe time that should be considered as 'now'.
bool$canignoretimelimitswhether the current user is exempt from time limits by the mod/quiz:ignoretimelimits capability.
Return values
access_rule_base[]rules that apply to this quiz.

◆ notify_preflight_check_passed()

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.

Parameters
int | null$attemptidthe id of the current attempt, if there is one, otherwise null.

◆ prevent_access()

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.

Return values
arrayAn array of reason why access is not allowed, or an empty array (== false) if access should be allowed.

◆ prevent_new_attempt()

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.

Parameters
int$numprevattemptsthe number of previous attempts this user has made.
stdClass | false$lastattemptinformation about the user's last completed attempt. if there is not a previous attempt, the false is passed.
Return values
arrayan array of reason why access is not allowed. An empty array (== false) if access should be allowed.

◆ save_settings()

static mod_quiz\access_manager::save_settings ( stdClass $quiz)
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.

Parameters
stdClass$quizthe data from the quiz form, including $quiz->id which is the id of the quiz being saved.

◆ setup_attempt_page()

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.

Parameters
moodle_page$pagethe page object to initialise.

◆ validate_preflight_check()

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.

Parameters
array$datapassed data for validation
array$filesun-used, Moodle seems to not support it anymore
int | null$attemptidthe id of the current attempt, if there is one, otherwise null.
Return values
arrayof errors, empty array means no errors
Since
Moodle 3.1

◆ validate_settings_form_fields()

static mod_quiz\access_manager::validate_settings_form_fields ( array $errors,
array $data,
array $files,
mod_quiz_mod_form $quizform )
static

Validate the data from any form fields added using {.

See also
add_settings_form_fields()}.
Parameters
array$errorsthe errors found so far.
array$datathe submitted form data.
array$filesinformation about any uploaded files.
mod_quiz_mod_form$quizformthe quiz form object.
Return values
array\$errorsthe updated $errors array.

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