MDL-37993 Quiz: completion upon all passing grade or attempts exhausted

This patch adds completion options to Quiz similar to what is available in scorm.
One can have the quiz marked complete when either a passing grade is achieved or
all attempts are used up. This will allow a quiz to complete when the user "passes
or fails".  (Where "fail" means "using up all attempts without passing".)
This commit is contained in:
Ray Morris 2014-05-30 11:39:42 -05:00
parent 5fd0df97c5
commit 349c930343
10 changed files with 300 additions and 2 deletions

View file

@ -585,4 +585,37 @@ class mod_quiz_mod_form extends moodleform_mod {
return $errors;
}
/**
* Display module-specific activity completion rules.
* Part of the API defined by moodleform_mod
* @return array Array of string IDs of added items, empty array if none
*/
public function add_completion_rules() {
$mform = $this->_form;
$items = array();
$group = array();
$group[] = $mform->createElement('advcheckbox', 'completionpass', null, get_string('completionpass', 'quiz'),
array('group' => 'cpass'));
$group[] = $mform->createElement('advcheckbox', 'completionattemptsexhausted', null,
get_string('completionattemptsexhausted', 'quiz'),
array('group' => 'cattempts'));
$mform->disabledIf('completionattemptsexhausted', 'completionpass', 'notchecked');
$mform->addGroup($group, 'completionpassgroup', get_string('completionpass', 'quiz'), '   ', false);
$mform->addHelpButton('completionpassgroup', 'completionpass', 'quiz');
$items[] = 'completionpassgroup';
return $items;
}
/**
* Called during validation. Indicates whether a module-specific completion rule is selected.
*
* @param array $data Input data (not yet validated)
* @return bool True if one or more rules is enabled, false if none are.
*/
public function completion_rule_enabled($data) {
return !empty($data['completionattemptsexhausted']) || !empty($data['completionpass']);
}
}