]> git.mjollnir.org Git - moodle.git/commitdiff
merged, added new config variables to control what roles get shown in the grade book
authortoyomoyo <toyomoyo>
Wed, 25 Oct 2006 08:51:26 +0000 (08:51 +0000)
committertoyomoyo <toyomoyo>
Wed, 25 Oct 2006 08:51:26 +0000 (08:51 +0000)
admin/settings/appearance.php
grade/lib.php
lib/adminlib.php

index 843092924c0334ad97734544b96a675c357f4f18..067c62e6c9308cc2caf747fb063953a49a301bb2 100644 (file)
@@ -118,6 +118,12 @@ $temp = new admin_settingpage('mymoodle', get_string('mymoodle', 'admin'));
 $temp->add(new admin_setting_configcheckbox('mymoodleredirect', get_string('mymoodleredirect', 'admin'), get_string('configmymoodleredirect', 'admin'), 0));
 $ADMIN->add('appearance', $temp);
 
+// new CFG variable for gradebook (what roles to display)
+$temp = new admin_settingpage('gradebook_roles', get_string('graderoles', 'admin'));
+$temp->add(new admin_setting_special_gradebook_roles());
+$ADMIN->add('appearance', $temp);
+
+
 $ADMIN->add('appearance', new admin_externalpage('stickyblocks', get_string('stickyblocks', 'admin'), "$CFG->wwwroot/$CFG->admin/stickyblocks.php"));
 
 ?>
index 60e9301f95244d09668e806df487d6fc571c8ed0..e457291ae6d3535a3ef9db954e242fe2dfa1a5af 100644 (file)
@@ -256,9 +256,11 @@ function grade_get_formatted_grades() {
                 } 
             }
         }
-        
-        // set the students name under student_data (this has the added bonus of creating an entry for students who do not have any grades)
-        $students = get_course_students($course->id);
+        if (!$students = grade_get_course_students($course->id)) {
+            return false;  
+        }
+
+                              
         if (isset($students) && $students) {
             foreach ($students as $userid => $student) {
                 $grades_by_student["$userid"]['student_data']['firstname'] = $student->firstname;
@@ -1218,7 +1220,7 @@ function grade_download($download, $id) {
     if ($currentgroup) {
         $students = get_group_students($currentgroup, "u.lastname ASC");
     } else {
-        $students = get_course_students($course->id, "u.lastname ASC");
+        $students = grade_get_course_students($course->id);
     }
 
     if (!empty($students)) {
@@ -1978,14 +1980,16 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a
     global $group; // yu: fix for 5814
     global $preferences;
     
-    $context = get_context_instance(CONTEXT_COURSE, $course->id);
-    
+    if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) {
+        return false;
+    }
+
     if (!has_capability('moodle/course:viewcoursegrades', $context)) {
         $view_by_student = $USER->id;    
     }
     
     list($grades_by_student, $all_categories) = grade_get_formatted_grades();
-    
+
     if ($grades_by_student != 0 && $all_categories != 0) {
       
         // output a form for the user to download the grades.  
@@ -2989,4 +2993,32 @@ function print_student_grade($user, $course) {
         }
     } // a new Moodle nesting record? ;-) 
 }
+
+function grade_get_course_students($courseid) {
+    global $CFG;
+    // The list of roles to display is stored in CFG->gradebook_roles
+    if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
+        return false;  
+    } 
+        
+    $configvar = get_config('', 'gradebook_roles');
+    if (empty($configvar->value)) {
+        notify ('no roles defined in admin->appearance->graderoles');
+        return false; // no roles to displayreturn false;  
+    }
+         
+    if ($rolestoget = explode(',', $configvar->value)) {
+        foreach ($rolestoget as $crole) {
+            if ($tempstudents = get_role_users($crole, $context, true)) {
+                foreach ($tempstudents as $tempuserid=>$tempstudent) {
+                    $students[$tempuserid] = $tempstudent;  
+                }            
+            }
+        }
+    } else {
+        notify ('no roles defined in admin->appearance->graderoles');
+        return false; // no roles to displayreturn false;  
+    }
+    return $students;
+}
 ?>
index d9ae7acdc25556c7ff0a032d1a76d246172d351c..acee7222b744d5617a66bf97d5d79ef26446ae9f 100644 (file)
@@ -2303,6 +2303,80 @@ class admin_setting_special_calendar_weekend extends admin_setting {
 
 }
 
+/* 
+ * this is used in config->appearance->gradeconfig 
+ */
+class admin_setting_special_gradebook_roles extends admin_setting {
+
+    function admin_setting_special_gradebook_roles() {
+        $name = 'gradebook_roles';
+        $visiblename = get_string('gradebook_roles', 'admin');
+        $description = get_string('gradebook_roles', 'admin');
+        
+        $value = array();
+        
+        if ($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {          
+            foreach ($studentroles as $roleid=>$studentrole) {
+                $value[$roleid] = 1;  
+            }
+        }
+
+        parent::admin_setting($name, $visiblename, $description, $value);
+    }
+
+    function get_setting() {
+        global $CFG;
+        if (isset($CFG->{$this->name})) {
+            return explode(',', $CFG->{$this->name});
+        } else {
+            return NULL;
+        }
+    }
+
+    function write_setting($data) {
+        if (!empty($data)) {
+            $str = '';
+            foreach($data as $key => $value) {
+                if ($value) {
+                    $str .= $key.',';
+                }
+            }
+            return set_config($this->name, rtrim($str, ","))?'':get_string('errorsetting', 'admin') . $this->visiblename . '<br />';
+        } else {
+            return set_config($this->name, '')?'':get_string('errorsetting', 'admin') . $this->visiblename . '<br />';  
+        }  
+    }
+
+    function output_html() {
+
+        if ($this->get_setting() === NULL) {
+            $currentsetting = $this->defaultsetting;
+        } else {
+            $currentsetting = $this->get_setting();
+        }
+        
+        // from to process which roles to display
+        if ($roles = get_records('role')) {
+            $return = '<table><tr><td class="c0">'.get_string('showroles','grades').':</td></tr>';        
+            foreach ($roles as $roleid=>$role) {  
+                if (is_array($currentsetting) && in_array($roleid, $currentsetting)) {
+                    $checked = 'checked="checked"';
+                } else {
+                    $checked = ''; 
+                }
+                            
+                $return .= '<tr><td class="c0">';
+                $return .= '<input type="checkbox" name="s_'.$this->name.'['.$roleid.']" value="1" '.$checked.'>'.$role->name;
+                $return .= '</td></tr>';
+            }
+            $return .= '</table>'; 
+        }
+        
+        return format_admin_setting($this->name, $this->visiblename, $return, $this->description);
+
+    }
+
+}
 
 class admin_setting_special_perfdebug extends admin_setting_configcheckbox {