MDL-78670 mod_quiz: Add offline atempt rule for sequential navigation

This commit is contained in:
Rodrigo Mady 2023-08-15 21:48:27 -03:00
parent 94ad185d09
commit 3089485e57
2 changed files with 8 additions and 5 deletions

View File

@ -27,10 +27,10 @@ defined('MOODLE_INTERNAL') || die();
$string['allowofflineattempts'] = 'Allow quiz to be attempted offline using the mobile app';
$string['allowofflineattempts_help'] = 'If enabled, a mobile app user can download the quiz and attempt it offline.
Note: It is not possible for a quiz to be attempted offline if it has a time limit, or requires a network address, or uses any question behaviour other than deferred feedback (with or without CBM).';
Note: It is not possible for a quiz to be attempted offline if it has a time limit, or requires a network address, or uses any question behaviour other than deferred feedback (with or without CBM), or uses sequential navigation.';
$string['confirmdatasaved'] = 'I confirm that I do not have any unsaved work on a mobile device.';
$string['mobileapp'] = 'Mobile app';
$string['offlineattemptserror'] = 'It is not possible for a quiz to be attempted offline if it has a time limit, or requires a network address, or uses any question behaviour other than deferred feedback (with or without CBM).';
$string['offlineattemptserror'] = 'It is not possible for a quiz to be attempted offline if it has a time limit, or requires a network address, or uses any question behaviour other than deferred feedback (with or without CBM), or uses sequential navigation.';
$string['offlinedatamessage'] = 'You have worked on this attempt using a mobile device. Data was last saved to this site {$a} ago.';
$string['pleaseconfirm'] = 'Please check and confirm that you do not have any unsaved work.';
$string['pluginname'] = 'Offline attempts access rule';

View File

@ -114,6 +114,7 @@ class quizaccess_offlineattempts extends quiz_access_rule_base {
$mform->setAdvanced('allowofflineattempts');
$mform->disabledIf('allowofflineattempts', 'timelimit[number]', 'neq', 0);
$mform->disabledIf('allowofflineattempts', 'subnet', 'neq', '');
$mform->disabledIf('allowofflineattempts', 'navmethod', 'eq', 'sequential');
}
}
@ -126,9 +127,11 @@ class quizaccess_offlineattempts extends quiz_access_rule_base {
// - The quiz uses a timer.
// - The quiz is restricted by subnet.
// - The question behaviour is not deferred feedback or deferred feedback with CBM.
if (!empty($data['allowofflineattempts']) and
(!empty($data['timelimit']) or !empty($data['subnet']) or
($data['preferredbehaviour'] != 'deferredfeedback' and $data['preferredbehaviour'] != 'deferredcbm'))) {
// - The quiz uses the sequential navigation.
if (!empty($data['allowofflineattempts']) &&
(!empty($data['timelimit']) || !empty($data['subnet']) ||
$data['navmethod'] === 'sequential' ||
($data['preferredbehaviour'] != 'deferredfeedback' && $data['preferredbehaviour'] != 'deferredcbm'))) {
$errors['allowofflineattempts'] = get_string('offlineattemptserror', 'quizaccess_offlineattempts');
}