From 413efd220026473ae08fe2f14da2e10f86a0c5fa Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 10 Apr 2007 14:51:34 +0000 Subject: [PATCH] MDL-7888 rewritten email alerts to graders - "mod/assignment:grade" permission is now used instead of legacy teacher; it should also fix missing alerts when using separate groups; merged from MOODLE_18_STABLE --- mod/assignment/lib.php | 67 ++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 12e400e068..6449375b08 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -1394,20 +1394,7 @@ class assignment_base { $user = get_record('user', 'id', $submission->userid); - if (groupmode($this->course, $this->cm) == SEPARATEGROUPS) { // Separate groups are being used - if ($groups = user_group($this->course->id, $user->id)) { // Try to find groups - $teachers = array(); - foreach ($groups as $group) { - $teachers = array_merge($teachers, get_group_teachers($this->course->id, $group->id)); - } - } else { - $teachers = get_group_teachers($this->course->id, 0); // Works even if not in group - } - } else { - $teachers = get_course_teachers($this->course->id); - } - - if ($teachers) { + if ($teachers = $this->get_graders($user)) { $strassignments = get_string('modulenameplural', 'assignment'); $strassignment = get_string('modulename', 'assignment'); @@ -1415,7 +1402,7 @@ class assignment_base { foreach ($teachers as $teacher) { $info = new object(); - $info->username = fullname($user); + $info->username = fullname($user, true); $info->assignment = format_string($this->assignment->name,true); $info->url = $CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id; @@ -1428,6 +1415,48 @@ class assignment_base { } } + /** + * Returns a list of teachers that should be grading given submission + */ + function get_graders($user) { + //potential graders + $potgraders = get_users_by_capability($this->context, 'mod/assignment:grade', $fields='', $sort='', $limitfrom='', + $limitnum='', $groups='', $exceptions='', $doanything=false, $view=false); + $graders = array(); + if (groupmode($this->course, $this->cm) == SEPARATEGROUPS) { // Separate groups are being used + if ($groups = user_group($this->course->id, $user->id)) { // Try to find all groups + foreach ($groups as $group) { + foreach ($potgraders as $t) { + if ($t->id == $user->id) { + continue; // do not send self + } + if (groups_is_member($group->id, $t->id)) { + $graders[$t->id] = $t; + } + } + } + } else { + // user not in group, try to find graders without group + foreach ($potgraders as $t) { + if ($t->id == $user->id) { + continue; // do not send self + } + if (!user_group($this->course->id, $t->id)) { //ugly hack + $graders[$t->id] = $t; + } + } + } + } else { + foreach ($potgraders as $t) { + if ($t->id == $user->id) { + continue; // do not send self + } + $graders[$t->id] = $t; + } + } + return $graders; + } + /** * Creates the text content for emails to teachers * @@ -1435,8 +1464,8 @@ class assignment_base { * @return string */ function email_teachers_text($info) { - $posttext = $this->course->shortname.' -> '.$this->strassignments.' -> '. - format_string($this->assignment->name, true)."\n"; + $posttext = format_string($this->course->shortname).' -> '.$this->strassignments.' -> '. + format_string($this->assignment->name)."\n"; $posttext .= '---------------------------------------------------------------------'."\n"; $posttext .= get_string("emailteachermail", "assignment", $info)."\n"; $posttext .= "\n---------------------------------------------------------------------\n"; @@ -1452,9 +1481,9 @@ class assignment_base { function email_teachers_html($info) { global $CFG; $posthtml = '

'. - ''.$this->course->shortname.' ->'. + ''.format_string($this->course->shortname).' ->'. ''.$this->strassignments.' ->'. - ''.format_string($this->assignment->name,true).'

'; + ''.format_string($this->assignment->name).'

'; $posthtml .= '
'; $posthtml .= '

'.get_string('emailteachermailhtml', 'assignment', $info).'

'; $posthtml .= '

'; -- 2.39.5