From 5a412dbf8f38a63f1cc5c7ddb074fb8955387ae5 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Wed, 25 Oct 2006 08:51:26 +0000 Subject: [PATCH] merged, added new config variables to control what roles get shown in the grade book --- admin/settings/appearance.php | 6 +++ grade/lib.php | 46 ++++++++++++++++++---- lib/adminlib.php | 74 +++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 7 deletions(-) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 843092924c..067c62e6c9 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -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")); ?> diff --git a/grade/lib.php b/grade/lib.php index 60e9301f95..e457291ae6 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -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; +} ?> diff --git a/lib/adminlib.php b/lib/adminlib.php index d9ae7acdc2..acee7222b7 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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 . '
'; + } else { + return set_config($this->name, '')?'':get_string('errorsetting', 'admin') . $this->visiblename . '
'; + } + } + + 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 = ''; + foreach ($roles as $roleid=>$role) { + if (is_array($currentsetting) && in_array($roleid, $currentsetting)) { + $checked = 'checked="checked"'; + } else { + $checked = ''; + } + + $return .= ''; + } + $return .= '
'.get_string('showroles','grades').':
'; + $return .= ''.$role->name; + $return .= '
'; + } + + return format_admin_setting($this->name, $this->visiblename, $return, $this->description); + + } + +} class admin_setting_special_perfdebug extends admin_setting_configcheckbox { -- 2.39.5