Added a basic report and some clean-ups
authormoodler <moodler>
Sun, 13 Oct 2002 13:51:56 +0000 (13:51 +0000)
committermoodler <moodler>
Sun, 13 Oct 2002 13:51:56 +0000 (13:51 +0000)
mod/quiz/lib.php
mod/quiz/report.php [new file with mode: 0644]
mod/quiz/view.php

index f34fda82c4865672295f99e1a748ad34a6be2582..8e463770e7b9f240459bdb1d61c65b0f32e2e2aa 100644 (file)
@@ -248,6 +248,16 @@ function quiz_get_best_grade($quizid, $userid) {
     return $grade->grade;
 }
 
+function quiz_get_grade_records($quiz) {
+/// Gets all info required to display the table of quiz results
+/// for report.php
+
+    return get_records_sql("SELECT qg.*, u.firstname, u.lastname, u.picture 
+                            FROM quiz_grades qg, user u
+                            WHERE qg.quiz = '$quiz->id'
+                              AND qg.user = u.id");
+}
+
 function quiz_save_best_grade($quiz, $user) {
 /// Calculates the best grade out of all attempts at a quiz for a user,
 /// and then saves that grade in the quiz_grades table.
diff --git a/mod/quiz/report.php b/mod/quiz/report.php
new file mode 100644 (file)
index 0000000..bd9b878
--- /dev/null
@@ -0,0 +1,93 @@
+<?PHP  // $Id$
+
+// This page prints a particular instance of quiz
+
+    require("../../config.php");
+    require("lib.php");
+
+    optional_variable($id);    // Course Module ID, or
+    optional_variable($q);     // quiz ID
+
+    if ($id) {
+        if (! $cm = get_record("course_modules", "id", $id)) {
+            error("Course Module ID was incorrect");
+        }
+    
+        if (! $course = get_record("course", "id", $cm->course)) {
+            error("Course is misconfigured");
+        }
+    
+        if (! $quiz = get_record("quiz", "id", $cm->instance)) {
+            error("Course module is incorrect");
+        }
+
+    } else {
+        if (! $quiz = get_record("quiz", "id", $q)) {
+            error("Course module is incorrect");
+        }
+        if (! $course = get_record("course", "id", $quiz->course)) {
+            error("Course is misconfigured");
+        }
+        if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
+            error("Course Module ID was incorrect");
+        }
+    }
+
+    require_login($course->id);
+
+    if (!isteacher($course->id)) {
+        error("Only teachers can see this page");
+    }
+
+    add_to_log($course->id, "quiz", "report", "report.php?id=$cm->id", "$quiz->id");
+
+// Print the page header
+
+    if ($course->category) {
+        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+
+    $strquizzes = get_string("modulenameplural", "quiz");
+    $strquiz  = get_string("modulename", "quiz");
+    $strreport  = get_string("report", "quiz");
+    $strname  = get_string("name");
+    $strattempts  = get_string("attempts", "quiz");
+    $strgrade  = get_string("grade", "quiz");
+
+    print_header("$course->shortname: $quiz->name", "$course->fullname",
+                 "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> 
+                  -> <A HREF=\"view.php?id=$cm->id\">$quiz->name</A> -> $strreport", 
+                 "", "", true);
+
+    print_heading($quiz->name);
+
+    if (!$grades = quiz_get_grade_records($quiz)) {
+        print_footer($course);
+        exit;
+    }
+
+    $table->head = array("", $strname, $strattempts, $strgrade);
+    $table->align = array("CENTER", "LEFT", "LEFT", "RIGHT");
+    $table->width = array(10, "*", "*", 20);
+
+    foreach ($grades as $grade) {
+        $picture = print_user_picture($grade->user, $course->id, $grade->picture, false, true);
+
+        if ($attempts = quiz_get_user_attempts($quiz->id, $grade->user)) {
+            foreach ($attempts as $attempt) {
+                $userattempts[] = ($attempt->sumgrades / $quiz->sumgrades) * $quiz->grade;
+            }
+            $userattempts = implode(",", $userattempts);
+        }
+
+        $table->data[] = array ($picture, 
+                                "<A HREF=\"$CFG->wwwroot/user/view.php?id=$grade->user&course=$course->id\">$grade->firstname $grade->lastname</A>", 
+                                "$userattempts", $grade->grade);
+    }
+
+    print_table($table);
+
+// Finish the page
+    print_footer($course);
+
+?>
index 03d3ff2dd10adf69a8e50a5a649a4097aa162d1b..2a2d362b6a8ed8532024c66c4658a8dbfe266253 100644 (file)
 
     print_header("$course->shortname: $quiz->name", "$course->fullname",
                  "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> -> $quiz->name", 
-                  "", "", true, update_module_icon($cm->id, $course->id));
+                 "", "", true, update_module_icon($cm->id, $course->id));
+
+    if (isteacher($course->id)) {
+        if ($allanswers = get_records("quiz_grades", "quiz", $quiz->id)) {
+            $answercount = count($allanswers);
+        } else {
+            $answercount = 0;
+        }
+        echo "<P align=right><A HREF=\"report.php?id=$cm->id\">".get_string("viewallanswers","quiz",$answercount)."</A></P>";
+    }
 
 // Print the main part of the page
 
         $numattempts = 0;
     }
 
-    echo "<P ALIGN=CENTER>You have attempted this quiz $numattempts times, out of $quiz->attempts allowed attempts.</P>";
+    if ($quiz->attempts > 1) {
+        echo "<P ALIGN=CENTER>".get_string("attemptsallowed", "quiz").": $quiz->attempts</P>";
+        echo "<P ALIGN=CENTER>".get_string("grademethod", "quiz").": ".$QUIZ_GRADE_METHOD[$quiz->grademethod]."</P>";
+    }
     if ($numattempts) { 
         $table->head = array("Attempt", "Time", "Grade");
         $table->align = array("CENTER", "LEFT", "RIGHT");
     $mygrade = quiz_get_best_grade($quiz->id, $USER->id);
 
     if ($numattempts < $quiz->attempts) { 
-        $options["id"] = $quiz->id;
-        if ($numattempts) {
-            print_heading("Your best grade so far is $mygrade / $quiz->grade.");
+        if ($available) {
+            $options["id"] = $quiz->id;
+            if ($numattempts) {
+                print_heading("Your best grade so far is $mygrade / $quiz->grade.");
+            }
+            echo "<DIV align=CENTER>";
+            print_single_button("attempt.php", $options, $label="Attempt quiz now");
+            echo "</P>";
         }
-        echo "<DIV align=CENTER>";
-        print_single_button("attempt.php", $options, $label="Attempt quiz now");
-        echo "</P>";
     } else {
-        print_heading("You have no attempts left.  Your final grade is $mygrade / $quiz->grade.");
+        print_heading(get_string("nomoreattempts", "quiz"));
+        print_heading(get_string("yourfinalgradeis", "quiz", "$mygrade / $quiz->grade"));
     }