]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-6376 - fix minor errors in the previous commit.
authortjhunt <tjhunt>
Tue, 30 Oct 2007 19:29:45 +0000 (19:29 +0000)
committertjhunt <tjhunt>
Tue, 30 Oct 2007 19:29:45 +0000 (19:29 +0000)
More significantly, this patch changes the '1 Students have made 1 attempts' string.

To start with, this code was being produced in five different places, so I made a function to do the work!. Next, as you can see, it is not gramatical. Also, some people find it confusing, as in MDL-6376.

Therefore, it now just says 'Attempts: 1'.

Merged from MOODLE_19_STABLE.

lang/en_utf8/quiz.php
lib/questionlib.php
mod/quiz/edit.php
mod/quiz/index.php
mod/quiz/lib.php
mod/quiz/report/overview/report.php
mod/quiz/view.php

index 690ad9aaa50700a0b53ceeeffd52168b7c7e7354..c996ac785aea311c4da74d092aa957b2ab4ecc93 100644 (file)
@@ -60,6 +60,7 @@ $string['attemptsallowed'] = 'Attempts allowed';
 $string['attemptsdeleted'] = 'Quiz attempts deleted';
 $string['attemptselection'] = 'Select which attempts to analyze per user:';
 $string['attemptsexist'] = 'You can no longer add or remove questions.';
+$string['attemptsnum'] = 'Attempts: $a';
 $string['attemptsonly'] = 'Show only students with attempts';
 $string['attemptsunlimited'] = 'Unlimited attempts';
 $string['back'] = 'Back to preview question';
index 20d649857f696606f0f788a9852b6818d73f4170..60eb20292288c263445625d077822a094c93c8d9 100644 (file)
@@ -1891,8 +1891,7 @@ function default_export_filename($course,$category) {
     $export_name .= moodle_strtolower($export_categoryname)."-";
     //The date format
     $export_name .= userdate(time(),$export_date_format,99,false);
-    //The extension - no extension, supplied by format
-    // $export_name .= ".txt";
+    //Extension is supplied by format later.
 
     return $export_name;
 }
index 03112733b3e0c08382fb133e62b82be5ff4d8f85..04aacad65b98ba600c2f090641bc75442b5c7bd3 100644 (file)
 
         print_box_start();
 
-        $a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0);
-        $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
-        $a->studentstring  = $course->students;
-
         echo "<div class=\"attemptsnotice\">\n";
-        echo "<a href=\"report.php?mode=overview&amp;id=$cm->id\">".get_string('numattempts', 'quiz', $a)."</a><br />".get_string("attemptsexist","quiz");
+        echo "<a href=\"report.php?mode=overview&amp;id=$cm->id\">".quiz_num_attempt_summary($quiz)."</a><br />".get_string("attemptsexist","quiz");
         echo "</div><br />\n";
 
         $sumgrades = quiz_print_question_list($quiz,  $thispageurl, false, $quiz_showbreaks, $quiz_reordertool);
index 3de177a3d2f7326d823f9948f14e0b268daabfaa..54d19c736060f6b3ae1bc7228e4e905123aa6e46 100644 (file)
         }
 
         if ($showing == 'stats') {
-
-            // Number of students who have attempted this quiz.
-            if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
-                $a->studentnum = count_records_select('quiz_attempts',
-                        "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
-                $a->studentstring  = $course->students;
-                $data[] = "<a href=\"report.php?mode=overview&amp;q=$quiz->id\">" .
-                        get_string('numattempts', 'quiz', $a) . '</a>';
-            } else {
-                $data[] = '';
-            }
+            $data[] = quiz_num_attempt_summary($quiz);
         } else if ($showing = 'scores') {
 
             // Grade and feedback.
index abacd41dc009e82b5054991a268a7309f7c2f200..a5dffeecfcc8754389770e4bdac5d7f8023bc6a5 100644 (file)
@@ -1023,7 +1023,7 @@ function quiz_print_overview($courses, &$htmlarray) {
 
 /// We want to list quizzes that are currently available, and which have a close date.
 /// This is the same as what the lesson does, and the dabate is in MDL-10568.
-    $now = date();
+    $now = time();
     foreach ($quizs as $quiz) {
         if ($quiz->timeclose >= $now && $quiz->timeopen < $now) {
         /// Give a link to the quiz, and the deadline.
@@ -1037,15 +1037,7 @@ function quiz_print_overview($courses, &$htmlarray) {
             $context = get_context_instance(CONTEXT_MODULE, $quiz->coursemodule);
             if (has_capability('mod/quiz:viewreports', $context)) {
             /// For teacher-like people, show a summary of the number of student attempts.
-                $a = new stdClass;
-                if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
-                    $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
-                } else {
-                    $a->studentnum = 0;
-                    $a->attemptnum = 0;
-                }
-                $a->studentstring  = $course->students;
-                $str .= '<div class="info">' . get_string('numattempts', 'quiz', $a) . '</div>';
+                $str .= '<div class="info">' . quiz_num_attempt_summary($quiz, true) . '</div>';
             } else if (has_capability('mod/quiz:attempt', $context)){ // Student
             /// For student-like people, tell them how many attempts they have made.
                 if (isset($USER->id) && ($attempts = quiz_get_user_attempts($quiz->id, $USER->id))) {
@@ -1069,4 +1061,19 @@ function quiz_print_overview($courses, &$htmlarray) {
         }
     }
 }
+
+/**
+ * Return a textual summary of the number of attemtps that have been made at a particular quiz,
+ * returns '' if no attemtps have been made yet, unless $returnzero is passed as true.
+ * @param object $quiz the quiz object. Only $quiz->id is used at the moment.
+ * @param boolean $returnzero if false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'. 
+ * @return string a string like "Attempts: 123".
+ */
+function quiz_num_attempt_summary($quiz, $returnzero = false) {
+    $numattempts = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0);
+    if ($numattempts || $returnzero) {
+        return get_string('attemptsnum', 'quiz', $numattempts);
+    }
+    return '';
+}
 ?>
index 13bfde6f77dd91f23709bd5373718502d9b4617b..cadfcf18e17558c70b629b1b631dc457152184fb 100644 (file)
@@ -74,14 +74,8 @@ class quiz_report extends quiz_default_report {
 
         // Print information on the number of existing attempts
         if (!$download) { //do not print notices when downloading
-            if ($attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
-                $a = new stdClass;
-                $a->attemptnum = $attemptnum;
-                $a->studentnum = count_records_select('quiz_attempts',
-                        "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
-                $a->studentstring = $course->students;
-
-                notify(get_string('numattempts', 'quiz', $a));
+            if ($strattemptnum = quiz_num_attempt_summary($quiz)) {
+                notify($strattemptnum);
             }
         }
 
index 906971a6a48f03284dd7ed73e6860b74c19057c2..e77ad5552b739c41d549d4b16ca70da05a709faf 100644 (file)
 
     // Show number of attempts summary to those who can view reports.
     if (has_capability('mod/quiz:viewreports', $context)) {
-        if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
-            $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
-            $a->studentstring  = $course->students;
-
-            notify("<a href=\"report.php?mode=overview&amp;id=$cm->id\">".get_string('numattempts', 'quiz', $a).'</a>');
+        if ($strattemptnum = quiz_num_attempt_summary($quiz)) {
+            notify("<a href=\"report.php?mode=overview&amp;id=$cm->id\">" . $strattemptnum . '</a>');
         }
     }