From a6478fdc0d7f5b0b08eff40286bcacad72a88c1e Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 17 Dec 2003 13:04:47 +0000 Subject: [PATCH] Improved overview, now allows deleting and shows more info. Thanks very much for Thomas Robb for submitting the original modification with the new functionality ... I ended up doing a lot of cleaning up and reworking of it but it wouldn't have been done without Thom's work. --- mod/quiz/report/overview/report.php | 119 +++++++++++++++++++++++++--- 1 file changed, 109 insertions(+), 10 deletions(-) diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index c4ddecdc94..962819b21f 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -1,4 +1,4 @@ -grademethod]; + $strtimeformat = get_string('strftimedatetime'); + + + if (!empty($del)) { /// Some attempts need to be deleted + + if (record_exists('quiz_attempts', 'quiz', $quiz->id)) { + + if ($del == 'all'){ /// Delete all the attempts + $attempts = get_records('quiz_attempts','quiz',$quiz->id); + delete_records('quiz_attempts','quiz',$quiz->id); + delete_records('quiz_grades','quiz',$quiz->id); + if ($attempts) { + foreach ($attempts as $thisattempt){ + delete_records('quiz_responses','attempt',$thisattempt->id); + } + } + + } else { /// Delete selected attempts + + $items = (array)data_submitted(); + + unset($items['del']); + unset($items['id']); + + if ($items) { + foreach ($items as $attemptid) { + if ($todelete = get_record('quiz_attempts', 'id', $attemptid)) { + delete_records('quiz_attempts', 'id', $attemptid); + delete_records('quiz_responses', 'attempt', $attemptid); + + // Search quiz_attempts for other instances by this user. + // If none, then delete record for this quiz, this user from quiz_grades + // else recalculate best grade + + $userid = $todelete->userid; + if (!record_exists('quiz_attempts', 'userid', $userid, 'quiz',$quiz->id)) { + delete_records('quiz_grades', 'userid', $userid,'quiz',$quiz->id); + } else { + quiz_save_best_grade($quiz, $userid); + } + } + } + } + } + } + } + + if (!$grades = quiz_get_grade_records($quiz)) { + print_heading($strnoattempts); + return true; + } $table->head = array(" ", $strname, $strattempts, "$strbestgrade /$quiz->grade"); $table->align = array("center", "left", "left", "center"); @@ -24,21 +75,69 @@ class quiz_report extends quiz_default_report { foreach ($grades as $grade) { $picture = print_user_picture($grade->userid, $course->id, $grade->picture, false, true); - + if ($attempts = quiz_get_user_attempts($quiz->id, $grade->userid)) { - $userattempts = quiz_get_user_attempts_string($quiz, $attempts, $grade->grade); + $userattempts = $this->quiz_get_user_attempts_list($quiz, $attempts, $grade->grade, $strtimeformat); + } else { + $userattempts = ""; } - + $table->data[] = array ($picture, "wwwroot/user/view.php?id=$grade->userid&course=$course->id\">". "$grade->firstname $grade->lastname", "$userattempts", round($grade->grade,0)); } - + + //Embed script for warning + echo "\n\n"; + + $onsub = "return confirm('$strreallydel')"; + + echo "
\n"; + echo "\n"; + echo "id\">\n"; + print_table($table); + + //There might be a more elegant way than using the
tag for this + echo "
 "; + echo "\n
\n"; + echo "\n"; return true; } + + function quiz_get_user_attempts_list($quiz, $attempts, $bestgrade, $timeformat) { + /// Returns a little list of all attempts, one per line, + /// with each grade linked to the feedback report and with the best grade highlighted + /// Each also has information about date and lapsed time + + $bestgrade = format_float($bestgrade); + + foreach ($attempts as $attempt) { + $attemptgrade = format_float(($attempt->sumgrades / $quiz->sumgrades) * $quiz->grade); + $attemptdate = userdate($attempt->timestart, $timeformat); + if ($attempt->timefinish) { + $attemptlapse = date("I:s", $attempt->timefinish - $attempt->timestart); + } else { + $attemptlapse = "..."; + } + $button = "id\" value=\"$attempt->id\">"; + $revurl = "review.php?q=$quiz->id&attempt=$attempt->id"; + if ($attemptgrade == $bestgrade) { + $userattempts[] = "$button $attemptgrade $attemptdate ($attemptlapse)"; + } else { + $userattempts[] = "$button $attemptgrade $attemptdate ($attemptlapse)"; + } + } + return implode("
\n", $userattempts); + } + } ?> -- 2.39.5