From: tjhunt Date: Thu, 15 May 2008 15:32:43 +0000 (+0000) Subject: MDL-14857 - Clean up summary table generation code at the top of the quiz review... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9c22b42ef7dabbd67d7a3e3912a67d7682a3c6b1;p=moodle.git MDL-14857 - Clean up summary table generation code at the top of the quiz review page - This is basically a merge of improvements we made at the OU. --- diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 45ed7b689b..ed58394af9 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -384,6 +384,8 @@ $string['onlyteachersimport'] = 'Only teachers with editing rights can import qu $string['openclosedatesupdated'] = 'Quiz open and close dates updated'; $string['optional'] = 'optional'; $string['outof'] = '$a->grade out of a maximum of $a->maxgrade'; +$string['outofpercent'] = '$a->grade out of a maximum of $a->maxgrade ($a->percent%%)'; +$string['outofshort'] = '$a->grade/$a->maxgrade'; $string['overallfeedback'] = 'Overall feedback'; $string['overdue'] = 'Overdue'; $string['pagesize'] = 'Attempts shown per page:'; diff --git a/mod/quiz/review.php b/mod/quiz/review.php index b6e7cf8c85..d61e089c33 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -128,11 +128,9 @@ $accessmanager->print_finish_review_link($canpreview); } -/// Print infobox +/// Work out some time-related things. $timelimit = (int)$quiz->timelimit * 60; $overtime = 0; - $grade = quiz_rescale_grade($attempt->sumgrades, $quiz); - $feedback = quiz_feedback_for_grade($grade, $attempt->quiz); if ($attempt->timefinish) { if ($timetaken = ($attempt->timefinish - $attempt->timestart)) { @@ -147,39 +145,54 @@ } else { $timetaken = get_string('unfinished', 'quiz'); } - echo ''; + +/// Print summary table about the whole attempt. +/// First we assemble all the rows that are appopriate to the current situation in +/// an array, then later we only output the table if there are any rows to show. + $rows = array(); if ($attempt->userid <> $USER->id) { $student = get_record('user', 'id', $attempt->userid); $picture = print_user_picture($student, $course->id, $student->picture, false, true); - echo ''; + $rows[] = ''; } - if (has_capability('mod/quiz:grade', $context) and + if (has_capability('mod/quiz:viewreports', $context) && count($attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND userid = '$attempt->userid'", 'attempt ASC')) > 1) { - // print list of attempts - $attemptlist = ''; + /// List of all this user's attempts for people who can see reports. + $urloptions = ''; + if ($showall) { + $urloptions .= '&showall=true'; + } else if ($page > 0) { + $urloptions .= '&page=' . $page; + } + $attemptlist = array(); foreach ($attempts as $at) { - $attemptlist .= ($at->id == $attempt->id) - ? ''.$at->attempt.', ' - : ''.$at->attempt.', '; + if ($at->id == $attempt->id) { + $attemptlist[] = '' . $at->attempt . ''; + } else { + $attemptlist[] = '' . $at->attempt . ''; + } } - echo ''; + $rows[] = ''; } - echo ''; +/// Timing information. + $rows[] = ''; if ($attempt->timefinish) { - echo ''; - echo ''; + $rows[] = ''; + $rows[] = ''; } if (!empty($overtime)) { - echo ''; + $rows[] = ''; } - //if the student is allowed to see their score + +/// Show scores (if the user is allowed to see scores at the moment). + $grade = quiz_rescale_grade($attempt->sumgrades, $quiz); if ($options->scores) { if ($quiz->grade and $quiz->sumgrades) { if($overtime) { @@ -187,22 +200,38 @@ $result->grade = "0.0"; } + /// Show raw marks only if they are different from the grade (like on the view page. + if ($quiz->grade != $quiz->sumgrades) { + $a = new stdClass; + $a->grade = round($attempt->sumgrades, $CFG->quiz_decimalpoints); + $a->maxgrade = $quiz->sumgrades; + $rows[] = ''; + } + + /// Now the scaled grade. $a = new stdClass; - $percentage = round(($attempt->sumgrades/$quiz->sumgrades)*100, 0); - $a->grade = $grade; + $a->grade = '' . $grade . ''; $a->maxgrade = $quiz->grade; - $rawscore = round($attempt->sumgrades, $CFG->quiz_decimalpoints); - echo ''; - echo ''; + $a->percent = '' . round(($attempt->sumgrades/$quiz->sumgrades)*100, 0) . ''; + $rows[] = ''; } } + +/// Feedback if there is any, and the user is allowed to see it now. + $feedback = quiz_feedback_for_grade($grade, $attempt->quiz); if ($options->overallfeedback && $feedback) { - echo ''; + $rows[] = ''; + } + +/// Now output the summary table, if there are any rows to be shown. + if (!empty($rows)) { + echo '
', $picture, '', - fullname($student, true), '
' . $picture . '' . + fullname($student, true) . '
', get_string('attempts', 'quiz'), '', - trim($attemptlist, ' ,'), '
' . get_string('attempts', 'quiz') . + '' . implode(', ', $attemptlist) . '
', get_string('startedon', 'quiz'), '', - userdate($attempt->timestart), '
' . get_string('startedon', 'quiz') . + '' . userdate($attempt->timestart) . '
', get_string('completedon', 'quiz'), '', - userdate($attempt->timefinish), '
', get_string('timetaken', 'quiz'), '', - $timetaken, '
' . get_string('completedon', 'quiz') . '' . + userdate($attempt->timefinish) . '
' . get_string('timetaken', 'quiz') . '' . + $timetaken . '
', get_string('overdue', 'quiz'), '',$overtime, '
' . get_string('overdue', 'quiz') . '' . $overtime . '
' . get_string('marks', 'quiz') . '' . + get_string('outofshort', 'quiz', $a) . '
', get_string('score', 'quiz'), '', - "$rawscore/$quiz->sumgrades ($percentage%)", '
', get_string('grade'), '', - get_string('outof', 'quiz', $a), '
' . get_string('grade') . '' . + get_string('outofpercent', 'quiz', $a) . '
', get_string('feedback', 'quiz'), '', - $feedback, '
' . get_string('feedback', 'quiz') . + '' . $feedback . '
', "\n"; + echo implode("\n", $rows); + echo "\n
\n"; } - echo ''; /// Print the navigation panel if required $numpages = quiz_number_of_pages($attempt->layout); diff --git a/mod/quiz/view.php b/mod/quiz/view.php index b4c9b35a7b..ff637a3d8f 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -172,14 +172,6 @@ print_heading(get_string('summaryofattempts', 'quiz')); - // Get some strings. - $strattempt = get_string("attempt", "quiz"); - $strtimetaken = get_string("timetaken", "quiz"); - $strtimecompleted = get_string("timecompleted", "quiz"); - $strgrade = get_string("grade"); - $strmarks = get_string('marks', 'quiz'); - $strfeedback = get_string('feedback', 'quiz'); - // Work out which columns we need, taking account what data is available in each attempt. list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context); @@ -192,26 +184,26 @@ // Prepare table header $table->class = 'generaltable quizattemptsummary'; - $table->head = array($strattempt, $strtimecompleted); - $table->align = array("center", "left"); - $table->size = array("", ""); + $table->head = array(get_string('attempt', 'quiz'), get_string('timecompleted', 'quiz')); + $table->align = array('center', 'left'); + $table->size = array('', ''); if ($markcolumn) { - $table->head[] = "$strmarks / $quiz->sumgrades"; + $table->head[] = get_string('marks', 'quiz') . " / $quiz->sumgrades"; $table->align[] = 'center'; $table->size[] = ''; } if ($gradecolumn) { - $table->head[] = "$strgrade / $quiz->grade"; + $table->head[] = get_string('grade') . " / $quiz->grade"; $table->align[] = 'center'; $table->size[] = ''; } if ($feedbackcolumn) { - $table->head[] = $strfeedback; + $table->head[] = get_string('feedback', 'quiz'); $table->align[] = 'left'; $table->size[] = ''; } if (isset($quiz->showtimetaken)) { - $table->head[] = $strtimetaken; + $table->head[] = get_string('timetaken', 'quiz'); $table->align[] = 'left'; $table->size[] = ''; }