MDL-23919 mod_data: small corrections to completion form element
This commit is contained in:
committed by
Marcus Green
parent
f9729dcfe0
commit
cf873ada46
+8
-11
@@ -920,7 +920,7 @@ function data_add_record($data, $groupid=0){
|
||||
$event->trigger();
|
||||
|
||||
$course = get_course($cm->course);
|
||||
data_update_completion_state($course, $cm);
|
||||
data_update_completion_state($data, $course, $cm);
|
||||
|
||||
return $record->id;
|
||||
}
|
||||
@@ -2890,6 +2890,7 @@ function data_supports($feature) {
|
||||
case FEATURE_GROUPINGS: return true;
|
||||
case FEATURE_MOD_INTRO: return true;
|
||||
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
|
||||
case FEATURE_COMPLETION_HAS_RULES: return true;
|
||||
case FEATURE_GRADE_HAS_GRADE: return true;
|
||||
case FEATURE_GRADE_OUTCOMES: return true;
|
||||
case FEATURE_RATE: return true;
|
||||
@@ -3948,7 +3949,7 @@ function data_delete_record($recordid, $data, $courseid, $cmid) {
|
||||
$event->trigger();
|
||||
$course = get_course($courseid);
|
||||
$cm = get_coursemodule_from_instance('data', $data->id, 0, false, MUST_EXIST);
|
||||
data_update_completion_state($course, $cm);
|
||||
data_update_completion_state($data, $course, $cm);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -4138,24 +4139,20 @@ function data_set_config(&$database, $key, $value) {
|
||||
* Sets the automatic completion state for this database item based on the
|
||||
* count of on its entries.
|
||||
* @since Moodle 3.3
|
||||
* @param object $data The data object for this activity
|
||||
* @param object $course Course
|
||||
* @param object $cm course-module
|
||||
*/
|
||||
function data_update_completion_state($course, $cm) {
|
||||
global $DB;
|
||||
// Get data details.
|
||||
$data = $DB->get_record('data', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
function data_update_completion_state($data, $course, $cm) {
|
||||
// If completion option is enabled, evaluate it and return true/false.
|
||||
$completion = new completion_info($course);
|
||||
if ($data->completionentries && $completion->is_enabled($cm)) {
|
||||
$numentries = data_numentries($data);
|
||||
// Check the number of entries required against the number of entries already made.
|
||||
if ($data->completionentries > 0 && $numentries >= $data->completionentries) {
|
||||
if ($numentries >= $data->completionentries) {
|
||||
$completion->update_state($cm, COMPLETION_COMPLETE);
|
||||
} else {
|
||||
if ($completion->is_enabled($cm)) {
|
||||
$completion->update_state($cm, COMPLETION_INCOMPLETE);
|
||||
}
|
||||
$completion->update_state($cm, COMPLETION_INCOMPLETE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4182,7 +4179,7 @@ function data_get_completion_state($course, $cm, $userid, $type) {
|
||||
$data = $DB->get_record('data', array('id' => $cm->instance));
|
||||
$numentries = data_numentries($data);
|
||||
// Check the number of entries required against the number of entries already made.
|
||||
if ($data->completionentries > 0 && $numentries >= $data->completionentries) {
|
||||
if ($numentries >= $data->completionentries) {
|
||||
$result = true;
|
||||
} else {
|
||||
$result = false;
|
||||
|
||||
@@ -120,14 +120,14 @@ class mod_data_mod_form extends moodleform_mod {
|
||||
public function add_completion_rules() {
|
||||
$mform = & $this->_form;
|
||||
$group = array();
|
||||
$group[] = $mform->createElement('checkbox', 'completionentriesendabled', '',
|
||||
$group[] = $mform->createElement('checkbox', 'completionentriesenabled', '',
|
||||
get_string('completionentriescount', 'data'));
|
||||
$group[] = $mform->createElement('text', 'completionentries',
|
||||
get_string('completionentriescount', 'data'), array('size' => '1'));
|
||||
|
||||
$mform->addGroup($group, 'completionentriesgroup', get_string('completionentries', 'data'),
|
||||
array(' '), false);
|
||||
$mform->disabledIf('completionentries', 'completionentriesendabled', 'notchecked');
|
||||
$mform->disabledIf('completionentries', 'completionentriesenabled', 'notchecked');
|
||||
$mform->setDefault('completionentries', 1);
|
||||
$mform->setType('completionentries', PARAM_INT);
|
||||
/* This ensures the elements are disabled unless completion rules are enabled */
|
||||
@@ -151,8 +151,11 @@ class mod_data_mod_form extends moodleform_mod {
|
||||
*
|
||||
*/
|
||||
public function data_preprocessing(&$defaultvalues) {
|
||||
$defaultvalues['completionentriesendabled'] = !empty($defaultvalues['completionentries']) ? 1 : 0;
|
||||
parent::data_preprocessing($defaultvalues);
|
||||
$defaultvalues['completionentriesenabled'] = !empty($defaultvalues['completionentries']) ? 1 : 0;
|
||||
if (empty($defaultvalues['completionentries'])) {
|
||||
$defaultvalues['completionentries'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,12 +171,11 @@ class mod_data_mod_form extends moodleform_mod {
|
||||
|
||||
if (!empty($data->completionunlocked)) {
|
||||
$autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (empty($data->completionentries) || !$autocompletion) {
|
||||
$data->completionentries = 0;
|
||||
if (empty($data->completionentriesenabled) || !$autocompletion) {
|
||||
$data->completionentries = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$data->completionunlocked = true;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ Scenario:
|
||||
| Name | Test database name |
|
||||
| Description | Test database description |
|
||||
| Completion tracking | Show activity as complete when conditions are met |
|
||||
| completionentriesendabled | checked |
|
||||
| completionentriesenabled | checked |
|
||||
| completionentries | 2 |
|
||||
And I follow "Course 1"
|
||||
And I add a "Text input" field to "Test database name" database and I fill the form with:
|
||||
|
||||
@@ -10,6 +10,9 @@ information provided here is intended especially for developers.
|
||||
This method is used for returning the field settings for external functions.
|
||||
You should check the user capabilities of the current user before returning any field setting value.
|
||||
This is intended to protect field settings like private keys for external systems.
|
||||
* Required entries has been added to the Activity completion setting of mod_form. Entries required for completion
|
||||
(in the entries section) is no longer displayed for new instances and will be deprecated in a future release
|
||||
in favour of the new completion setting.
|
||||
|
||||
=== 3.2 ===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user