This class keeps track of the various access rules that apply to a particular quiz, with convinient methods for seeing whether access is allowed.
More...
|
| __construct ($quizobj, $timenow, $canignoretimelimits) |
| Create an instance for a particular quiz. More...
|
|
| attempt_must_be_in_popup () |
|
| back_to_view_page ($output, $message='') |
| Send the user back to the quiz view page. More...
|
|
| current_attempt_finished () |
| Inform the rules that the current attempt is finished. More...
|
|
| 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. More...
|
|
| get_active_rule_names () |
|
| get_end_time ($attempt) |
| Compute when the attempt must be submitted. More...
|
|
| get_popup_options () |
|
| get_preflight_check_form (moodle_url $url, $attemptid) |
| Build the form required to do the pre-flight checks. More...
|
|
| get_time_left_display ($attempt, $timenow) |
| Compute what should be displayed to the user for time remaining in this attempt. More...
|
|
| is_finished ($numprevattempts, $lastattempt) |
| Do any of the rules mean that this student will no be allowed any further attempts at this quiz. More...
|
|
| is_preflight_check_required ($attemptid) |
|
| make_review_link ($attempt, $reviewoptions, $output) |
| Make some text into a link to review the quiz, if that is appropriate. More...
|
|
| notify_preflight_check_passed ($attemptid) |
| The pre-flight check has passed. More...
|
|
| prevent_access () |
| Whether the user should be blocked from starting a new attempt or continuing an attempt now. More...
|
|
| prevent_new_attempt ($numprevattempts, $lastattempt) |
| Whether or not a user should be allowed to start a new attempt at this quiz now. More...
|
|
| setup_attempt_page ($page) |
| Sets up the attempt (review or summary) page with any properties required by the access rules. More...
|
|
| validate_preflight_check ($data, $files, $attemptid) |
| Run the preflight checks using the given data in all the rules supporting them. More...
|
|
This class keeps track of the various access rules that apply to a particular quiz, with convinient methods for seeing whether access is allowed.
- Copyright
- 2009 Tim Hunt
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- Since
- Moodle 2.2
◆ __construct()
quiz_access_manager::__construct |
( |
|
$quizobj, |
|
|
|
$timenow, |
|
|
|
$canignoretimelimits |
|
) |
| |
Create an instance for a particular quiz.
- Parameters
-
object | $quizobj | An instance of the class quiz from attemptlib.php. 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', ...)). |
◆ accumulate_messages()
quiz_access_manager::accumulate_messages |
( |
|
$messages, |
|
|
|
$new |
|
) |
| |
|
protected |
Accumulates an array of messages.
- Parameters
-
array | $messages | the current list of messages. |
string | array | $new | the new messages or messages. |
- Return values
-
array | the updated array of messages. |
◆ add_settings_form_fields()
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
-
◆ attempt_must_be_in_popup()
quiz_access_manager::attempt_must_be_in_popup |
( |
| ) |
|
- Return values
-
bolean | if this quiz should only be shown to students in a popup window. |
◆ back_to_view_page()
quiz_access_manager::back_to_view_page |
( |
|
$output, |
|
|
|
$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
-
mod_quiz_renderer | $output | the quiz renderer. |
string | $message | optional message to output while redirecting. |
◆ current_attempt_finished()
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 quiz_access_manager::delete_settings |
( |
|
$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
-
object | $quiz | the 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()
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
-
array | an array of description messages which may be empty. It would be sensible to output each one surrounded by <p> tags. |
◆ get_active_rule_names()
quiz_access_manager::get_active_rule_names |
( |
| ) |
|
- Return values
-
array | the class names of all the active rules. Mainly useful for debugging. |
◆ get_browser_security_choices()
static quiz_access_manager::get_browser_security_choices |
( |
| ) |
|
|
static |
The the options for the Browser security settings menu.
- Return values
-
◆ get_end_time()
quiz_access_manager::get_end_time |
( |
|
$attempt | ) |
|
Compute when the attempt must be submitted.
- Parameters
-
object | $attempt | the data from the relevant quiz_attempts row. |
- Return values
-
int|false | the attempt close time. False if there is no limit. |
◆ get_load_sql()
static quiz_access_manager::get_load_sql |
( |
|
$quizid, |
|
|
|
$rules, |
|
|
|
$basefields |
|
) |
| |
|
staticprotected |
Build the SQL for loading all the access settings in one go.
- Parameters
-
int | $quizid | the quiz id. |
string | $basefields | initial part of the select list. |
- Return values
-
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 = ''. |
◆ get_popup_options()
quiz_access_manager::get_popup_options |
( |
| ) |
|
- Return values
-
array | any options that are required for showing the attempt page in a popup window. |
◆ get_preflight_check_form()
quiz_access_manager::get_preflight_check_form |
( |
moodle_url |
$url, |
|
|
|
$attemptid |
|
) |
| |
Build the form required to do the pre-flight checks.
- Parameters
-
moodle_url | $url | the form action URL. |
int | null | $attemptid | the id of the current attempt, if there is one, otherwise null. |
- Return values
-
◆ get_rule_classes()
static quiz_access_manager::get_rule_classes |
( |
| ) |
|
|
staticprotected |
- Return values
-
array | of all the installed rule class names. |
◆ get_time_left_display()
quiz_access_manager::get_time_left_display |
( |
|
$attempt, |
|
|
|
$timenow |
|
) |
| |
Compute what should be displayed to the user for time remaining in this attempt.
- Parameters
-
object | $attempt | the data from the relevant quiz_attempts row. |
int | $timenow | the time to consider as 'now'. |
- Return values
-
int|false | the number of seconds remaining for this attempt. False if no limit should be displayed. |
◆ is_finished()
quiz_access_manager::is_finished |
( |
|
$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 | $numattempts | the number of previous attempts this user has made. |
object | $lastattempt | information about the user's last completed attempt. |
- Return values
-
bool | true if there is no way the user will ever be allowed to attempt this quiz again. |
◆ is_preflight_check_required()
quiz_access_manager::is_preflight_check_required |
( |
|
$attemptid | ) |
|
- Parameters
-
int | null | $attemptid | the id of the current attempt, if there is one, otherwise null. |
- Return values
-
bool | whether a check is required before the user starts/continues their attempt. |
◆ load_quiz_and_settings()
static quiz_access_manager::load_quiz_and_settings |
( |
|
$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
-
- Return values
-
object | mdl_quiz row with extra fields. |
◆ load_settings()
static quiz_access_manager::load_settings |
( |
|
$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
-
- Return values
-
array | setting value name => value. The value names should all start with the name of the corresponding plugin to avoid collisions. |
◆ make_review_link()
quiz_access_manager::make_review_link |
( |
|
$attempt, |
|
|
|
$reviewoptions, |
|
|
|
$output |
|
) |
| |
Make some text into a link to review the quiz, if that is appropriate.
- Parameters
-
string | $linktext | some text. |
object | $attempt | the attempt object |
- Return values
-
string | some HTML, the $linktext either unmodified or wrapped in a link to the review page. |
◆ make_rules()
quiz_access_manager::make_rules |
( |
|
$quizobj, |
|
|
|
$timenow, |
|
|
|
$canignoretimelimits |
|
) |
| |
|
protected |
Make all the rules relevant to a particular quiz.
- Parameters
-
quiz | $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. |
- Return values
-
◆ notify_preflight_check_passed()
quiz_access_manager::notify_preflight_check_passed |
( |
|
$attemptid | ) |
|
The pre-flight check has passed.
This is a chance to record that fact in some way.
- Parameters
-
int | null | $attemptid | the id of the current attempt, if there is one, otherwise null. |
◆ prevent_access()
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
-
mixed | An array of reason why access is not allowed, or an empty array (== false) if access should be allowed. |
◆ prevent_new_attempt()
quiz_access_manager::prevent_new_attempt |
( |
|
$numprevattempts, |
|
|
|
$lastattempt |
|
) |
| |
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.
- Parameters
-
int | $numattempts | the number of previous attempts this user has made. |
object | false | $lastattempt | information about the user's last completed attempt. if there is not a previous attempt, the false is passed. |
- Return values
-
mixed | An array of reason why access is not allowed, or an empty array (== false) if access should be allowed. |
◆ save_settings()
static quiz_access_manager::save_settings |
( |
|
$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
-
object | $quiz | the data from the quiz form, including $quiz->id which is the id of the quiz being saved. |
◆ setup_attempt_page()
quiz_access_manager::setup_attempt_page |
( |
|
$page | ) |
|
Sets up the attempt (review or summary) page with any properties required by the access rules.
- Parameters
-
◆ validate_preflight_check()
quiz_access_manager::validate_preflight_check |
( |
|
$data, |
|
|
|
$files, |
|
|
|
$attemptid |
|
) |
| |
Run the preflight checks using the given data in all the rules supporting them.
- Parameters
-
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. |
- Return values
-
array | of errors, empty array means no erros |
- Since
- Moodle 3.1
◆ validate_settings_form_fields()
static quiz_access_manager::validate_settings_form_fields |
( |
array |
$errors, |
|
|
array |
$data, |
|
|
|
$files, |
|
|
mod_quiz_mod_form |
$quizform |
|
) |
| |
|
static |
Validate the data from any form fields added using add_settings_form_fields().
- Parameters
-
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. |
- Return values
-
array::$errors | the updated $errors array. |
The documentation for this class was generated from the following file: