]> git.mjollnir.org Git - moodle.git/commitdiff
New "create multiple questions" wizard.
authormoodler <moodler>
Thu, 10 Apr 2003 17:55:57 +0000 (17:55 +0000)
committermoodler <moodler>
Thu, 10 Apr 2003 17:55:57 +0000 (17:55 +0000)
Improvements to the importing routine for AON

lang/en/help/quiz/createmultiple.html [new file with mode: 0644]
lang/en/quiz.php
mod/quiz/format/aon.php
mod/quiz/lib.php
mod/quiz/multiple.php [new file with mode: 0644]
mod/quiz/question.php

diff --git a/lang/en/help/quiz/createmultiple.html b/lang/en/help/quiz/createmultiple.html
new file mode 100644 (file)
index 0000000..ead4c55
--- /dev/null
@@ -0,0 +1,10 @@
+<P ALIGN=CENTER><B>Create multiple questions</B></P>
+
+<P>This page allows you to create multiple questions at once.</P>
+
+<P>Currently it will only allow you to create a number of 
+   Random Questions and (optionally) add them to the current 
+   quiz.</P>
+
+<P>Eventually this page will evolve into a larger wizard that 
+   will have more options.</P>
index 0c3b785997533107961092bf8708c9d46716247e..806d9e8019f489e30e403ef8bbf29155d8581c71 100644 (file)
@@ -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.";
index 7e2986e378b5c36d0360378b5cdbcb7b72383b6a..e07fcadd971812bb6699dbefea033639840ac6dd 100644 (file)
@@ -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 "<CENTER>";
+        print_single_button("multiple.php", $options, get_string("randomcreate", "quiz"));
+        echo "</CENTER>";
 
         return true;
     }
index 641c19e178b8c862626a71e85283f48b8674a189..3dfe6ff9443226484ff48e1480fea81aef112b64 100644 (file)
@@ -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 "<P align=center>";
@@ -1075,6 +1076,12 @@ function quiz_print_cat_question_list($categoryid) {
     helpbutton("import", $strimportquestions, "quiz");
     echo "</FORM>";
 
+    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 "</TR></TABLE>";
 
     echo "</CENTER>";
diff --git a/mod/quiz/multiple.php b/mod/quiz/multiple.php
new file mode 100644 (file)
index 0000000..4650aac
--- /dev/null
@@ -0,0 +1,160 @@
+<?PHP // $Id$
+      // A quick way to add lots of questions to a category (and a quiz)
+
+       require_once("../../config.php");
+       require_once("lib.php");
+
+    require_variable($category);
+
+    // This script can only be called while editing a quiz
+
+    if (!isset($SESSION->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",
+                 "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> 
+                   -> <A HREF=\"edit.php\">$streditingquiz</A> -> $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 "<FORM METHOD=\"POST\" ACTION=multiple.php>";
+    echo "<TABLE cellpadding=5>";
+    echo "<TR><TD align=right>";
+    print_string("category", "quiz");
+    echo ":</TD><TD>";
+    choose_from_menu($categories, "category", "$category->id", "");
+    echo "</TR>";
+
+    echo "<TR><TD align=right>";
+    print_string("randomcreate", "quiz");
+    echo ":</TD><TD>";
+    choose_from_menu($randomcount, "randomcreate", "10", "");
+    echo "</TR>";
+
+    echo "<TR><TD align=right>";
+    print_string("defaultgrade", "quiz");
+    echo ":</TD><TD>";
+    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>&nbsp;</TD><TD>";
+    echo " <INPUT TYPE=hidden NAME=category VALUE=\"$category->id\">";
+    echo " <INPUT TYPE=submit NAME=save VALUE=\"$strcreatemultiple\">";
+    echo "</TD></TR>";
+    echo "</TABLE>";
+    echo "</FORM>";
+    print_simple_box_end();
+
+    print_footer();
+
+?>
index 6ab1261384ea069800ef6702b2a2b6e5a4bc5220..92846eef83b103ace6478067e2498ee579e99b7d 100644 (file)
@@ -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);