diff --git a/grade/classes/component_gradeitem.php b/grade/classes/component_gradeitem.php index 9e7ba921078..9662ec3e2fc 100644 --- a/grade/classes/component_gradeitem.php +++ b/grade/classes/component_gradeitem.php @@ -483,4 +483,34 @@ abstract class component_gradeitem { return $gradinginstance; } + + /** + * Sends a notification about the item being graded for the student. + * + * @param stdClass $gradeduser The user being graded + * @param stdClass $grader The user who is grading + */ + public function send_student_notification(stdClass $gradeduser, stdClass $grader): void { + list($itemtype, $itemmodule) = \core_component::normalize_component($this->component); + $gradeitem = \grade_item::fetch([ + 'itemtype' => $itemtype, + 'itemmodule' => $itemmodule, + 'iteminstance' => $this->itemnumber, + ]); + + $eventdata = new \core\message\message(); + $eventdata->courseid = $this->context->get_course_context()->instanceid; + $eventdata->component = 'moodle'; + $eventdata->name = 'gradenotifications'; + $eventdata->userfrom = $grader; + $eventdata->userto = $gradeduser; + $eventdata->subject = get_string('gradenotificationsubject', 'grades'); + $eventdata->fullmessage = get_string('gradenotificationmessage', 'grades', ['name' => $gradeitem->get_name()]); + + $eventdata->fullmessageformat = FORMAT_PLAIN; + $eventdata->fullmessagehtml = ''; + $eventdata->smallmessage = ''; + $eventdata->notification = 1; + message_send($eventdata); + } } diff --git a/lang/en/grades.php b/lang/en/grades.php index 63f2b000431..b65c9b131e0 100644 --- a/lang/en/grades.php +++ b/lang/en/grades.php @@ -318,6 +318,8 @@ $string['grademax'] = 'Maximum grade'; $string['grademax_help'] = 'This setting determines the maximum grade when using the value grade type. The maximum grade for an activity-based grade item is set on the activity settings page.'; $string['grademin'] = 'Minimum grade'; $string['grademin_help'] = 'This setting determines the minimum grade when using the value grade type.'; +$string['gradenotificationmessage'] = 'You have new feedback on your work for "{$a->name}"'; +$string['gradenotificationsubject'] = 'Your have been graded'; $string['gradeoutcomeitem'] = 'Grade outcome item'; $string['gradeoutcomes'] = 'Outcomes'; $string['gradeoutcomescourses'] = 'Course outcomes';