MDL-83195 mod_assign: Individual grade release

Fix pushing individual grades into the gradebook (as opposed to the
batch release of grades) when "Allow partial release of grades while
marking anonymously" is enabled.

This change reworks MDL-73626's fix for the same issue for releasing
multiple grades in a batch operation.
This commit is contained in:
Leon Stringer
2025-02-14 09:28:21 +00:00
parent 9508120293
commit ff4f2c02ef
3 changed files with 44 additions and 12 deletions
+2 -1
View File
@@ -118,7 +118,8 @@ $string['batchsetallocatedmarker'] = 'Set allocated marker for {$a} selected use
$string['batchsetmarkingworkflowstateforusers'] = 'Set marking workflow state for {$a} selected user(s).';
$string['beginassignment'] = 'Begin assignment';
$string['blindmarking'] = 'Anonymous submissions';
$string['blindmarkingenabledwarning'] = 'Anonymous submissions are enabled for this activity. Grades will not be added to the gradebook until student identities are revealed via the grading action menu.';
$string['blindmarkingenabledwarning'] = 'Anonymous submissions are enabled for this activity.';
$string['blindmarkingnogradewarning'] = 'Anonymous submissions are enabled for this activity. Grades will not be added to the gradebook until student identities are revealed via the grading action menu.';
$string['blindmarking_help'] = 'Anonymous submissions hide the identity of students from markers. Anonymous submission settings will be locked once a submission or grade has been made in relation to this assignment.';
$string['cachedef_overrides'] = 'User and group override information';
$string['calendardue'] = '{$a} is due';
+15 -11
View File
@@ -4572,7 +4572,11 @@ class assign {
}
if ($this->is_blind_marking() && has_capability('mod/assign:viewblinddetails', $this->get_context())) {
$o .= $this->get_renderer()->notification(get_string('blindmarkingenabledwarning', 'assign'), 'notifymessage');
if ($this->is_marking_anonymous()) {
$o .= $this->get_renderer()->notification(get_string('blindmarkingenabledwarning', 'assign'), 'notifymessage');
} else {
$o .= $this->get_renderer()->notification(get_string('blindmarkingnogradewarning', 'assign'), 'notifymessage');
}
}
// Load and print the table of submissions.
@@ -6012,7 +6016,7 @@ class assign {
require_once($CFG->dirroot.'/mod/assign/lib.php');
// Do not push grade to gradebook if blind marking is active as
// the gradebook would reveal the students.
if ($this->is_blind_marking()) {
if ($this->is_blind_marking() && !$this->is_marking_anonymous()) {
return false;
}
@@ -8386,15 +8390,6 @@ class assign {
$grade->feedbackfiles = $plugin->files_for_gradebook($grade);
}
$this->update_grade($grade);
$assign = clone $this->get_instance();
$assign->cmidnumber = $this->get_course_module()->idnumber;
// Set assign gradebook feedback plugin status.
$assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled();
// If markinganonymous is enabled then allow to release grades anonymously.
if (isset($assign->markinganonymous) && $assign->markinganonymous == 1) {
assign_update_grades($assign, $userid);
}
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
\mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger();
}
@@ -9697,6 +9692,15 @@ class assign {
return !empty($submission) && $submission->status !== ASSIGN_SUBMISSION_STATUS_SUBMITTED && $timedattemptstarted;
}
/**
* Is "Allow partial release of grades while marking anonymously" enabled?
*
* @return bool
*/
public function is_marking_anonymous(): bool {
return isset($this->get_instance()->markinganonymous) && $this->get_instance()->markinganonymous;
}
}
/**
+27
View File
@@ -4626,4 +4626,31 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
$this->AssertTrue($assign->is_userid_filtered($student1->id));
$this->AssertTrue($assign->is_userid_filtered($student2->id));
}
/**
* Test that assignment grades are pushed to the gradebook when anonymous
* submissions and marking workflow are enabled (MDL-83195).
* @covers \assign::gradebook_item_update
*/
public function test_release_grade_anon(): void {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assign = $this->create_instance($course, [
'blindmarking' => 1,
'markingworkflow' => 1,
'markinganonymous' => 1,
]);
// Add a grade and change the workflow status to "Released".
$this->mark_submission($teacher, $assign, $student, 50.0, [
'workflowstate' => ASSIGN_MARKING_WORKFLOW_STATE_RELEASED,
]);
// Make sure the grade has been pushed to the gradebook.
$gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $assign->get_instance()->id, $student->id);
$this->assertEquals(50, (int)$gradinginfo->items[0]->grades[$student->id]->grade);
}
}