From: gustav_delius Date: Wed, 29 Dec 2004 22:57:35 +0000 (+0000) Subject: Changed user interface for adding multiple random questions, see http://moodle.org... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0dc4810a9a9326ef7d6da833f6a27fe42f19671b;p=moodle.git Changed user interface for adding multiple random questions, see http://moodle.org/mod/forum/discuss.php?d=16531#78785 --- diff --git a/lang/en/help/quiz/random.html b/lang/en/help/quiz/random.html index 189bfe2979..ea5ae4ab00 100644 --- a/lang/en/help/quiz/random.html +++ b/lang/en/help/quiz/random.html @@ -1,18 +1,15 @@

Random Question

-

Random questions are a special question type.

- -

When you put a Random Question into a quiz, then a question - will be chosen randomly from the whole category, on each attempt.

- -

The maximum grade for the question will always be when you have chosen - as the grade for the Random Question.

- -

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.

- -

Note that you can mix random and non-random questions if you want to - ensure that particular questions are always included.

- - +

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.

+ +

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. +

+ +

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.

diff --git a/lang/en/quiz.php b/lang/en/quiz.php index 76f5631640..1dfc09fdfc 100644 --- a/lang/en/quiz.php +++ b/lang/en/quiz.php @@ -6,6 +6,8 @@ $string['acceptederror'] = 'Accepted error'; $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.

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'; @@ -59,7 +61,7 @@ $string['countdownfinished'] = 'The quiz is closing, you should submit your answ $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'; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index cdba95e9a3..ad71e87921 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -31,7 +31,6 @@ $QUIZ_QUESTION_TYPE = array ( MULTICHOICE => get_string("multichoice", "quiz") 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") ); @@ -936,7 +935,7 @@ function quiz_print_question_icon($question, $editlink=true) { if ($editlink) { echo "id\" title=\"" - .$QUIZ_QUESTION_TYPE[$question->qtype]."\">"; + .$QUIZ_QTYPES[$question->qtype]->name()."\">"; } echo '';
@@ -1385,14 +1384,6 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) {
         echo '<td width='; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); echo ''; - - echo ''; - echo '
'; - echo "id\" />"; - echo ""; - helpbutton("import", $strimportquestions, "quiz"); - echo '
'; - echo ''; } else { echo ''; @@ -1400,23 +1391,15 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) { echo ''; } - echo ''; - echo '
'; - echo "id\" />"; - echo ""; - helpbutton("export", $strexportquestions, "quiz"); - echo '
'; - echo ''; - + echo ''; if (isteacheredit($category->course)) { - echo ''; - echo '
'; - echo "id\" />"; - echo ""; - helpbutton("createmultiple", $strcreatemultiple, "quiz"); - echo '
'; - echo ''; + echo '
'.$strimportquestions.''; + helpbutton("import", $strimportquestions, "quiz"); + echo ' | '; } + echo ''.$strexportquestions.''; + helpbutton("export", $strexportquestions, "quiz"); + echo ''; echo ''; @@ -1443,6 +1426,9 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) { } echo "\n"; foreach ($questions as $question) { + if ($question->qtype == RANDOM) { + continue; + } echo "cellcontent\">\n"; if ($quizselected) { echo ""; @@ -1474,6 +1460,22 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) { } echo "\n"; echo "\n"; + if ($quizselected and isteacheredit($category->course)) { + for ($i=1;$i<=10; $i++) { + $randomcount[$i] = $i; + } + echo '
'; + 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 ''; + echo "id\" />"; + echo ' '; + helpbutton('random', get_string('random', 'quiz'), 'quiz'); + echo '
'; + } } diff --git a/mod/quiz/multiple.php b/mod/quiz/multiple.php index 862d1518b3..3c715c6ad3 100644 --- a/mod/quiz/multiple.php +++ b/mod/quiz/multiple.php @@ -34,11 +34,34 @@ 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; @@ -52,33 +75,23 @@ 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'); } @@ -143,15 +156,9 @@ choose_from_menu($gradecount, 'randomgrade', '1', ''); echo ''; - echo ''; - print_string('addquestionstoquiz', 'quiz'); - echo ':'; - choose_from_menu($options, 'addquestionstoquiz', '1', ''); - echo ''; - echo ' '; echo ' '; - echo ' '; + echo ' '; echo ''; echo ''; echo ''; @@ -159,4 +166,4 @@ print_footer(); -?> \ No newline at end of file +?>