]> git.mjollnir.org Git - moodle.git/commitdiff
Grade display for current user
authormoodler <moodler>
Wed, 1 Jan 2003 06:42:11 +0000 (06:42 +0000)
committermoodler <moodler>
Wed, 1 Jan 2003 06:42:11 +0000 (06:42 +0000)
course/grade.php [new file with mode: 0644]

diff --git a/course/grade.php b/course/grade.php
new file mode 100644 (file)
index 0000000..c7a9d03
--- /dev/null
@@ -0,0 +1,99 @@
+<?PHP // $Id$
+      // Displays all grades for a student in a course
+
+       require("../config.php");
+       require("lib.php");
+    require("../lib/psxlsgen.php");
+
+    require_variable($id);              // course id
+
+    if (! $course = get_record("course", "id", $id)) {
+        error("Course ID was incorrect");
+    }
+
+       require_login($course->id);
+
+    $strgrades = get_string("grades");
+    $strgrade = get_string("grade");
+    $strmax = get_string("maximumshort");
+    $stractivityreport = get_string("activityreport");
+
+
+/// Get a list of all students
+
+    $columnhtml = array();  // Accumulate column html in this array.
+    $grades = array();      // Collect all grades in this array
+    $maxgrades = array();   // Collect all max grades in this array
+    $totalgrade = 0;
+
+
+/// Collect modules data
+    get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
+
+
+/// Search through all the modules, pulling out grade data
+    $sections = get_all_sections($course->id); // Sort everything the same as the course
+    for ($i=0; $i<=$course->numsections; $i++) {
+        if (isset($sections[$i])) {   // should always be true
+            $section = $sections[$i];
+            if (!empty($section->sequence)) {
+                $sectionmods = explode(",", $section->sequence);
+                foreach ($sectionmods as $sectionmod) {
+                    $mod = $mods[$sectionmod];
+                    $instance = get_record("$mod->modname", "id", "$mod->instance");
+                    $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
+                    if (file_exists($libfile)) {
+                        require_once($libfile);
+                        $gradefunction = $mod->modname."_grades";
+                        if (function_exists($gradefunction)) {   // Skip modules without grade function
+                            if ($modgrades = $gradefunction($mod->instance)) {
+
+                                $image = "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\"".
+                                         "   TITLE=\"$mod->modfullname\">".
+                                         "<IMG BORDER=0 VALIGN=absmiddle SRC=\"../mod/$mod->modname/icon.gif\" ".
+                                         "HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\"></A>";
+                                $columnhtml[] = "$image ".
+                                             "<A HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
+                                             "$instance->name".
+                                             "</A>$maxgrade";
+    
+                                $grades[]  = $modgrades->grades[$USER->id]; // may be empty, that's ok
+
+                                $maxgrades[] = $modgrades->maxgrade;
+
+                                if (!empty($modgrades->maxgrade)) {
+                                    $totalgrade += (float)$modgrades->grades[$USER->id];
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    } 
+
+
+/// OK, we have all the data, now present it to the user
+
+    print_header("$course->shortname: $strgrades", "$course->fullname", 
+                 "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> 
+                  -> $strgrades");
+    
+    print_heading($strgrades);
+
+    $table->head  = array( get_string("activity"), get_string("maximumgrade"), get_string("grade"));
+    $table->align = array("LEFT", "RIGHT", "RIGHT");
+
+    foreach ($grades as $key => $grade) {
+        $table->data[] = array($columnhtml[$key], $maxgrades[$key], $grade);
+    }
+
+    $table->data[] = array("", get_string("total"), $totalgrade);
+
+    print_table($table);
+
+    print_continue("view.php?id=$course->id");
+
+    print_footer($course);
+    
+?>