Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

New feature:

Maximum-number-of-questions-per-page
  • Loading branch information...
commit d70ccc495ca904789940f281655b94d9a8e8637b 1 parent edb42f0
authored January 03, 2005
2  lang/en/quiz.php
@@ -11,6 +11,7 @@
11 11
 $string['addrandom2'] = 'random questions ';
12 12
 $string['addselectedtoquiz'] = 'Add selected to quiz';
13 13
 $string['aiken'] = 'Aiken format';
  14
+$string['allinone'] = 'Unlimited';
14 15
 $string['allowreview'] = 'Allow review';
15 16
 $string['alreadysubmitted'] = 'It is likely that you have already submitted this attempt';
16 17
 $string['alternativeunits'] = 'Alternative Units';
@@ -199,6 +200,7 @@
199 200
 $string['questionname'] = 'Question name';
200 201
 $string['questionnametoolong'] = 'Question name too long at line $a (255 char. max). It has been truncated.';
201 202
 $string['questions'] = 'Questions';
  203
+$string['questionsperpage'] = 'Max number of questions per page';
202 204
 $string['quizavailable'] = 'The quiz is available until: $a';
203 205
 $string['quizclose'] = 'Close the quiz';
204 206
 $string['quizclosed'] = 'This quiz closed on $a';
78  mod/quiz/attempt.php
@@ -165,6 +165,9 @@
165 165
             } else if ('shuffleorder' == $key) {
166 166
                 $shuffleorder = explode(",", $value);   // Actual order questions were given in
167 167
 
  168
+            } else if ('navigation' == $key) {
  169
+                $navigation = $value;   // Determines next page to show in quiz
  170
+
168 171
             } else {  // Useful for debugging new question types.  Must be last.
169 172
                 error("Unrecognizable input has been posted ($key -> $value)");
170 173
             }
@@ -184,13 +187,16 @@
184 187
             $questions[$qid]->maxgrade = $grade->grade;
185 188
         }
186 189
 
187  
-        if (!$result = quiz_grade_responses($quiz, $questions)) {
  190
+        if (!$result = quiz_grade_responses($quiz, $questions, $unattempt->id)) {
188 191
             error("Could not grade your quiz attempt!");
189 192
         }
190 193
 
191  
-        if ($attempt = quiz_save_attempt($quiz, $questions, $result, $attemptnumber)) {
192  
-            add_to_log($course->id, "quiz", "submit",
  194
+        if ($attempt = quiz_save_attempt($quiz, $questions, $result,
  195
+                                         $attemptnumber, 0 == $navigation)) {
  196
+            if (empty($navigation)) {
  197
+                add_to_log($course->id, "quiz", "submit",
193 198
                        "review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id", $cm->id);
  199
+            }
194 200
         } else {
195 201
             notice(get_string("alreadysubmitted", "quiz"), "view.php?id=$cm->id");
196 202
             if (empty($quiz->popup)) {
@@ -199,38 +205,51 @@
199 205
             exit;
200 206
         }
201 207
 
202  
-        if (! quiz_save_best_grade($quiz, $USER->id)) {
203  
-            error("Sorry! Could not calculate your best grade!");
204  
-        }
205  
-        
206  
-        if (empty($quiz->popup) and !$quiz->feedback) {
207  
-            // No need to stop on this page, go directly to view.php
208  
-            redirect('view.php?q='.$quiz->id);
209  
-        }
  208
+        if (empty($navigation)) {
  209
+            /// Attempt has finished
210 210
 
211  
-        $strgrade = get_string("grade");
212  
-        $strscore = get_string("score", "quiz");
  211
+            if (! quiz_save_best_grade($quiz, $USER->id)) {
  212
+                error("Sorry! Could not calculate your best grade!");
  213
+            }
  214
+        
  215
+            if (empty($quiz->popup) and !$quiz->feedback) {
  216
+                // No need to stop on this page, go directly to view.php
  217
+                redirect('view.php?q='.$quiz->id);
  218
+            }
213 219
 
214  
-        if ($quiz->grade) {
215  
-            print_heading("$strscore: $result->sumgrades/$quiz->sumgrades ($result->percentage %)");
216  
-            print_heading("$strgrade: $result->grade/$quiz->grade");
217  
-        }
  220
+            $strgrade = get_string("grade");
  221
+            $strscore = get_string("score", "quiz");
218 222
 
219  
-        /// continue button - use javascript to close down child window if in popup
220  
-        include('attempt_close_js.php');
  223
+            if ($quiz->grade) {
  224
+                print_heading("$strscore: $result->sumgrades/$quiz->sumgrades ($result->percentage %)");
  225
+                print_heading("$strgrade: $result->grade/$quiz->grade");
  226
+            }
221 227
 
222  
-        if ($quiz->feedback) {
223  
-            $quiz->shuffleanswers = false;       // Never shuffle answers in feedback
224  
-            quiz_print_quiz_questions($quiz, $questions, $result, $shuffleorder);
225 228
             /// continue button - use javascript to close down child window if in popup
226 229
             include('attempt_close_js.php');
227  
-        }
228 230
 
229  
-        if (empty($quiz->popup)) {
230  
-            print_footer($course);
231  
-        }
  231
+            if ($quiz->feedback) {
  232
+                $quiz->shuffleanswers = false;       // Never shuffle answers in feedback
  233
+
  234
+                /// Make sure to get all questions in case not all are shown
  235
+                /// in quiz all the time.
  236
+                $questions = quiz_get_attempt_questions($quiz, $attempt);
  237
+                quiz_print_quiz_questions($quiz, $questions,
  238
+                        quiz_grade_responses($quiz, $questions, $unattempt->id),
  239
+                        $shuffleorder);
  240
+                /// continue button - use javascript to close down child window if in popup
  241
+                include('attempt_close_js.php');
  242
+            }
232 243
 
233  
-        exit;
  244
+            if (empty($quiz->popup)) {
  245
+                print_footer($course);
  246
+            }
  247
+
  248
+            exit;
  249
+        }
  250
+    } else {
  251
+        $navigation= 1;
  252
+        $shuffleorder= NULL;
234 253
     }
235 254
 
236 255
 
@@ -289,7 +308,7 @@
289 308
 
290 309
     $questions = quiz_get_attempt_questions($quiz, $attempt, true);
291 310
     if ($quiz->attemptonlast && $attemptnumber >= 2 and
292  
-            $quiz->attempts == 0 || !unattempt) {
  311
+            $quiz->attempts == 0 || !$unattempt) {
293 312
         // There are unlimited attempts or it is a new attempt.
294 313
         // As the attempt also builds on the last, we can here
295 314
         // have the student see the scores of the pre-entered
@@ -303,7 +322,8 @@
303 322
     // We do not show feedback or correct answers during an attempt:
304 323
     $quiz->feedback = $quiz->correctanswers = false;
305 324
     
306  
-    if (!quiz_print_quiz_questions($quiz, $questions, $result)) {
  325
+    if (!quiz_print_quiz_questions($quiz, $questions,
  326
+            $result, $shuffleorder, $navigation)) {
307 327
         print_continue("view.php?id=$cm->id");
308 328
     }
309 329
 
3  mod/quiz/db/mysql.php
@@ -302,6 +302,9 @@ function quiz_upgrade($oldversion) {
302 302
         table_column('quiz_categories', '', 'sortorder', '', '', '', '999');
303 303
     }
304 304
 
  305
+    if ($oldversion < 2005010300) {
  306
+        table_column("quiz", "", "questionsperpage", "integer", "10", "", "0", "not null", "review");
  307
+    }
305 308
     return true;
306 309
 }
307 310
 
1  mod/quiz/db/mysql.sql
@@ -26,6 +26,7 @@ CREATE TABLE `prefix_quiz` (
26 26
   `correctanswers` tinyint(4) NOT NULL default '1',
27 27
   `grademethod` tinyint(4) NOT NULL default '1',
28 28
   `review` tinyint(4) NOT NULL default '0',
  29
+  `questionsperpage` int(10) NOT NULL default '0',
29 30
   `shufflequestions` tinyint(4) NOT NULL default '0',
30 31
   `shuffleanswers` tinyint(4) NOT NULL default '0',
31 32
   `questions` text NOT NULL,
6  mod/quiz/db/postgres7.php
@@ -275,7 +275,7 @@ function quiz_upgrade($oldversion) {
275 275
     }
276 276
 
277 277
     if ($oldversion < 2004120501) {
278  
-        table_column("quiz_calculated", "", "correctanswerformat", "integer", "10", "", "2", "not null", "correctanswerlength");
  278
+        table_column("quiz_calculated", "", "correctanswerformat", "integer", "10", "", "0", "not null", "correctanswerlength");
279 279
     }
280 280
 
281 281
     if ($oldversion < 2004121400) {  // New field to determine popup window behaviour
@@ -287,6 +287,10 @@ function quiz_upgrade($oldversion) {
287 287
         table_column('quiz_categories', '', 'sortorder', '', '', '', '999');
288 288
     }
289 289
 
  290
+    if ($oldversion < 2005010300) {
  291
+        table_column("quiz", "", "questionsperpage", "integer", "10", "", "0", "not null", "review");
  292
+    }
  293
+
290 294
     return true;
291 295
 }
292 296
 
1  mod/quiz/db/postgres7.sql
@@ -26,6 +26,7 @@ CREATE TABLE prefix_quiz (
26 26
   correctanswers integer NOT NULL default '1',
27 27
   grademethod integer NOT NULL default '1',
28 28
   review integer NOT NULL default '0',
  29
+  questionsperpage integer NOT NULL default '0',
29 30
   shufflequestions integer NOT NULL default '0',
30 31
   shuffleanswers integer NOT NULL default '0',
31 32
   questions text NOT NULL default '',
229  mod/quiz/lib.php
@@ -290,6 +290,13 @@ function print_question_formulation_and_controls($question,
290 290
                .'  been implemented for question type '.$this->name());
291 291
     }
292 292
 
  293
+    function actual_number_of_questions($question) {
  294
+        /// Used for the feature number-of-questions-per-page
  295
+        /// to determine the actual number of questions wrapped
  296
+        /// by this question. The default is ONE!
  297
+        return 1;
  298
+    }
  299
+
293 300
     function grade_response($question, $nameprefix) {
294 301
     // Analyzes $question->response[] and determines the result
295 302
     // The result is to be returned in this structure:
@@ -809,7 +816,7 @@ function quiz_get_attempt_questions($quiz, $attempt, $attempting = false) {
809 816
         $prevresponses= array();
810 817
         while (--$prevattempt) {
811 818
             $prevresponses = get_records_sql("
812  
-                    SELECT r.question, r.answer, r.attempt
  819
+                    SELECT r.question, r.answer, r.attempt, r.grade
813 820
                     FROM {$CFG->prefix}quiz_responses r, {$CFG->prefix}quiz_attempts a
814 821
                     WHERE a.quiz='$quiz->id' AND a.userid='$attempt->userid'
815 822
                       AND a.attempt='$prevattempt' AND r.attempt=a.id ");
@@ -984,10 +991,125 @@ function quiz_print_possible_question_image($quizid, $question) {
984 991
     }
985 992
 }
986 993
 
987  
-function quiz_print_quiz_questions($quiz, $questions,
988  
-                                   $results=NULL, $shuffleorder=NULL) {
  994
+function quiz_navigation_javascript($link) {
  995
+    return "javascript:navigate($link);";
  996
+}
  997
+
  998
+function quiz_print_navigation_panel($questions, $questionsperpage, $navigation) {
  999
+    global $QUIZ_QTYPES;
  1000
+
  1001
+    $numberinglayout = array();
  1002
+    $nextqnumber = 1;
  1003
+    foreach ($questions as $question) {
  1004
+        if ($qnumberinc = $QUIZ_QTYPES[$question->qtype]
  1005
+                ->actual_number_of_questions($question)) {
  1006
+            $numberinglayout[] = $nextqnumber;
  1007
+            $nextqnumber += $qnumberinc;
  1008
+        }
  1009
+    }
  1010
+
  1011
+    if ($nextqnumber - $qnumberinc <= $questionsperpage) {
  1012
+        /// The total number of questions does not exceed the maximum
  1013
+        /// number of allowed questions per page so...
  1014
+        return 0;
  1015
+    }
  1016
+    /// else - Navigation menu will be printed!
  1017
+
  1018
+    ///////////////////////////////////////////////
  1019
+    /// Determine the layout of the navigation menu
  1020
+    ///////////////////////////////////////////////
  1021
+    if (1 == $questionsperpage) {
  1022
+        /// The simple case:
  1023
+        $pagelinkagelayout = $pagenavigationlayout = $numberinglayout;
  1024
+
  1025
+    } else {
  1026
+        /// More complicated:
  1027
+        $pagenavigationlayout = array();
  1028
+        $pagelinkagelayout = array($currentpagestart = 1);
  1029
+        foreach ($numberinglayout as $questionnumber) {
  1030
+            if ($questionnumber - $currentpagestart >= $questionsperpage) {
  1031
+                $pagenavigationlayout[] = $currentpagestart
  1032
+                        .'-'. ($questionnumber - 1);
  1033
+                if ($currentpagestart < $navigation
  1034
+                        && $navigation < $questionnumber) {
  1035
+                    // $navigation is out of sync so adjust for robustness
  1036
+                    $navigation = $currentpagestart;
  1037
+                }
  1038
+                $pagelinkagelayout[] = $currentpagestart = $questionnumber;
  1039
+            }
  1040
+        }
  1041
+        $pagenavigationlayout[] = $currentpagestart .'-'. ($nextqnumber - 1);
  1042
+        if ($currentpagestart < $navigation) {
  1043
+            // $firsquestion is out of sync so adjust it for robustness...
  1044
+            $navigation = $currentpagestart;
  1045
+        }
  1046
+    }
  1047
+
  1048
+    foreach ($pagelinkagelayout as $key => $link) {
  1049
+        if ($link < $navigation) {
  1050
+            $previouspagelink = $link;
  1051
+        } else if ($link == $navigation) {
  1052
+            $currentnavigationtitle = $pagenavigationlayout[$key];
  1053
+        } else {
  1054
+            $endpagelink = $link;
  1055
+            if (false == isset($nextpagelink)) {
  1056
+               $nextpagelink = $link; 
  1057
+            }
  1058
+        }
  1059
+    }
  1060
+
  1061
+    ///////////////////////////////////////////////
  1062
+    /// Print the navigation meny
  1063
+    ///////////////////////////////////////////////
  1064
+    print_simple_box_start('center', '*');
  1065
+    echo '<table><tr><td colspan="5" align="center"><table><tr>';
  1066
+    foreach ($pagelinkagelayout as $key => $link) {
  1067
+        echo '<td align="center">&nbsp;';
  1068
+        if ($link != $navigation) {
  1069
+            echo '<a href="' . quiz_navigation_javascript($link) . '">';
  1070
+        }
  1071
+        echo $pagenavigationlayout[$key];
  1072
+        if ($link != $navigation) {
  1073
+            echo '</a>';
  1074
+        }
  1075
+        echo '&nbsp;</td>';
  1076
+    }
  1077
+    echo '</tr></table></td></tr><tr><td width="20%" align="left">';
  1078
+    if (isset($previouspagelink)) {
  1079
+        echo '<a href="' . quiz_navigation_javascript('1') . '">|&lt;&lt;&lt;</a></td><td width="20%" align="center" cellpadding="2">';
  1080
+        echo '<a href="' . quiz_navigation_javascript($previouspagelink) . '">&lt;&lt;&lt;</a></td>';
  1081
+    } else {
  1082
+        echo '</td><td width="20%"></td>';
  1083
+    }
  1084
+    echo '<td width="20%" align="center"><b>';
  1085
+    echo $currentnavigationtitle;
  1086
+    echo '</b></td><td width="20%" align="center" cellpadding="2">';
  1087
+    if (isset($nextpagelink)) {
  1088
+        echo '<a href="';
  1089
+        echo quiz_navigation_javascript($nextpagelink);
  1090
+        echo '">&gt;&gt;&gt;</a></td><td width="20%" align="right"><a href="';
  1091
+        echo quiz_navigation_javascript($endpagelink);
  1092
+        echo '">&gt;&gt;&gt;|</a>';
  1093
+    } else {
  1094
+        echo '</td><td width="20%">';
  1095
+    }
  1096
+    echo '</td></tr></table>';
  1097
+    print_simple_box_end();
  1098
+
  1099
+    ////////////////////////////////////////////////
  1100
+    /// Return the potentially adjusted $navigation
  1101
+    ////////////////////////////////////////////////
  1102
+    return $navigation;
  1103
+}
  1104
+
  1105
+function quiz_print_quiz_questions($quiz, $questions, $results=NULL,
  1106
+                                   $shuffleorder=NULL, $navigation=0) {
989 1107
 // Prints a whole quiz on one page.
990 1108
 
  1109
+    if ($navigation < 0) {
  1110
+        $navigation = 0; // For robustness
  1111
+    }
  1112
+
991 1113
     global $QUIZ_QTYPES;
992 1114
 
993 1115
     /// Check arguments
@@ -1025,7 +1147,7 @@ function quiz_print_quiz_questions($quiz, $questions,
1025 1147
         ?>
1026 1148
         <script language="javascript" type="text/javascript">
1027 1149
         <!--
1028  
-            document.write("<form method=\"post\" action=\"attempt.php\" <?php print(addslashes($onsubmit));?>>\n");
  1150
+            document.write("<form name=\"responseform\" method=\"post\" action=\"attempt.php\" <?php print(addslashes($onsubmit));?>>\n");
1029 1151
         // -->
1030 1152
         </script>
1031 1153
         <noscript>
@@ -1033,12 +1155,19 @@ function quiz_print_quiz_questions($quiz, $questions,
1033 1155
         </noscript>
1034 1156
         <?php
1035 1157
     } else {
1036  
-    echo "<form method=\"post\" action=\"attempt.php\" $onsubmit>\n";
  1158
+        echo "<form name=\"responseform\" method=\"post\" action=\"attempt.php\" $onsubmit>\n";
1037 1159
     }
1038 1160
     // END EDIT
1039 1161
     echo "<input type=\"hidden\" name=\"q\" value=\"$quiz->id\" />\n";
1040 1162
 
1041  
-    // $count = 0;
  1163
+    if ($navigation && $quiz->questionsperpage) {
  1164
+        echo '<input type="hidden" id="navigation" name="navigation" value="0" />';
  1165
+        $navigation = quiz_print_navigation_panel($questions,
  1166
+                $quiz->questionsperpage, $navigation);
  1167
+    } else {
  1168
+        $navigation = 0;
  1169
+    }
  1170
+
1042 1171
     $nextquestionnumber = 1;
1043 1172
     $questionorder = array();
1044 1173
 
@@ -1055,18 +1184,31 @@ function quiz_print_quiz_questions($quiz, $questions,
1055 1184
 
1056 1185
         $questionorder[] = $question->id;
1057 1186
 
1058  
-        if ($results && isset($results->details[$question->id])) {
1059  
-            $details = $results->details[$question->id];
  1187
+        if (0 == $navigation
  1188
+                || $navigation <= $nextquestionnumber
  1189
+                && $nextquestionnumber - $navigation < $quiz->questionsperpage) {
  1190
+            if ($results && isset($results->details[$question->id])) {
  1191
+                $details = $results->details[$question->id];
  1192
+            } else {
  1193
+                $details = false;
  1194
+            }
  1195
+
  1196
+            echo "<br />";
  1197
+            print_simple_box_start("center", "90%");
  1198
+            $nextquestionnumber = $QUIZ_QTYPES[$question->qtype]->print_question
  1199
+                    ($nextquestionnumber, $quiz, $question, $readonly, $details);
  1200
+            print_simple_box_end();
1060 1201
         } else {
1061  
-            $details = false;
  1202
+            $nextquestionnumber += $QUIZ_QTYPES[$question->qtype]
  1203
+                    ->actual_number_of_questions($question);
1062 1204
         }
  1205
+    }
1063 1206
 
1064  
-        print_simple_box_start("center", "90%");
1065  
-        $nextquestionnumber = $QUIZ_QTYPES[$question->qtype]->print_question
1066  
-                ($nextquestionnumber, $quiz, $question, $readonly, $details);
1067  
-        print_simple_box_end();
1068  
-        echo "<br />";
  1207
+    if ($navigation) {
  1208
+        quiz_print_navigation_panel($questions, $quiz->questionsperpage,
  1209
+                                    $navigation);
1069 1210
     }
  1211
+    echo "<br />";
1070 1212
 
1071 1213
     if (empty($readonly)) {
1072 1214
         if (!empty($quiz->shufflequestions)) {  // Things have been mixed up, so pass the question order
@@ -1083,11 +1225,20 @@ function quiz_print_quiz_questions($quiz, $questions,
1083 1225
             echo "<center><strong>".get_string("noscript","quiz")."</strong></center>\n";
1084 1226
             echo "</noscript>\n";
1085 1227
         } else {
1086  
-        echo "<center>\n<input type=\"submit\" value=\"".get_string("savemyanswers", "quiz")."\" />\n</center>";
1087  
-    }
  1228
+            echo "<center>\n<input type=\"submit\" value=\"".get_string("savemyanswers", "quiz")."\" />\n</center>";
  1229
+        }
1088 1230
     }
1089 1231
     echo "</form>";
1090 1232
 
  1233
+    if ($navigation && $quiz->questionsperpage) {
  1234
+        echo '<script language="javascript" type="text/javascript">';
  1235
+        echo "function navigate(link) {
  1236
+                document.responseform.navigation.value=link;
  1237
+                document.responseform.submit();
  1238
+              }
  1239
+              </script>";
  1240
+    }
  1241
+
1091 1242
     return true;
1092 1243
 }
1093 1244
 
@@ -1695,7 +1846,8 @@ function quiz_calculate_best_attempt($quiz, $attempts) {
1695 1846
 }
1696 1847
 
1697 1848
 
1698  
-function quiz_save_attempt($quiz, $questions, $result, $attemptnum) {
  1849
+function quiz_save_attempt($quiz, $questions, $result,
  1850
+                           $attemptnum, $finished = true) {
1699 1851
 /// Given a quiz, a list of attempted questions and a total grade
1700 1852
 /// this function saves EVERYTHING so it can be reconstructed later
1701 1853
 /// if necessary.
@@ -1718,7 +1870,9 @@ function quiz_save_attempt($quiz, $questions, $result, $attemptnum) {
1718 1870
     // Now let's complete this record and save it
1719 1871
 
1720 1872
     $attempt->sumgrades = $result->sumgrades;
1721  
-    $attempt->timefinish = time();
  1873
+    if ($finished) {
  1874
+        $attempt->timefinish = time();
  1875
+    }
1722 1876
     $attempt->timemodified = time();
1723 1877
 
1724 1878
     if (!update_record("quiz_attempts", $attempt)) {
@@ -1741,7 +1895,8 @@ function quiz_save_attempt($quiz, $questions, $result, $attemptnum) {
1741 1895
                     ->convert_to_response_answer_field($question->response);
1742 1896
 
1743 1897
             $response->answer = $responseanswerfield;
1744  
-        } else {
  1898
+
  1899
+        } else if (!isset($response->answer)) {
1745 1900
             $response->answer = '';
1746 1901
         }
1747 1902
 
@@ -1770,7 +1925,7 @@ function quiz_extract_correctanswers($answers, $nameprefix) {
1770 1925
     return $correctanswers;
1771 1926
 }
1772 1927
 
1773  
-function quiz_grade_responses($quiz, $questions) {
  1928
+function quiz_grade_responses($quiz, $questions, $attemptid=0) {
1774 1929
 /// Given a list of questions (including ->response[] and ->maxgrade
1775 1930
 /// on each question) this function does all the hard work of calculating the
1776 1931
 /// score for each question, as well as a total grade for
@@ -1786,6 +1941,8 @@ function quiz_grade_responses($quiz, $questions) {
1786 1941
 /// []->grade            (Grade awarded on the specifik question)
1787 1942
 /// []->answers[]        (result answer records for the question response(s))
1788 1943
 /// []->correctanswers[] (answer records if question response(s) had been correct)
  1944
+///  - HOWEVER, ->answers[] and ->correctanswers[] are supplied only
  1945
+///             if there is a response on the question...
1789 1946
 /// The array ->answers[] is indexed like ->respoonse[] on its corresponding
1790 1947
 /// element in $questions. It is the case for ->correctanswers[] when
1791 1948
 /// there can be multiple responses per question but if there can be only one
@@ -1802,23 +1959,33 @@ function quiz_grade_responses($quiz, $questions) {
1802 1959
     $result->sumgrades = 0.0;
1803 1960
     foreach ($questions as $qid => $question) {
1804 1961
 
1805  
-        if (empty($question->qtype)) {
  1962
+        if (!isset($question->response) && $attemptid) {
  1963
+            /// No response on the question
  1964
+            /// This case is common if the quiz shows a limited
  1965
+            /// number of questions per page.
  1966
+            $response = get_record('quiz_responses', 'attempt',
  1967
+                                   $attemptid, 'question', $qid);
  1968
+            $resultdetails->grade = $response->grade;
  1969
+
  1970
+        } else if (empty($question->qtype)) {
1806 1971
             continue;
1807  
-        }
1808 1972
 
1809  
-        $resultdetails = $QUIZ_QTYPES[$question->qtype]->grade_response
  1973
+        } else {
  1974
+
  1975
+            $resultdetails = $QUIZ_QTYPES[$question->qtype]->grade_response
1810 1976
                                 ($question, quiz_qtype_nameprefix($question));
1811 1977
 
1812  
-        // Negative grades will not do:
1813  
-        if (((float)($resultdetails->grade)) <= 0.0) {
1814  
-            $resultdetails->grade = 0.0;
  1978
+            // Negative grades will not do:
  1979
+            if (((float)($resultdetails->grade)) <= 0.0) {
  1980
+                $resultdetails->grade = 0.0;
1815 1981
 
1816  
-        // Neither will extra credit:
1817  
-        } else if (((float)($resultdetails->grade)) >= 1.0) {
1818  
-            $resultdetails->grade = $question->maxgrade;
  1982
+            // Neither will extra credit:
  1983
+            } else if (((float)($resultdetails->grade)) >= 1.0) {
  1984
+                $resultdetails->grade = $question->maxgrade;
1819 1985
             
1820  
-        } else {
1821  
-            $resultdetails->grade *= $question->maxgrade;
  1986
+            } else {
  1987
+                $resultdetails->grade *= $question->maxgrade;
  1988
+            }
1822 1989
         }
1823 1990
 
1824 1991
         // if time limit is enabled and exceeded, return zero grades
19  mod/quiz/mod.html
@@ -63,6 +63,9 @@
63 63
     if (!isset($form->review)) {
64 64
         $form->review = $CFG->quiz_allowreview;
65 65
     }
  66
+    if (!isset($form->questionsperpage)) {
  67
+        $form->questionsperpage = 0;
  68
+    }
66 69
     if (!isset($form->shufflequestions)) {
67 70
         $form->shufflequestions = $CFG->quiz_shufflequestions;
68 71
     }
@@ -194,6 +197,22 @@
194 197
     </tr>
195 198
 <?php } ?>
196 199
 
  200
+<tr valign="top">
  201
+    <td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
  202
+    <td>
  203
+    <?php
  204
+        $perpage= array();
  205
+        for ($i=0; $i<=50; ++$i) {
  206
+            $perpage[$i] = $i;
  207
+        }
  208
+        $perpage[0] = get_string('allinone', 'quiz');
  209
+
  210
+        choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
  211
+        helpbutton('questionsperpage', get_string('questionsperpage'), 'quiz');
  212
+     ?>
  213
+    </td>
  214
+</tr>
  215
+
197 216
 <?php if (!$CFG->quiz_fix_shufflequestions) { ?>
198 217
     <tr valign="top">
199 218
         <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
9  mod/quiz/questiontypes/description/questiontype.php
@@ -40,6 +40,15 @@ function print_question($currentnumber, $quiz, $question,
40 40
         return $currentnumber;        
41 41
     }
42 42
 
  43
+    function actual_number_of_questions($question) {
  44
+        /// Used for the feature number-of-questions-per-page
  45
+        /// to determine the actual number of questions wrapped
  46
+        /// by this question.
  47
+        /// The question type description is not even a question
  48
+        /// in itself so it will return ZERO!
  49
+        return 0;
  50
+    }
  51
+
43 52
     function grade_response($question, $nameprefix) {
44 53
         $result->grade = 0.0;
45 54
         $result->answers = array();
2  mod/quiz/version.php
@@ -5,7 +5,7 @@
5 5
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
6 6
 ////////////////////////////////////////////////////////////////////////////////
7 7
 
8  
-$module->version  = 2005010201;   // The (date) version of this module
  8
+$module->version  = 2005010300;   // The (date) version of this module
9 9
 $module->requires = 2005010100;   // Requires this Moodle version
10 10
 $module->cron     = 0;            // How often should cron check this module (seconds)?
11 11
 

0 notes on commit d70ccc4

Please sign in to comment.
Something went wrong with that request. Please try again.