Skip to content

Commit

Permalink
MDL-67116 course: allow grading completion for non ratings grade item
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie authored and andrewnicols committed Nov 13, 2019
1 parent d21ba3f commit a492f69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
28 changes: 24 additions & 4 deletions course/moodleform_mod.php
Expand Up @@ -409,6 +409,7 @@ function validation($data, $files) {
}
}

$hasgradedefined = false;
$component = "mod_{$this->_modname}";
$itemnames = component_gradeitems::get_itemname_mapping_for_component($component);
foreach ($itemnames as $itemnumber => $itemname) {
Expand Down Expand Up @@ -449,6 +450,14 @@ function validation($data, $files) {
$errors[$gradepassfieldname] = get_string('gradepassgreaterthangrade', 'grades', $grade);
}
}

// We have a grade if we've already found one, or the 'assessed' field is set to a non falsey value (this is for
// ratings), or the grade field name is set to a non falsey value (this is all other grading items).
$hasgradedefined = $hasgradedefined || !empty($data[$assessedfieldname]) || !empty($data[$gradefieldname]);
}

if (!empty($data['completionusegrade']) && !$hasgradedefined) {
$errors['completionusegrade'] = get_string('badcompletionusegrade', 'completion');
}

// Completion: Don't let them choose automatic completion without turning
Expand Down Expand Up @@ -664,10 +673,21 @@ protected function standard_coursemodule_elements() {
$mform->hideIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
$mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');
$gotcompletionoptions = true;

// If using the rating system, there is no grade unless ratings are enabled.
if ($this->_features->rating) {
$mform->disabledIf('completionusegrade', 'assessed', 'eq', 0);
$component = "mod_{$this->_modname}";
$itemnames = component_gradeitems::get_itemname_mapping_for_component($component);

if (count($itemnames) === 1) {
// Only add disable if logic if we've got exactly one grade item since we can't do
// make the disable conditional on multiple elements.
if ($this->_features->rating) {
// If using the rating system, there is no grade unless ratings are enabled.
$mform->disabledIf('completionusegrade', 'assessed', 'eq', 0);
} else {
$itemnumbers = array_keys($itemnames);
$itemnumber = array_shift($itemnumbers);
$gradefieldname = component_gradeitems::get_field_name_for_itemnumber($component, $itemnumber, 'grade');
$mform->disabledIf('completionusegrade', "{$gradefieldname}[modgrade_type]", 'eq', 'none');
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/completion.php
Expand Up @@ -41,6 +41,7 @@
$string['approval'] = 'Approval';
$string['areyousureoverridecompletion'] = 'Are you sure you want to override the current completion state of this activity for this user and mark it "{$a}"?';
$string['badautocompletion'] = 'When you select automatic completion, you must also enable at least one requirement (below).';
$string['badcompletionusegrade'] = 'When you select require grade, you must also enable at least one grade item.';
$string['bulkactivitycompletion'] = 'Bulk edit activity completion';
$string['bulkactivitydetail'] = 'Select the activities you wish to bulk edit.';
$string['bulkcompletiontracking'] = 'Completion tracking';
Expand Down

0 comments on commit a492f69

Please sign in to comment.