<p align="center"><b>Random Question</b></p>
-<p>Random questions are a special question type.</p>
-
-<p>When you put a Random Question into a quiz, then a question
- will be chosen randomly from the whole category, on each attempt.</p>
-
-<p>The maximum grade for the question will always be when you have chosen
- as the grade for the Random Question.</p>
-
-<p>If you make a quiz with, say, 10 random questions, then each student
- may get a completely different set of 10 questions each time they
- attempt the quiz.</p>
-
-<p>Note that you can mix random and non-random questions if you want to
- ensure that particular questions are always included.</p>
-
-
+<p>When you put a random question into a quiz, then a question
+ will be chosen randomly from the category, on each attempt. Thus different students
+ are likely to get a different selection of questions and furthermore for quizzes that allow
+ reattempts that are not based on previous attempts, the new attempt are likely to contain a
+ new selection of questions. </p>
+
+<p>If you include several random questions then different questions will be chosen for each of
+ them. If you mix random and non-random questions then the random questions
+ will be chosen so that they do not duplicate one of the non-random questions.
+ </p>
+
+<p>The grade for the randomly chosen question will be rescaled so that the maximum grade is
+ what you have chosen as the grade for the random question.</p>
$string['addingquestions'] = 'This side of the page is where you manage your database of questions. Questions are stored in categories to help you keep them organised, and can be used by any quiz in your course or even other courses if you choose to \'publish\' them. <br /><br />After you select or create a question category you will be able to create or edit questions. You can select any of these questions to add to your quiz over on the other side of this page.';
$string['addquestions'] = 'Add questions';
$string['addquestionstoquiz'] = 'Add questions to current quiz';
+$string['addrandom1'] = ' Add ';
+$string['addrandom2'] = 'random questions ';
$string['addselectedtoquiz'] = 'Add selected to quiz';
$string['aiken'] = 'Aiken format';
$string['allowreview'] = 'Allow review';
$string['countdowntenminutes'] = 'The quiz will be closing in ten minutes.';
$string['coursetestmanager'] = 'Course Test Manager format';
$string['createfirst'] = 'You must create some short-answer questions first. ';
-$string['createmultiple'] = 'Create multiple questions';
+$string['createmultiple'] = 'Add several random questions to quiz';
$string['createnewquestion'] = 'Create new question';
$string['custom'] = 'Custom format';
$string['datasetdefinitions'] = 'Reusable dataset definitions for category $a';
CALCULATED => get_string("calculated", "quiz"),
MATCH => get_string("match", "quiz"),
DESCRIPTION => get_string("description", "quiz"),
- RANDOM => get_string("random", "quiz"),
RANDOMSAMATCH => get_string("randomsamatch", "quiz"),
MULTIANSWER => get_string("multianswer", "quiz")
);
if ($editlink) {
echo "<a href=\"question.php?id=$question->id\" title=\""
- .$QUIZ_QUESTION_TYPE[$question->qtype]."\">";
+ .$QUIZ_QTYPES[$question->qtype]->name()."\">";
}
echo '<img border="0" height="16" width="16" src="questiontypes/';
echo $QUIZ_QTYPES[$question->qtype]->name().'/icon.gif" alt="';
echo '<td width="10" valign="top" align="right">';
helpbutton("questiontypes", $strcreatenewquestion, "quiz");
echo '</td></tr>';
-
- echo '<tr><td colspan="3" align="right">';
- echo '<form method="get" action="import.php">';
- echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
- echo "<input type=\"submit\" value=\"$strimportquestions\" />";
- helpbutton("import", $strimportquestions, "quiz");
- echo '</form>';
- echo '</td></tr>';
}
else {
echo '<tr><td>';
echo '</td></tr>';
}
- echo '<tr><td colspan="3" align="right">';
- echo '<form method="get" action="export.php">';
- echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
- echo "<input type=\"submit\" value=\"$strexportquestions\" />";
- helpbutton("export", $strexportquestions, "quiz");
- echo '</form>';
- echo '</td></tr>';
-
+ echo '<tr><td colspan="3" align="right"><font size="2">';
if (isteacheredit($category->course)) {
- echo '<tr><td colspan="3" align="right">';
- echo '<form method="get" action="multiple.php">';
- echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
- echo "<input type=\"submit\" value=\"$strcreatemultiple\" />";
- helpbutton("createmultiple", $strcreatemultiple, "quiz");
- echo '</form>';
- echo '</td></tr>';
+ echo '<a href="import.php?category='.$category->id.'">'.$strimportquestions.'</a>';
+ helpbutton("import", $strimportquestions, "quiz");
+ echo ' | ';
}
+ echo '<a href="export.php?category='.$category->id.'">'.$strexportquestions.'</a>';
+ helpbutton("export", $strexportquestions, "quiz");
+ echo '</font></td></tr>';
echo '</table>';
}
echo "</tr>\n";
foreach ($questions as $question) {
+ if ($question->qtype == RANDOM) {
+ continue;
+ }
echo "<tr bgcolor=\"$THEME->cellcontent\">\n";
if ($quizselected) {
echo "<td align=\"center\">";
}
echo "</table>\n";
echo "</form>\n";
+ if ($quizselected and isteacheredit($category->course)) {
+ for ($i=1;$i<=10; $i++) {
+ $randomcount[$i] = $i;
+ }
+ echo '<form method="post" action="multiple.php">';
+ print_string('addrandom1', 'quiz');
+ choose_from_menu($randomcount, 'randomcreate', '10', '');
+ print_string('addrandom2', 'quiz');
+ // Don't offer the option to change the grade
+ //choose_from_menu($randomcount, 'randomgrade', '1', '');
+ echo '<input type="hidden" name="randomgrade", value="1" />';
+ echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
+ echo ' <input type="submit" name="save" value="'. get_string('add') .'" />';
+ helpbutton('random', get_string('random', 'quiz'), 'quiz');
+ echo '</form>';
+ }
}
if ($form = data_submitted()) {
if ($form->randomcreate > 0) {
- $existing = count_records('quiz_questions', 'qtype', RANDOM, 'category', $category->id);
- $randomcreate = $form->randomcreate - $existing;
+ $newquestionids = array(); // this will hold the ids of the random questions
+
+ // find existing random questions in this category
+ $random = RANDOM;
+ if ($existingquestions = get_records_select('quiz_questions', "qtype = '$random' AND category = '$category->id'")) {
+ // now remove the ones that are already used in this quiz, if any
+ if ($questionids = explode(',', $modform->questions)) {
+ foreach ($questionids as $questionid) {
+ foreach ($existingquestions as $key => $existingquestion) {
+ if ($existingquestion->id == $questionid) {
+ unset($existingquestions[$key]);
+ break;
+ }
+ }
+ }
+ }
+ // now take as many of these as needed
+ $i = 0;
+ while (($existingquestion = array_pop($existingquestions)) and ($i < $form->randomcreate)) {
+ $newquestionids[] = $existingquestion->id;
+ $i++;
+ }
+ $randomcreate = $form->randomcreate - $i; // the number of additional random questions needed.
+ } else {
+ $randomcreate = $form->randomcreate;
+ }
if ($randomcreate > 0) {
- $newquestionids = array();
$question->qtype = RANDOM;
$question->category = $category->id;
error('Could not insert new random question!');
}
}
+ }
- // Add them to the quiz if necessary
- if (!empty($form->addquestionstoquiz)) {
- if (!empty($modform->questions)) {
- $questionids = explode(',', $modform->questions);
- foreach ($questionids as $questionid) {
- foreach ($newquestionids as $key => $newquestionid) {
- if ($newquestionid == $questionid) {
- unset($newquestionids[$key]);
- break;
- }
- }
- }
- } else {
- $questionids = array();
- }
-
- foreach ($newquestionids as $newquestionid) {
- $modform->grades[$newquestionid] = $form->randomgrade;
- $modform->sumgrades += $form->randomgrade;
- }
+ // Add them to the quiz
+ if (!empty($modform->questions)) {
+ $questionids = explode(',', $modform->questions);
+ } else {
+ $questionids = array();
+ }
- $newquestionids = array_merge($questionids, $newquestionids);
- $modform->questions = implode(',', $newquestionids);
- $SESSION->modform = $modform;
- }
+ foreach ($newquestionids as $newquestionid) {
+ $modform->grades[$newquestionid] = $form->randomgrade;
+ $modform->sumgrades += $form->randomgrade;
}
+
+ $newquestionids = array_merge($questionids, $newquestionids);
+ $modform->questions = implode(',', $newquestionids);
+ $SESSION->modform = $modform;
}
redirect('edit.php');
}
choose_from_menu($gradecount, 'randomgrade', '1', '');
echo '</tr>';
- echo '<tr><td align="right">';
- print_string('addquestionstoquiz', 'quiz');
- echo ':</td><td>';
- choose_from_menu($options, 'addquestionstoquiz', '1', '');
- echo '</tr>';
-
echo '<tr><td> </td><td>';
echo ' <input type="hidden" name="category" value="'. $category->id .'" />';
- echo ' <input type="submit" name="save" value="'. $strcreatemultiple .'" />';
+ echo ' <input type="submit" name="save" value="'. get_string('add') .'" />';
echo '</td></tr>';
echo '</table>';
echo '</form>';
print_footer();
-?>
\ No newline at end of file
+?>