Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a new grading tool for teachers to see all grades on one page.

Grades are collected from each module using the module_grades function in
each mod/*/lib.php.
  • Loading branch information...
commit 3486b7bee5de8213ded8caea64e88a0318fa0d2f 1 parent 19c4f55
moodler authored
100 course/grades.php
... ... @@ -0,0 +1,100 @@
  1 +<?PHP // $Id$
  2 + // Displays all grades for a course
  3 +
  4 + require("../config.php");
  5 + require("lib.php");
  6 +
  7 + require_variable($id); // course id
  8 +
  9 + if (! $course = get_record("course", "id", $id)) {
  10 + error("Course ID was incorrect");
  11 + }
  12 +
  13 + require_login($course->id);
  14 +
  15 + if (!isteacher($course->id)) {
  16 + error("Only teachers can use this page!");
  17 + }
  18 +
  19 + $strgrades = get_string("grades");
  20 + $strgrade = get_string("grade");
  21 +
  22 +
  23 +/// Otherwise fill and print the form.
  24 +
  25 + print_header("$course->shortname: $strgrades", "$course->fullname",
  26 + "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
  27 + -> $strgrades");
  28 +
  29 + print_heading($strgrades);
  30 +
  31 + if (!$students = get_course_students($course->id)) {
  32 + print_heading(get_string("nostudentsyet"));
  33 + print_footer($course);
  34 + exit;
  35 + }
  36 +
  37 + foreach ($students as $student) {
  38 + $grades[$student->id] = array(); // Collect all grades in this array
  39 + }
  40 + $columns = array(); // Accumulate column names in this array.
  41 +
  42 + // Collect module data
  43 + get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused, $modsectioncounts);
  44 +
  45 + $sections = get_all_sections($course->id); // Sort everything the same as the course
  46 + for ($i=0; $i<=$course->numsections; $i++) {
  47 + if (isset($sections[$i])) { // should always be true
  48 + $section = $sections[$i];
  49 + if ($section->sequence) {
  50 + $sectionmods = explode(",", $section->sequence);
  51 + foreach ($sectionmods as $sectionmod) {
  52 + $mod = $mods[$sectionmod];
  53 + $instance = get_record("$mod->modname", "id", "$mod->instance");
  54 + $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
  55 + if (file_exists($libfile)) {
  56 + require_once($libfile);
  57 + $gradefunction = $mod->modname."_grades";
  58 + if (function_exists($gradefunction)) { // Skip modules without grade function
  59 + $image = "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\"".
  60 + " TITLE=\"$mod->modfullname\">".
  61 + "<IMG BORDER=0 VALIGN=absmiddle SRC=\"../mod/$mod->modname/icon.gif\" ".
  62 + "HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\"></A>";
  63 + $columns[] = "$image ".
  64 + "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
  65 + "$instance->name".
  66 + "</A>";
  67 +
  68 + $modgrades = $gradefunction($mod->instance);
  69 +
  70 + foreach ($students as $student) {
  71 + $grades[$student->id][] = $modgrades[$student->id]->grade; // may be empty, that's ok
  72 + }
  73 + }
  74 + }
  75 + }
  76 + }
  77 + }
  78 + } // a new Moodle nesting record? ;-)
  79 +
  80 + $table->head = array ("", get_string("name"));
  81 + $table->head = array_merge($table->head, $columns);
  82 + $table->width = array(35, "");
  83 + $table->align = array("LEFT", "LEFT");
  84 + foreach ($columns as $column) {
  85 + $table->width[] = "";
  86 + $table->align[] = "CENTER";
  87 + }
  88 +
  89 + foreach ($grades as $studentid => $gradelist) {
  90 + $student = $students[$studentid];
  91 + $picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
  92 + $name = array ("$picture", "$student->firstname&nbsp;$student->lastname");
  93 + $table->data[] = array_merge($name, $gradelist);
  94 + }
  95 +
  96 + print_table($table);
  97 +
  98 + print_footer($course);
  99 +
  100 +?>
3  course/lib.php
@@ -534,6 +534,9 @@ function print_course_admin_links($course, $width=180) {
534 534 $admindata[]="<A HREF=\"teachers.php?id=$course->id\">$course->teachers...</A>";
535 535 $adminicon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
536 536
  537 + $admindata[]="<A HREF=\"grades.php?id=$course->id\">".get_string("grades")."...</A>";
  538 + $adminicon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/grades.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
  539 +
537 540 $admindata[]="<A HREF=\"log.php?id=$course->id\">".get_string("logs")."...</A>";
538 541 $adminicon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/log.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
539 542 $admindata[]="<A HREF=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</A>";
BIN  pix/i/grades.gif

0 comments on commit 3486b7b

Please sign in to comment.
Something went wrong with that request. Please try again.