Moodle  2.2.1
http://www.collinsharper.com
quiz_access_rule_base Class Reference
Inheritance diagram for quiz_access_rule_base:

Public Member Functions

 __construct ($quizobj, $timenow)
 prevent_new_attempt ($numprevattempts, $lastattempt)
 prevent_access ()
 is_preflight_check_required ($attemptid)
 add_preflight_check_form_fields (mod_quiz_preflight_check_form $quizform, MoodleQuickForm $mform, $attemptid)
 validate_preflight_check ($data, $files, $errors, $attemptid)
 notify_preflight_check_passed ($attemptid)
 current_attempt_finished ()
 description ()
 is_finished ($numprevattempts, $lastattempt)
 time_left ($attempt, $timenow)
 attempt_must_be_in_popup ()
 get_popup_options ()
 setup_attempt_page ($page)
 get_superceded_rules ()

Static Public Member Functions

static make (quiz $quizobj, $timenow, $canignoretimelimits)
static add_settings_form_fields (mod_quiz_mod_form $quizform, MoodleQuickForm $mform)
static get_browser_security_choices ()
static save_settings ($quiz)
static get_settings_sql ($quizid)
static get_extra_settings ($quizid)

Protected Attributes

 $quiz
 $quizobj
 $timenow

Detailed Description

A base class that defines the interface for the various quiz access rules. Most of the methods are defined in a slightly unnatural way because we either want to say that access is allowed, or explain the reason why it is block. Therefore instead of is_access_allowed(...) we have prevent_access(...) that return false if access is permitted, or a string explanation (which is treated as true) if access should be blocked. Slighly unnatural, but acutally the easist way to implement this.

Definition at line 44 of file accessrulebase.php.


Constructor & Destructor Documentation

__construct ( quizobj,
timenow 
)

Create an instance of this rule for a particular quiz.

Parameters:
quiz$quizobjinformation about the quiz in question.
int$timenowthe time that should be considered as 'now'.

Definition at line 57 of file accessrulebase.php.


Member Function Documentation

Add any field you want to pre-flight check form. You should only do something here if is_preflight_check_required() returned true.

Parameters:
mod_quiz_preflight_check_form$quizformthe form being built.
MoodleQuickForm$mformThe wrapped MoodleQuickForm.
int | null$attemptidthe id of the current attempt, if there is one, otherwise null.

Reimplemented in quizaccess_password.

Definition at line 116 of file accessrulebase.php.

static add_settings_form_fields ( mod_quiz_mod_form quizform,
MoodleQuickForm mform 
) [static]

Add any fields that this rule requires to the quiz settings form. This method is called from mod_quiz_mod_form::definition(), while the security seciton is being built.

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

Definition at line 240 of file accessrulebase.php.

Returns:
boolean whether this rule requires that the attemp (and review) pages must be displayed in a pop-up window.

Reimplemented in quizaccess_securewindow.

Definition at line 197 of file accessrulebase.php.

This is called when the current attempt at the quiz is finished. This is used, for example by the password rule, to clear the flag in the session.

Reimplemented in quizaccess_password.

Definition at line 152 of file accessrulebase.php.

Information, such as might be shown on the quiz view page, relating to this restriction. There is no obligation to return anything. If it is not appropriate to tell students about this rule, then just return ''.

Returns:
mixed a message, or array of messages, explaining the restriction (may be '' if no message is appropriate).

Reimplemented in quizaccess_safebrowser, quizaccess_timelimit, quizaccess_numattempts, quizaccess_password, and quizaccess_openclosedate.

Definition at line 163 of file accessrulebase.php.

static get_browser_security_choices ( ) [static]
Returns:
array key => lang string any choices to add to the quiz Browser security settings menu.

Reimplemented in quizaccess_securewindow, and quizaccess_safebrowser.

Definition at line 249 of file accessrulebase.php.

static get_extra_settings ( quizid) [static]

You can use this method to load any extra settings your plugin has that cannot be loaded efficiently with get_settings_sql().

Parameters:
int$quizidthe quiz id.
Returns:
array setting value name => value. The value names should all start with the name of your plugin to avoid collisions.

Definition at line 294 of file accessrulebase.php.

Returns:
array any options that are required for showing the attempt page in a popup window.

Reimplemented in quizaccess_securewindow.

Definition at line 205 of file accessrulebase.php.

static get_settings_sql ( quizid) [static]

Return the bits of SQL needed to load all the settings from all the access plugins in one DB query. The easiest way to understand what you need to do here is probalby to read the code of quiz_access_manager::load_settings().

If you have some settings that cannot be loaded in this way, then you can use the get_extra_settings() method instead, but that has performance implications.

Parameters:
int$quizidthe id of the quiz we are loading settings for. This can also be accessed as quiz.id in the SQL. (quiz is a table alisas for {quiz}.)
Returns:
array with three elements: 1. fields: any fields to add to the select list. These should be alised if neccessary so that the field name starts the name of the plugin. 2. joins: any joins (should probably be LEFT JOINS) with other tables that are needed. 3. params: array of placeholder values that are needed by the SQL. You must used named placeholders, and the placeholder names should start with the plugin name, to avoid collisions.

Definition at line 283 of file accessrulebase.php.

It is possible for one rule to override other rules.

The aim is that third-party rules should be able to replace sandard rules if they want. See, for example MDL-13592.

Returns:
array plugin names of other rules that this one replaces. For example array('ipaddress', 'password').

Definition at line 229 of file accessrulebase.php.

is_finished ( numprevattempts,
lastattempt 
)

If this rule can determine that this user will never be allowed another attempt at this quiz, then return true. This is used so we can know whether to display a final grade on the view page. This will only be called if there is not a currently active attempt for this user.

Parameters:
int$numattemptsthe number of previous attempts this user has made.
object$lastattemptinformation about the user's last completed attempt.
Returns:
bool true if this rule means that this user will never be allowed another attempt at this quiz.

Reimplemented in quizaccess_delaybetweenattempts, quizaccess_openclosedate, and quizaccess_numattempts.

Definition at line 177 of file accessrulebase.php.

is_preflight_check_required ( attemptid)
Parameters:
int | null$attemptidthe id of the current attempt, if there is one, otherwise null.
Returns:
bool whether a check is required before the user starts/continues their attempt.

Reimplemented in quizaccess_password.

Definition at line 103 of file accessrulebase.php.

static make ( quiz quizobj,
timenow,
canignoretimelimits 
) [static]

Return an appropriately configured instance of this rule, if it is applicable to the given quiz, otherwise return null.

Parameters:
quiz$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.
Returns:
quiz_access_rule_base|null the rule, if applicable, else null.

Reimplemented in quizaccess_securewindow, quizaccess_timelimit, quizaccess_delaybetweenattempts, quizaccess_ipaddress, quizaccess_numattempts, quizaccess_openclosedate, quizaccess_password, and quizaccess_safebrowser.

Definition at line 72 of file accessrulebase.php.

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.

Reimplemented in quizaccess_password.

Definition at line 144 of file accessrulebase.php.

Whether the user should be blocked from starting a new attempt or continuing an attempt now.

Returns:
string false if access should be allowed, a message explaining the reason if access should be prevented.

Reimplemented in quizaccess_openclosedate, quizaccess_safebrowser, and quizaccess_ipaddress.

Definition at line 93 of file accessrulebase.php.

prevent_new_attempt ( numprevattempts,
lastattempt 
)

Whether or not a user should be allowed to start a new attempt at this quiz now.

Parameters:
int$numattemptsthe number of previous attempts this user has made.
object$lastattemptinformation about the user's last completed attempt.
Returns:
string false if access should be allowed, a message explaining the reason if access should be prevented.

Reimplemented in quizaccess_numattempts, and quizaccess_delaybetweenattempts.

Definition at line 83 of file accessrulebase.php.

static save_settings ( quiz) [static]

Save any submitted settings when the quiz settings form is submitted. This is called from quiz_after_add_or_update() in lib.php.

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

Definition at line 259 of file accessrulebase.php.

setup_attempt_page ( page)

Sets up the attempt (review or summary) page with any special extra properties required by this rule. securewindow rule is an example of where this is used.

Parameters:
moodle_page$pagethe page object to initialise.

Reimplemented in quizaccess_securewindow, and quizaccess_safebrowser.

Definition at line 216 of file accessrulebase.php.

time_left ( attempt,
timenow 
)

If, because of this rule, the user has to finish their attempt by a certain time, you should override this method to return the amount of time left in seconds.

Parameters:
object$attemptthe current attempt
int$timenowthe time now. We don't use $this->timenow, so we can give the user a more accurate indication of how much time is left.
Returns:
mixed false if there is no deadline, of the time left in seconds if there is one.

Reimplemented in quizaccess_openclosedate, and quizaccess_timelimit.

Definition at line 189 of file accessrulebase.php.

validate_preflight_check ( data,
files,
errors,
attemptid 
)

Validate the pre-flight check form submission. You should only do something here if is_preflight_check_required() returned true.

If the form validates, the user will be allowed to continue.

Parameters:
array$datathe submitted form data.
array$filesany files in the submission.
array$errorsthe list of validation errors that is being built up.
int | null$attemptidthe id of the current attempt, if there is one, otherwise null.
Returns:
array the update $errors array;

Reimplemented in quizaccess_password.

Definition at line 134 of file accessrulebase.php.


Field Documentation

$quiz [protected]

Definition at line 46 of file accessrulebase.php.

$quizobj [protected]

Definition at line 48 of file accessrulebase.php.

$timenow [protected]

Definition at line 50 of file accessrulebase.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations