]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18951 standardised group support in grader report
authorskodak <skodak>
Thu, 30 Apr 2009 09:00:43 +0000 (09:00 +0000)
committerskodak <skodak>
Thu, 30 Apr 2009 09:00:43 +0000 (09:00 +0000)
grade/report/grader/lib.php

index a8b95db6bb1b70d3e34eca4845fc446c18ad2f83..57e2cac97cab907a340f6f0ea76be45c35695a68 100644 (file)
@@ -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);
         }