$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"));
?>
}
}
}
-
- // 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;
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)) {
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.
}
} // 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;
+}
?>
}
+/*
+ * 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 {