Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

File Size: 586 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: access_manager  - X-Ref

This class aggregates the access rules that apply to a particular quiz.

This provides a convenient API which other parts of the quiz code can use
to interact with the access rules.

__construct(quiz_settings $quizobj, int $timenow, bool $canignoretimelimits)   X-Ref
Create an instance for a particular quiz.

param: quiz_settings $quizobj the quiz settings.
param: int $timenow The time to use as 'now'.
param: bool $canignoretimelimits Whether this user is exempt from time

make_rules(quiz_settings $quizobj, int $timenow, bool $canignoretimelimits)   X-Ref
Make all the rules relevant to a particular quiz.

param: quiz_settings $quizobj information about the quiz in question.
param: int $timenow the time that should be considered as 'now'.
param: bool $canignoretimelimits whether the current user is exempt from
return: access_rule_base[] rules that apply to this quiz.

get_rule_classes()   X-Ref
Get that names of all the installed rule classes.

return: array of class names.

add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform)   X-Ref
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.

param: mod_quiz_mod_form $quizform the quiz settings form that is being built.
param: MoodleQuickForm $mform the wrapped MoodleQuickForm.

get_browser_security_choices()   X-Ref
The the options for the Browser security settings menu.

return: array key => lang string.

validate_settings_form_fields(array $errors,array $data, array $files, mod_quiz_mod_form $quizform)   X-Ref
Validate the data from any form fields added using {@see add_settings_form_fields()}.

param: array $errors the errors found so far.
param: array $data the submitted form data.
param: array $files information about any uploaded files.
param: mod_quiz_mod_form $quizform the quiz form object.
return: array $errors the updated $errors array.

save_settings(stdClass $quiz)   X-Ref
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.

param: stdClass $quiz the data from the quiz form, including $quiz->id

delete_settings(stdClass $quiz)   X-Ref
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.

param: stdClass $quiz the data from the database, including $quiz->id

get_load_sql(int $quizid, array $rules, string $basefields)   X-Ref
Build the SQL for loading all the access settings in one go.

param: int $quizid the quiz id.
param: array $rules list of rule plugins, from {@see get_rule_classes()}.
param: string $basefields initial part of the select list.
return: array with two elements, the sql and the placeholder values.

load_settings(int $quizid)   X-Ref
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.

param: int $quizid the quiz id.
return: array setting value name => value. The value names should all

load_quiz_and_settings(int $quizid)   X-Ref
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.

param: int $quizid the quiz id.
return: stdClass mdl_quiz row with extra fields.

get_active_rule_names()   X-Ref
Get an array of the class names of all the active rules.

Mainly useful for debugging.

return: array

accumulate_messages(array $messages, $new)   X-Ref
Accumulates an array of messages.

param: array $messages the current list of messages.
param: string|array $new the new messages or messages.
return: array the updated array of messages.

describe_rules()   X-Ref
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: array an array of description messages which may be empty. It

prevent_new_attempt(int $numprevattempts, $lastattempt)   X-Ref
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.

param: int $numprevattempts the number of previous attempts this user has made.
param: stdClass|false $lastattempt information about the user's last completed attempt.
return: array an array of reason why access is not allowed. An empty array

prevent_access()   X-Ref
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: array An array of reason why access is not allowed, or an empty array

is_preflight_check_required(?int $attemptid)   X-Ref
Is a UI check is required before the user starts/continues their attempt.

param: int|null $attemptid the id of the current attempt, if there is one,
return: bool whether a check is required.

get_preflight_check_form(moodle_url $url, ?int $attemptid)   X-Ref
Build the form required to do the pre-flight checks.

param: moodle_url $url the form action URL.
param: int|null $attemptid the id of the current attempt, if there is one,
return: preflight_check_form the form.

notify_preflight_check_passed(?int $attemptid)   X-Ref
The pre-flight check has passed. This is a chance to record that fact in some way.

param: int|null $attemptid the id of the current attempt, if there is one,

current_attempt_finished()   X-Ref
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.

is_finished(int $numprevattempts, $lastattempt)   X-Ref
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'.

param: int $numprevattempts the number of previous attempts this user has made.
param: stdClass|false $lastattempt information about the user's last completed attempt.
return: bool true if there is no way the user will ever be allowed to attempt

setup_attempt_page(moodle_page $page)   X-Ref
Sets up the attempt (review or summary) page with any properties required
by the access rules.

param: moodle_page $page the page object to initialise.

get_end_time(stdClass $attempt)   X-Ref
Compute when the attempt must be submitted.

param: stdClass $attempt the data from the relevant quiz_attempts row.
return: int|false the attempt close time. False if there is no limit.

get_time_left_display(stdClass $attempt, int $timenow)   X-Ref
Compute what should be displayed to the user for time remaining in this attempt.

param: stdClass $attempt the data from the relevant quiz_attempts row.
param: int $timenow the time to consider as 'now'.
return: int|false the number of seconds remaining for this attempt.

attempt_must_be_in_popup()   X-Ref
Is this quiz required to be shown in a popup window?

return: bool true if a popup is required.

get_popup_options()   X-Ref
Get options required for opening the attempt in a popup window.

return: array any options that are required for showing the attempt page

back_to_view_page(renderer $output, string $message = '')   X-Ref
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;

param: renderer $output the quiz renderer.
param: string $message optional message to output while redirecting.

make_review_link(stdClass $attempt, $nolongerused, renderer $output)   X-Ref
Make some text into a link to review the quiz, if that is appropriate.

param: stdClass $attempt the attempt object
param: mixed $nolongerused not used any more.
param: renderer $output quiz renderer instance.
return: string some HTML, the $linktext either unmodified or wrapped in a

validate_preflight_check(array $data, array $files, ?int $attemptid)   X-Ref
Run the preflight checks using the given data in all the rules supporting them.

param: array $data passed data for validation
param: array $files un-used, Moodle seems to not support it anymore
param: int|null $attemptid the id of the current attempt, if there is one,
return: array of errors, empty array means no errors