function grade_get_grades() { global $CFG; global $course; $mods = grade_get_grade_items($course->id); $preferences = grade_get_preferences($course->id); if ($mods) { foreach ($mods as $mod) { // hidden is a gradebook setting for an assignment and visible is a course_module setting if ($mod->hidden != 1 && $mod->visible == 1 or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->cmid)) && $preferences->show_hidden == 1) { $libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php"; if (file_exists($libfile)) { require_once $libfile; $gradefunction = $mod->modname . "_grades"; // MDL-12043, skip this mod there is no such function, to prevent fatal errors. if (!function_exists($gradefunction)) { continue; } if ($grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"] = $gradefunction($mod->cminstance)) { // added grades for particular mod // now get the grade_item modifiers ie. scale_grade and extra credit $scale_grade = get_record('grade_item', 'courseid', $course->id, 'cminstance', $mod->cminstance, 'modid', $mod->modid); if (isset($scale_grade)) { $grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->scale_grade = $scale_grade->scale_grade; $grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->extra_credit = $scale_grade->extra_credit; } else { $grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->scale_grade = 1.0; $grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->extra_credit = 0; } if ($mod->hidden != 1 && $mod->visible == 1) { $grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->hidden = 0; } else { $grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->hidden = 1; } $grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->sort_order = $scale_grade->sort_order; // I don't think this should be necessary but it appears that the forum doesn't follow the grades API properly it returns blank or NULL when it // should return a value for maxgrade according to the moodle API... so if it doesn't want to give us a grade let's not use it. // this happens when grading is set to a non-numeric for a forum ie. uses "seperate and connected ways of knowing" if ($grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->maxgrade == '') { $grades["{$mod->cname}"]["{$mod->modid}"]["{$mod->cminstance}"]->maxgrade = 100; //unset($grades["$mod->cname"]["$mod->modid"]["$mod->cminstance"]); } } else { // delete this item from the grade_item table since it was deleted through the mod interface delete_records('grade_item', 'modid', $mods->modid, 'courseid', $course->id); delete_records('grade_exceptions', 'grade_itemid', $mod->id, 'courseid', $course->id); } } else { //echo "<center><font color=red>Could not find lib file for $mod->modid</font></center>"; } } } } else { // Do something here for no grades //echo "<center><font color=red>No grades returned. It appears that there are no items with grades for this course.</font></center>"; } if (isset($grades)) { return $grades; } else { return NULL; } }
$download = optional_param('download'); $user = optional_param('user', -1); $action = optional_param('action', 'grades'); $cview = optional_param('cview', -1); if (!($course = get_record('course', 'id', $id))) { error('No course ID'); } require_login($course->id); // if the user set new prefs make sure they happen now if ($action == 'set_grade_preferences' && ($prefs = data_submitted())) { if (!confirm_sesskey()) { error(get_string('confirmsesskeybad', 'error')); } grade_set_preferences($course, $prefs); } $preferences = grade_get_preferences($course->id); // we want this in its own window if ($action == 'stats') { grade_stats(); exit; } else { if ($action == 'ods') { grade_download('ods', $id); exit; } else { if ($action == 'excel') { grade_download('xls', $id); exit; } else { if ($action == 'text') { grade_download('txt', $id);