Differences Between: [Versions 310 and 402] [Versions 310 and 403]
Classes to enforce the various access rules that can apply to a quiz.
Copyright: | 2009 Tim Hunt |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 562 lines (20 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
quiz_access_manager:: (29 methods):
__construct()
make_rules()
get_rule_classes()
add_settings_form_fields()
get_browser_security_choices()
validate_settings_form_fields()
save_settings()
delete_settings()
get_load_sql()
load_settings()
load_quiz_and_settings()
get_active_rule_names()
accumulate_messages()
describe_rules()
prevent_new_attempt()
prevent_access()
is_preflight_check_required()
get_preflight_check_form()
notify_preflight_check_passed()
current_attempt_finished()
is_finished()
setup_attempt_page()
get_end_time()
get_time_left_display()
attempt_must_be_in_popup()
get_popup_options()
back_to_view_page()
make_review_link()
validate_preflight_check()
Class: quiz_access_manager - X-Ref
This class keeps track of the various access rules that apply to a particular__construct($quizobj, $timenow, $canignoretimelimits) X-Ref |
Create an instance for a particular quiz. param: object $quizobj An instance of the class quiz from attemptlib.php. param: int $timenow The time to use as 'now'. param: bool $canignoretimelimits Whether this user is exempt from time |
make_rules($quizobj, $timenow, $canignoretimelimits) X-Ref |
Make all the rules relevant to a particular quiz. param: quiz $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: array of {@link quiz_access_rule_base}s. |
get_rule_classes() X-Ref |
return: array of all the installed rule 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, $files, mod_quiz_mod_form $quizform) X-Ref |
Validate the data from any form fields added using {@link 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($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: object $quiz the data from the quiz form, including $quiz->id |
delete_settings($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: object $quiz the data from the database, including $quiz->id |
get_load_sql($quizid, $rules, $basefields) X-Ref |
Build the SQL for loading all the access settings in one go. param: int $quizid the quiz id. param: string $basefields initial part of the select list. return: array with two elements, the sql and the placeholder values. |
load_settings($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($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: object mdl_quiz row with extra fields. |
get_active_rule_names() X-Ref |
return: array the class names of all the active rules. Mainly useful for |
accumulate_messages($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($numprevattempts, $lastattempt) X-Ref |
Whether or not 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 $numattempts the number of previous attempts this user has made. param: object|false $lastattempt information about the user's last completed attempt. return: mixed An array of reason why access is not allowed, or 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: mixed An array of reason why access is not allowed, or an empty array |
is_preflight_check_required($attemptid) X-Ref |
param: int|null $attemptid the id of the current attempt, if there is one, return: bool whether a check is required before the user starts/continues |
get_preflight_check_form(moodle_url $url, $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: mod_quiz_preflight_check_form the form. |
notify_preflight_check_passed($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($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 $numattempts the number of previous attempts this user has made. param: object $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($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($attempt) X-Ref |
Compute when the attempt must be submitted. param: object $attempt the data from the relevant quiz_attempts row. return: int|false the attempt close time. |
get_time_left_display($attempt, $timenow) X-Ref |
Compute what should be displayed to the user for time remaining in this attempt. param: object $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 |
return: bolean if this quiz should only be shown to students in a popup window. |
get_popup_options() X-Ref |
return: array any options that are required for showing the attempt page |
back_to_view_page($output, $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: mod_quiz_renderer $output the quiz renderer. param: string $message optional message to output while redirecting. |
make_review_link($attempt, $reviewoptions, $output) X-Ref |
Make some text into a link to review the quiz, if that is appropriate. param: string $linktext some text. param: object $attempt the attempt object return: string some HTML, the $linktext either unmodified or wrapped in a |
validate_preflight_check($data, $files, $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 erros |