Skip to content

Commit

Permalink
Merge branch 'MDL-67116-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Nov 13, 2019
2 parents 23ac81e + c035141 commit 289c9e1
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 23 deletions.
15 changes: 12 additions & 3 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 @@ -411,7 +415,7 @@ function set_moduleinfo_defaults($moduleinfo) {
// Convert the 'use grade' checkbox into a grade-item number: 0 if checked, null if not.
if (isset($moduleinfo->completionusegrade) && $moduleinfo->completionusegrade) {
$moduleinfo->completiongradeitemnumber = 0;
} else {
} else if (!isset($moduleinfo->completiongradeitemnumber)) {
$moduleinfo->completiongradeitemnumber = null;
}

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 Expand Up @@ -684,6 +692,7 @@ function get_moduleinfo_data($cm, $course) {
$data->completionview = $cm->completionview;
$data->completionexpected = $cm->completionexpected;
$data->completionusegrade = is_null($cm->completiongradeitemnumber) ? 0 : 1;
$data->completiongradeitemnumber = $cm->completiongradeitemnumber;
$data->showdescription = $cm->showdescription;
$data->tags = core_tag_tag::get_item_tags_array('core', 'course_modules', $cm->id);
if (!empty($CFG->enableavailability)) {
Expand Down
95 changes: 82 additions & 13 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ function definition_after_data() {
if ($mform->elementExists('completionusegrade')) {
$mform->freeze('completionusegrade');
}
if ($mform->elementExists('completiongradeitemnumber')) {
$mform->freeze('completiongradeitemnumber');
}
$mform->freeze($this->_customcompletionelements);
}
}
Expand Down Expand Up @@ -449,16 +452,46 @@ function validation($data, $files) {
$errors[$gradepassfieldname] = get_string('gradepassgreaterthangrade', 'grades', $grade);
}
}

// We have a grade if there is a non-falsey value for:
// - the assessedfieldname for Ratings there; or
// - the gradefieldname for Ratings there.
if (empty($data[$assessedfieldname]) && empty($data[$gradefieldname])) {
// There are no grades set therefore completion is not allowed.
if (isset($data['completiongradeitemnumber']) && $data['completiongradeitemnumber'] == (string) $itemnumber) {
$errors['completiongradeitemnumber'] = get_string(
'badcompletiongradeitemnumber',
'completion',
get_string("grade_{$itemname}_name", $component)
);
}
}
}

// Completion: Don't let them choose automatic completion without turning
// on some conditions. Ignore this check when completion settings are
// locked, as the options are then disabled.
if (array_key_exists('completion', $data) &&
$data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
!empty($data['completionunlocked'])) {
if (empty($data['completionview']) && empty($data['completionusegrade']) &&
!$this->completion_rule_enabled($data)) {
$automaticcompletion = array_key_exists('completion', $data);
$automaticcompletion = $automaticcompletion && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC;
$automaticcompletion = $automaticcompletion && !empty($data['completionunlocked']);

if ($automaticcompletion) {
// View to complete.
$rulesenabled = !empty($data['completionview']);

// Use grade to complete (only one grade item).
$rulesenabled = $rulesenabled || !empty($data['completionusegrade']);

// Use grade to complete (specific grade item).
if (!$rulesenabled && isset($data['completiongradeitemnumber'])) {
$rulesenabled = $data['completiongradeitemnumber'] != '';
}

// Module-specific completion rules.
$rulesenabled = $rulesenabled || $this->completion_rule_enabled($data);

if (!$rulesenabled) {
// No rules are enabled. Can't set automatically completed without rules.
$errors['completion'] = get_string('badautocompletion', 'completion');
}
}
Expand Down Expand Up @@ -657,17 +690,53 @@ protected function standard_coursemodule_elements() {
$gotcompletionoptions = true;
}

// Automatic completion once it's graded
if (plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false)) {
$mform->addElement('checkbox', 'completionusegrade', get_string('completionusegrade', 'completion'),
get_string('completionusegrade_desc', 'completion'));
$mform->hideIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
$mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');
// This activity supports grading.
$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 one gradeitem in this activity.
// We use the completionusegrade field here.
$mform->addElement(
'checkbox',
'completionusegrade',
get_string('completionusegrade', 'completion'),
get_string('completionusegrade_desc', 'completion')
);
$mform->hideIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
$mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');

// The disabledIf logic differs between ratings and other grade items due to different field types.
if ($this->_features->rating) {
// If using the rating system, there is no grade unless ratings are enabled.
$mform->disabledIf('completionusegrade', 'assessed', 'eq', 0);
} else {
// All other field types use the '$gradefieldname' field's modgrade_type.
$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');
}
} else if (count($itemnames) > 1) {
// There are multiple grade items in this activity.
// Show them all.
$options = [
'' => get_string('activitygradenotrequired', 'completion'),
];
foreach ($itemnames as $itemnumber => $itemname) {
$options[$itemnumber] = get_string("grade_{$itemname}_name", $component);
}

$mform->addElement(
'select',
'completiongradeitemnumber',
get_string('completionusegrade', 'completion'),
$options
);
$mform->hideIf('completiongradeitemnumber', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
}
}

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 lang/en/completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
$string['activitiescompletednote'] = 'Note: Activity completion must be set for an activity to appear in the above list.';
$string['activitycompletion'] = 'Activity completion';
$string['activitycompletionupdated'] = 'Changes saved';
$string['activitygradenotrequired'] = 'Grade not required';
$string['affectedactivities'] = 'The changes will affect the following <b>{$a}</b> activities or resources:';
$string['aggregationmethod'] = 'Aggregation method';
$string['all'] = 'All';
$string['any'] = 'Any';
$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['badcompletiongradeitemnumber'] = 'Require grade can\'t be enabled for <b>{$a}</b> because grading by {$a} is not enabled.';
$string['bulkactivitycompletion'] = 'Bulk edit activity completion';
$string['bulkactivitydetail'] = 'Select the activities you wish to bulk edit.';
$string['bulkcompletiontracking'] = 'Completion tracking';
Expand Down
15 changes: 8 additions & 7 deletions mod/forum/lang/en/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,26 +738,27 @@
$string['yourreply'] = 'Your reply';
$string['forumsubjectdeleted'] = 'This forum post has been removed';
$string['forumbodydeleted'] = 'The content of this forum post has been removed and can no longer be accessed.';
$string['gradeusers'] = 'Grade users';
$string['forumgrader'] = 'Forum grader';
$string['grading'] = 'Grading';
$string['viewconversation'] = 'View discussion';

$string['grade_forum_header'] = 'Whole forum grading';
$string['grade_forum_name'] = 'Whole forum';
$string['grade_forum_title'] = 'Grade';
$string['gradingstatus'] = 'Grade status:';
$string['grade_rating_name'] = 'Rating';
$string['gradeusers'] = 'Grade users';
$string['graded'] = 'Graded';
$string['notgraded'] = 'Not graded';
$string['gradeforrating'] = 'Grade for rating: {$a->str_long_grade}';
$string['gradeforratinghidden'] = 'Grade for rating hidden';
$string['gradeforwholeforum'] = 'Grade for forum: {$a->str_long_grade}';
$string['grading'] = 'Grading';
$string['gradingstatus'] = 'Grade status:';
$string['gradeforwholeforumhidden'] = 'Grade for forum hidden';
$string['gradeitemnameforwholeforum'] = 'Whole forum grade for {$a->name}';
$string['gradeitemnameforrating'] = 'Rating grade for {$a->name}';
$string['grades:gradesavedfor'] = 'Grade saved for {$a->fullname}';
$string['grades:gradesavefailed'] = 'Unable to save grade for {$a->fullname}: {$a->error}';
$string['showmoreusers'] = 'Show more users';
$string['notgraded'] = 'Not graded';
$string['nousersmatch'] = 'No user(s) found for given criteria';
$string['showmoreusers'] = 'Show more users';
$string['viewconversation'] = 'View conversation';
$string['viewgrades'] = 'View grades';

// Deprecated since Moodle 3.8.
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 289c9e1

Please sign in to comment.