MDL-70935 mod_quiz: combine 'pass' and 'attemptsexhausted' rules
Custom rules are combined using the AND operator. However, the 'completionpass' and 'completionattemptsexhausted' rules are exceptions because they are combined together with OR, and form a single new rule that then will be combined with the rest of the rules using AND. This commit combines the mentioned rules into a single rule named 'completionpassorattemptsexhausted'.
This commit is contained in:
committed by
Michael Hawkins
parent
1ef67caf2c
commit
e5ac4fd1d9
@@ -186,8 +186,8 @@ $string['completionminattemptserror'] = 'Minimum number of attempts must be lowe
|
||||
$string['completionpass'] = 'Require passing grade';
|
||||
$string['completionpassdesc'] = 'Student must achieve a passing grade to complete this activity';
|
||||
$string['completionpass_help'] = 'If enabled, this activity is considered complete when the student receives a pass grade (as specified in the Grade section of the quiz settings) or higher.';
|
||||
$string['completionpassorattemptsexhausteddesc'] = 'Student must achieve a passing grade, or exhaust all available attempts to complete this activity';
|
||||
$string['completionattemptsexhausted'] = 'Or all available attempts completed';
|
||||
$string['completionattemptsexhausteddesc'] = 'Complete if all available attempts are exhausted';
|
||||
$string['completionattemptsexhausted_help'] = 'Mark quiz complete when the student has exhausted the maximum number of attempts.';
|
||||
$string['configadaptive'] = 'If you choose Yes for this option then the student will be allowed multiple responses to a question even within the same attempt at the quiz.';
|
||||
$string['configattemptsallowed'] = 'Restriction on the number of attempts students are allowed at the quiz.';
|
||||
@@ -1018,3 +1018,6 @@ $string['numattemptsmade'] = '{$a} attempts made on this quiz';
|
||||
$string['reviewofattempt'] = 'Review of attempt {$a}';
|
||||
$string['reviewofpreview'] = 'Review of preview';
|
||||
$string['settingsoverrides'] = 'Settings overrides';
|
||||
|
||||
// Deprecated since Moodle 3.11.
|
||||
$string['completionattemptsexhausteddesc'] = 'Complete if all available attempts are exhausted';
|
||||
|
||||
+31
-24
@@ -1949,8 +1949,6 @@ function quiz_completion_check_passing_grade_or_all_attempts($course, $cm, $user
|
||||
* @throws coding_exception
|
||||
*/
|
||||
function quiz_completion_check_min_attempts($userid, $quiz) {
|
||||
global $DB;
|
||||
|
||||
if (empty($quiz->completionminattempts)) {
|
||||
return true;
|
||||
}
|
||||
@@ -2174,7 +2172,7 @@ function quiz_get_coursemodule_info($coursemodule) {
|
||||
global $DB;
|
||||
|
||||
$dbparams = ['id' => $coursemodule->instance];
|
||||
$fields = 'id, name, intro, introformat, completionattemptsexhausted, completionpass';
|
||||
$fields = 'id, name, intro, introformat, completionattemptsexhausted, completionpass, completionminattempts';
|
||||
if (!$quiz = $DB->get_record('quiz', $dbparams, $fields)) {
|
||||
return false;
|
||||
}
|
||||
@@ -2189,8 +2187,16 @@ function quiz_get_coursemodule_info($coursemodule) {
|
||||
|
||||
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
|
||||
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
|
||||
$result->customdata['customcompletionrules']['completionattemptsexhausted'] = $quiz->completionattemptsexhausted;
|
||||
$result->customdata['customcompletionrules']['completionpass'] = $quiz->completionpass;
|
||||
if ($quiz->completionpass || $quiz->completionattemptsexhausted) {
|
||||
$result->customdata['customcompletionrules']['completionpassorattemptsexhausted'] = [
|
||||
'completionpass' => $quiz->completionpass,
|
||||
'completionattemptsexhausted' => $quiz->completionattemptsexhausted,
|
||||
];
|
||||
} else {
|
||||
$result->customdata['customcompletionrules']['completionpassorattemptsexhausted'] = [];
|
||||
}
|
||||
|
||||
$result->customdata['customcompletionrules']['completionminattempts'] = $quiz->completionminattempts;
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -2210,27 +2216,28 @@ function mod_quiz_get_completion_active_rule_descriptions($cm) {
|
||||
}
|
||||
|
||||
$descriptions = [];
|
||||
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
|
||||
switch ($key) {
|
||||
case 'completionattemptsexhausted':
|
||||
if (!empty($val)) {
|
||||
$descriptions[] = get_string('completionattemptsexhausteddesc', 'quiz');
|
||||
}
|
||||
break;
|
||||
case 'completionpass':
|
||||
if (!empty($val)) {
|
||||
$descriptions[] = get_string('completionpassdesc', 'quiz', format_time($val));
|
||||
}
|
||||
break;
|
||||
case 'completionminattempts':
|
||||
if (!empty($val)) {
|
||||
$descriptions[] = get_string('completionminattemptsdesc', 'quiz', $val);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
$rules = $cm->customdata['customcompletionrules'];
|
||||
|
||||
if (!empty($rules['completionpassorattemptsexhausted'])) {
|
||||
if (!empty($rules['completionpassorattemptsexhausted']['completionattemptsexhausted'])) {
|
||||
$descriptions[] = get_string('completionpassorattemptsexhausteddesc', 'quiz');
|
||||
} else if (!empty($rules['completionpassorattemptsexhausted']['completionpass'])) {
|
||||
$descriptions[] = get_string('completionpassdesc', 'quiz',
|
||||
format_time($rules['completionpassorattemptsexhausted']['completionpass']));
|
||||
}
|
||||
} else {
|
||||
// Fallback.
|
||||
if (!empty($rules['completionattemptsexhausted'])) {
|
||||
$descriptions[] = get_string('completionpassorattemptsexhausteddesc', 'quiz');
|
||||
} else if (!empty($rules['completionpass'])) {
|
||||
$descriptions[] = get_string('completionpassdesc', 'quiz', format_time($rules['completionpass']));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($rules['completionminattempts'])) {
|
||||
$descriptions[] = get_string('completionminattemptsdesc', 'quiz', $rules['completionminattempts']);
|
||||
}
|
||||
|
||||
return $descriptions;
|
||||
}
|
||||
|
||||
|
||||
@@ -1134,8 +1134,7 @@ class mod_quiz_lib_testcase extends advanced_testcase {
|
||||
$moddefaults->completion = 2;
|
||||
|
||||
$activeruledescriptions = [
|
||||
get_string('completionattemptsexhausteddesc', 'quiz'),
|
||||
get_string('completionpassdesc', 'quiz'),
|
||||
get_string('completionpassorattemptsexhausteddesc', 'quiz'),
|
||||
];
|
||||
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions($cm1), $activeruledescriptions);
|
||||
$this->assertEquals(mod_quiz_get_completion_active_rule_descriptions($cm2), []);
|
||||
|
||||
Reference in New Issue
Block a user