Skip to content

Commit

Permalink
MDL-67116 course: Fix completion disabled for gradable items
Browse files Browse the repository at this point in the history
The default value is an empty string (""), which in PHP evaluates to 0 when
cast to a string in our DML layer.

The fix is to forcibly make it null which is not cast to string in DML
for optional strings.
  • Loading branch information
andrewnicols committed Nov 13, 2019
1 parent fe795b5 commit c035141
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions course/modlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
$completion = new completion_info($course);
if ($completion->is_enabled()) {
$newcm->completion = $moduleinfo->completion;
$newcm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
if ($moduleinfo->completiongradeitemnumber == '') {
$newcm->completiongradeitemnumber = null;
} else {
$newcm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
}
$newcm->completionview = $moduleinfo->completionview;
$newcm->completionexpected = $moduleinfo->completionexpected;
}
Expand Down Expand Up @@ -524,7 +528,11 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) {
// the activity may be locked; if so, these should not be updated.
if (!empty($moduleinfo->completionunlocked)) {
$cm->completion = $moduleinfo->completion;
$cm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
if ($moduleinfo->completiongradeitemnumber == '') {
$cm->completiongradeitemnumber = null;
} else {
$cm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
}
$cm->completionview = $moduleinfo->completionview;
}
// The expected date does not affect users who have completed the activity,
Expand Down
1 change: 1 addition & 0 deletions course/tests/modlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function test_get_moduleinfo_data() {
$expecteddata->completionview = $assigncm->completionview;
$expecteddata->completionexpected = $assigncm->completionexpected;
$expecteddata->completionusegrade = is_null($assigncm->completiongradeitemnumber) ? 0 : 1;
$expecteddata->completiongradeitemnumber = null;
$expecteddata->showdescription = $assigncm->showdescription;
$expecteddata->tags = core_tag_tag::get_item_tags_array('core', 'course_modules', $assigncm->id);
$expecteddata->availabilityconditionsjson = null;
Expand Down
2 changes: 2 additions & 0 deletions mod/workshop/lang/en/workshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
$string['formatpeergradeoverweighted'] = '<span class="grade">{$a->grade}</span> <span class="gradinggrade">(<del>{$a->gradinggrade}</del> / <ins>{$a->gradinggradeover}</ins>)</span> @ <span class="weight">{$a->weight}</span>';
$string['formatpeergradeweighted'] = '<span class="grade">{$a->grade}</span> <span class="gradinggrade">({$a->gradinggrade})</span> @ <span class="weight">{$a->weight}</span>';
$string['givengrades'] = 'Grades given';
$string['grade_submission_name'] = 'Submission';
$string['grade_grading_name'] = 'Assessment';
$string['gradecalculated'] = 'Calculated grade for submission';
$string['gradedecimals'] = 'Decimal places in grades';
$string['gradegivento'] = '&gt;';
Expand Down

0 comments on commit c035141

Please sign in to comment.