From: skodak Date: Thu, 30 Apr 2009 09:00:43 +0000 (+0000) Subject: MDL-18951 standardised group support in grader report X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=30ebb74f444db8cc912cee59f92f08036ea80056;p=moodle.git MDL-18951 standardised group support in grader report --- diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index a8b95db6bb..57e2cac97c 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -159,6 +159,20 @@ class grade_report_grader extends grade_report { global $DB; $warnings = array(); + $separategroups = false; + $mygroups = array(); + if ($this->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $this->context)) { + $separategroups = true; + $mygroups = groups_get_user_groups($this->course->id); + $mygroups = $mygroups[0]; // ignore groupings + // reorder the groups fro better perf bellow + $current = array_search($this->currentgroup, $mygroups); + if ($current !== false) { + unset($mygroups[$current]); + array_unshift($mygroups, $this->currentgroup); + } + } + // always initialize all arrays $queue = array(); foreach ($data as $varname => $postedvalue) { @@ -233,6 +247,24 @@ class grade_report_grader extends grade_report { } } + // group access control + if ($separategroups) { + // note: we can not use $this->currentgroup because it would fail badly + // when having two browser windows each with different group + $sharinggroup = false; + foreach($mygroups as $groupid) { + if (groups_is_member($groupid, $userid)) { + $sharinggroup = true; + break; + } + } + if (!$sharinggroup) { + // either group membership changed or somebedy is hacking grades of other group + $warnings[] = get_string('errorsavegrade', 'grades'); + continue; + } + } + $grade_item->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE); }