From: moodler Date: Thu, 10 Apr 2003 17:55:57 +0000 (+0000) Subject: New "create multiple questions" wizard. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c6eed097307b1218cf08e465471d9ed11e6b9cde;p=moodle.git New "create multiple questions" wizard. Improvements to the importing routine for AON --- diff --git a/lang/en/help/quiz/createmultiple.html b/lang/en/help/quiz/createmultiple.html new file mode 100644 index 0000000000..ead4c555f9 --- /dev/null +++ b/lang/en/help/quiz/createmultiple.html @@ -0,0 +1,10 @@ +

Create multiple questions

+ +

This page allows you to create multiple questions at once.

+ +

Currently it will only allow you to create a number of + Random Questions and (optionally) add them to the current + quiz.

+ +

Eventually this page will evolve into a larger wizard that + will have more options.

diff --git a/lang/en/quiz.php b/lang/en/quiz.php index 0c3b785997..806d9e8019 100644 --- a/lang/en/quiz.php +++ b/lang/en/quiz.php @@ -6,6 +6,7 @@ $string['modulenameplural'] = "Quizzes"; #------------------------------------------------------------ $string['addquestions'] = "Add questions"; +$string['addquestionstoquiz'] = "Add questions to current quiz"; $string['addselectedtoquiz'] = "Add selected to quiz"; $string['allowreview'] = "Allow review"; $string['alwaysavailable'] = "Always available"; @@ -35,10 +36,12 @@ $string['choice'] = "Choice"; $string['choices'] = "Available choices"; $string['correctanswer'] = "Correct answer"; $string['correctanswers'] = "Correct answers"; +$string['createmultiple'] = "Create multiple questions"; $string['createnewquestion'] = "Create new question"; $string['custom'] = "Custom format"; $string['daysavailable'] = "Days available"; $string['default'] = "Default"; +$string['defaultgrade'] = "Default question grade"; $string['defaultinfo'] = "The default category for questions."; $string['deletequestioncheck'] = "Are you absolutely sure you want to delete '\$a'?"; $string['editcategories'] = "Edit categories"; @@ -96,6 +99,7 @@ $string['quizclosed'] = "This quiz closed on \$a"; $string['quizopen'] = "Open the quiz"; $string['quiznotavailable'] = "The quiz will not be available until: \$a"; $string['random'] = "Random Question"; +$string['randomcreate'] = "Create Random Questions"; $string['randomsamatch'] = "Random Short-Answer Matching"; $string['randomsamatchcreate'] = "Create Random Short-Answer Matching questions"; $string['randomsamatchintro'] = "For each of the following questions, select the matching answer from the menu."; diff --git a/mod/quiz/format/aon.php b/mod/quiz/format/aon.php index 7e2986e378..e07fcadd97 100644 --- a/mod/quiz/format/aon.php +++ b/mod/quiz/format/aon.php @@ -118,6 +118,8 @@ class quiz_file_format extends quiz_default_format { global $db, $CFG; + print_heading(count($questionids)." ".get_string("questions", "quiz")); + $questionids = implode(',', $questionids); if (!$shortanswers = get_records_select("quiz_questions", @@ -135,8 +137,9 @@ class quiz_file_format extends quiz_default_format { $strmatch = "$category->name - ".get_string("match", "quiz"); $shortanswerids = swapshuffle($shortanswerids); - $count = count($shortanswerids); + $count = $shortanswercount = count($shortanswerids); $i = 1; + $matchcount = 0; $question->category = $category->id; $question->qtype = MATCH; @@ -144,6 +147,7 @@ class quiz_file_format extends quiz_default_format { $question->image = ""; while ($count > 4) { + $matchcount++; $question->name = "$strmatch $i"; $question->subquestions = array(); $question->subanswers = array(); @@ -186,9 +190,9 @@ class quiz_file_format extends quiz_default_format { /// Delete the old short-answer questions - execute_sql("DELETE FROM {$CFG->prefix}quiz_questions WHERE id IN ($extractids)"); - execute_sql("DELETE FROM {$CFG->prefix}quiz_shortanswer WHERE question IN ($extractids)"); - execute_sql("DELETE FROM {$CFG->prefix}quiz_answers WHERE question IN ($extractids)"); + execute_sql("DELETE FROM {$CFG->prefix}quiz_questions WHERE id IN ($extractids)", false); + execute_sql("DELETE FROM {$CFG->prefix}quiz_shortanswer WHERE question IN ($extractids)", false); + execute_sql("DELETE FROM {$CFG->prefix}quiz_answers WHERE question IN ($extractids)", false); } @@ -199,7 +203,15 @@ class quiz_file_format extends quiz_default_format { delete_records("quiz_answers", "question", $shortanswerid); } } - + $info = "$shortanswercount ".get_string("shortanswer", "quiz"). + " => $matchcount ".get_string("match", "quiz"); + + print_heading($info); + + $options['category'] = $category->id; + echo "
"; + print_single_button("multiple.php", $options, get_string("randomcreate", "quiz")); + echo "
"; return true; } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 641c19e178..3dfe6ff944 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -1044,6 +1044,7 @@ function quiz_print_cat_question_list($categoryid) { $stredit = get_string("edit"); $straddselectedtoquiz = get_string("addselectedtoquiz", "quiz"); $strtype = get_string("type", "quiz"); + $strcreatemultiple = get_string("createmultiple", "quiz"); if (!$categoryid) { echo "

"; @@ -1075,6 +1076,12 @@ function quiz_print_cat_question_list($categoryid) { helpbutton("import", $strimportquestions, "quiz"); echo ""; + echo "

"; + echo "id\">"; + echo ""; + helpbutton("createmultiple", $strcreatemultiple, "quiz"); + echo "
"; + echo ""; echo ""; diff --git a/mod/quiz/multiple.php b/mod/quiz/multiple.php new file mode 100644 index 0000000000..4650aac607 --- /dev/null +++ b/mod/quiz/multiple.php @@ -0,0 +1,160 @@ +modform)) { + error("You have used this page incorrectly!"); + } else { + $modform = $SESSION->modform; + } + + if (! $category = get_record("quiz_categories", "id", $category)) { + error("Course ID is incorrect"); + } + + if (! $course = get_record("course", "id", $category->course)) { + error("Course ID is incorrect"); + } + + require_login($course->id); + + if (!isteacher($course->id)) { + error("Only teachers can use this page!"); + } + + + +/// If data submitted, then process and store. + + if ($form = data_submitted()) { + if ($form->randomcreate > 0) { + $existing = count_records("quiz_questions", "qtype", RANDOM, "category", $category->id); + $randomcreate = $form->randomcreate - $existing; + + if ($randomcreate > 0) { + $newquestionids = array(); + + $question->qtype = RANDOM; + $question->category = $category->id; + $question->name = get_string("random", "quiz"); + $question->questiontext = "---"; + $question->image = ""; + $question->defaultgrade = $form->randomgrade; + for ($i=0; $i<$randomcreate; $i++) { + if (!$newquestionids[] = insert_record("quiz_questions", $question)) { + 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; + } + + $newquestionids = array_merge($questionids, $newquestionids); + $modform->questions = implode(",", $newquestionids); + $SESSION->modform = $modform; + } + } + } + redirect("edit.php"); + } + + +/// Otherwise print the form + +/// Print headings + + $strquestions = get_string("questions", "quiz"); + $strpublish = get_string("publish", "quiz"); + $strdelete = get_string("delete"); + $straction = get_string("action"); + $stradd = get_string("add"); + $strcancel = get_string("cancel"); + $strsavechanges = get_string("savechanges"); + $strbacktoquiz = get_string("backtoquiz", "quiz"); + + $streditingquiz = get_string("editingquiz", "quiz"); + $strcreatemultiple = get_string("createmultiple", "quiz"); + + print_header("$course->shortname: $strcreatemultiple", "$course->shortname: $strcreatemultiple", + "wwwroot/course/view.php?id=$course->id\">$course->shortname + -> $streditingquiz -> $strcreatemultiple"); + + + print_heading_with_help($strcreatemultiple, "createmultiple", "quiz"); + + if (!$categories = quiz_get_category_menu($course->id, true)) { + error("No categories!"); + } + + for ($i=1;$i<=100; $i++) { + $randomcount[$i] = $i; + } + for ($i=1;$i<=10; $i++) { + $gradecount[$i] = $i; + } + $options = array(); + $options[0] = get_string("no"); + $options[1] = get_string("yes"); + + print_simple_box_start("center", "", "$THEME->cellheading"); + echo "
"; + echo ""; + echo ""; + + echo ""; + + echo ""; + + echo ""; + + echo ""; + echo "
"; + print_string("category", "quiz"); + echo ":"; + choose_from_menu($categories, "category", "$category->id", ""); + echo "
"; + print_string("randomcreate", "quiz"); + echo ":"; + choose_from_menu($randomcount, "randomcreate", "10", ""); + echo "
"; + print_string("defaultgrade", "quiz"); + echo ":"; + choose_from_menu($gradecount, "randomgrade", "1", ""); + echo "
"; + print_string("addquestionstoquiz", "quiz"); + echo ":"; + choose_from_menu($options, "addquestionstoquiz", "1", ""); + echo "
 "; + echo " id\">"; + echo " "; + echo "
"; + echo "
"; + print_simple_box_end(); + + print_footer(); + +?> diff --git a/mod/quiz/question.php b/mod/quiz/question.php index 6ab1261384..92846eef83 100644 --- a/mod/quiz/question.php +++ b/mod/quiz/question.php @@ -5,7 +5,7 @@ require_once("lib.php"); require_once("../../files/mimetypes.php"); - optional_variable($id); + optional_variable($id); // question id optional_variable($qtype); optional_variable($category);