]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14857 - Clean up summary table generation code at the top of the quiz review...
authortjhunt <tjhunt>
Thu, 15 May 2008 15:32:43 +0000 (15:32 +0000)
committertjhunt <tjhunt>
Thu, 15 May 2008 15:32:43 +0000 (15:32 +0000)
lang/en_utf8/quiz.php
mod/quiz/review.php
mod/quiz/view.php

index 45ed7b689b67beda872070155b5d2f102086ff29..ed58394af91da94b29a34e78805075ff363eaadf 100644 (file)
@@ -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:';
index b6e7cf8c8569eaa869eeab6d44108416745b5b27..d61e089c3309692f05d00df5b8212941d4fe8f18 100644 (file)
         $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)) {
     } else {
         $timetaken = get_string('unfinished', 'quiz');
     }
-    echo '<table class="generaltable generalbox quizreviewsummary"><tbody>';
+
+/// 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 '<tr><th scope="row" class="cell">', $picture, '</th><td class="cell"><a href="', $CFG->wwwroot,
-            '/user/view.php?id=', $student->id, '&amp;course='.$course->id.'">',
-            fullname($student, true), '</a></td></tr>';
+        $rows[] = '<tr><th scope="row" class="cell">' . $picture . '</th><td class="cell"><a href="' .
+                $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&amp;course=' . $course->id . '">' .
+                fullname($student, true) . '</a></td></tr>';
     }
-    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 .= '&amp;showall=true';
+        } else if ($page > 0) {
+            $urloptions .= '&amp;page=' . $page;
+        }
+        $attemptlist = array();
         foreach ($attempts as $at) {
-            $attemptlist .= ($at->id == $attempt->id)
-                ? '<strong>'.$at->attempt.'</strong>, '
-                : '<a href="review.php?attempt='.$at->id.($showall?'&amp;showall=true':'').'">'.$at->attempt.'</a>, ';
+            if ($at->id == $attempt->id) {
+                $attemptlist[] = '<strong>' . $at->attempt . '</strong>';
+            } else {
+                $attemptlist[] = '<a href="review.php?attempt=' . $at->id . $urloptions . ' ">' . $at->attempt . '</a>';
+            }
         }
-        echo '<tr><th scope="row" class="cell">', get_string('attempts', 'quiz'), '</th><td class="cell">',
-                trim($attemptlist, ' ,'), '</td></tr>';
+        $rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') .
+                '</th><td class="cell">' . implode(', ', $attemptlist) . '</td></tr>';
     }
 
-    echo '<tr><th scope="row" class="cell">', get_string('startedon', 'quiz'), '</th><td class="cell">',
-            userdate($attempt->timestart), '</td></tr>';
+/// Timing information.
+    $rows[] = '<tr><th scope="row" class="cell">' . get_string('startedon', 'quiz') .
+            '</th><td class="cell">' . userdate($attempt->timestart) . '</td></tr>';
     if ($attempt->timefinish) {
-        echo '<tr><th scope="row" class="cell">', get_string('completedon', 'quiz'), '</th><td class="cell">',
-                userdate($attempt->timefinish), '</td></tr>';
-        echo '<tr><th scope="row" class="cell">', get_string('timetaken', 'quiz'), '</th><td class="cell">',
-                $timetaken, '</td></tr>';
+        $rows[] = '<tr><th scope="row" class="cell">' . get_string('completedon', 'quiz') . '</th><td class="cell">' .
+                userdate($attempt->timefinish) . '</td></tr>';
+        $rows[] = '<tr><th scope="row" class="cell">' . get_string('timetaken', 'quiz') . '</th><td class="cell">' .
+                $timetaken . '</td></tr>';
     }
     if (!empty($overtime)) {
-        echo '<tr><th scope="row" class="cell">', get_string('overdue', 'quiz'), '</th><td class="cell">',$overtime, '</td></tr>';
+        $rows[] = '<tr><th scope="row" class="cell">' . get_string('overdue', 'quiz') . '</th><td class="cell">' . $overtime . '</td></tr>';
     }
-    //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) {
                 $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[] = '<tr><th scope="row" class="cell">' . get_string('marks', 'quiz') . '</th><td class="cell">' .
+                        get_string('outofshort', 'quiz', $a) . '</td></tr>';
+            }
+
+        /// Now the scaled grade.
             $a = new stdClass;
-            $percentage = round(($attempt->sumgrades/$quiz->sumgrades)*100, 0);
-            $a->grade = $grade;
+            $a->grade = '<b>' . $grade . '</b>';
             $a->maxgrade = $quiz->grade;
-            $rawscore = round($attempt->sumgrades, $CFG->quiz_decimalpoints);
-            echo '<tr><th scope="row" class="cell">', get_string('score', 'quiz'), '</th><td class="cell">',
-                "$rawscore/$quiz->sumgrades ($percentage%)", '</td></tr>';
-            echo '<tr><th scope="row" class="cell">', get_string('grade'), '</th><td class="cell">',
-                get_string('outof', 'quiz', $a), '</td></tr>';
+            $a->percent = '<b>' . round(($attempt->sumgrades/$quiz->sumgrades)*100, 0) . '</b>';
+            $rows[] = '<tr><th scope="row" class="cell">' . get_string('grade') . '</th><td class="cell">' .
+                    get_string('outofpercent', 'quiz', $a) . '</td></tr>';
         }
     }
+
+/// 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 '<tr><th scope="row" class="cell">', get_string('feedback', 'quiz'), '</th><td class="cell">',
-                $feedback, '</td></tr>';
+        $rows[] = '<tr><th scope="row" class="cell">' . get_string('feedback', 'quiz') .
+                '</th><td class="cell">' . $feedback . '</td></tr>';
+    }
+
+/// Now output the summary table, if there are any rows to be shown.
+    if (!empty($rows)) {
+        echo '<table class="generaltable generalbox quizreviewsummary"><tbody>', "\n";
+        echo implode("\n", $rows);
+        echo "\n</tbody></table>\n";
     }
-    echo '</tbody></table>';
 
 /// Print the navigation panel if required
     $numpages = quiz_number_of_pages($attempt->layout);
index b4c9b35a7bb774e2c02f3ddd4954a862c70628f7..ff637a3d8fc84353e5b6c24e7f43accbb95272e4 100644 (file)
 
         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);
 
 
         // 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[] = '';
         }