From 579ddad5ef181299080f8d75641f392300649441 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 13 Oct 2002 13:51:56 +0000 Subject: [PATCH] Added a basic report and some clean-ups --- mod/quiz/lib.php | 10 +++++ mod/quiz/report.php | 93 +++++++++++++++++++++++++++++++++++++++++++++ mod/quiz/view.php | 33 +++++++++++----- 3 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 mod/quiz/report.php diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index f34fda82c4..8e463770e7 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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 index 0000000000..bd9b878f4b --- /dev/null +++ b/mod/quiz/report.php @@ -0,0 +1,93 @@ +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 = "id\">$course->shortname ->"; + } + + $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 id>$strquizzes + -> id\">$quiz->name -> $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, + "wwwroot/user/view.php?id=$grade->user&course=$course->id\">$grade->firstname $grade->lastname", + "$userattempts", $grade->grade); + } + + print_table($table); + +// Finish the page + print_footer($course); + +?> diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 03d3ff2dd1..2a2d362b6a 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -57,7 +57,16 @@ print_header("$course->shortname: $quiz->name", "$course->fullname", "$navigation id>$strquizzes -> $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 "

id\">".get_string("viewallanswers","quiz",$answercount)."

"; + } // Print the main part of the page @@ -80,7 +89,10 @@ $numattempts = 0; } - echo "

You have attempted this quiz $numattempts times, out of $quiz->attempts allowed attempts.

"; + if ($quiz->attempts > 1) { + echo "

".get_string("attemptsallowed", "quiz").": $quiz->attempts

"; + echo "

".get_string("grademethod", "quiz").": ".$QUIZ_GRADE_METHOD[$quiz->grademethod]."

"; + } if ($numattempts) { $table->head = array("Attempt", "Time", "Grade"); $table->align = array("CENTER", "LEFT", "RIGHT"); @@ -95,15 +107,18 @@ $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 "
"; + print_single_button("attempt.php", $options, $label="Attempt quiz now"); + echo "

"; } - echo "
"; - print_single_button("attempt.php", $options, $label="Attempt quiz now"); - echo "

"; } 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")); } -- 2.39.5