MDL-67116 course: Fix completion disabled for gradable items

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.
This commit is contained in:
Andrew Nicols
2019-11-13 12:49:59 +08:00
parent fe795b59e4
commit c035141971
3 changed files with 13 additions and 2 deletions
+10 -2
View File
@@ -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;
}
@@ -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,
+1
View File
@@ -112,6 +112,7 @@ class core_course_modlib_testcase extends advanced_testcase {
$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;
+2
View File
@@ -157,6 +157,8 @@ $string['formatpeergradeover'] = '<span class="grade">{$a->grade}</span> <span c
$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;';