]> git.mjollnir.org Git - moodle.git/commitdiff
New question type called "Description". All it does is print some
authormoodler <moodler>
Sun, 6 Jul 2003 04:00:05 +0000 (04:00 +0000)
committermoodler <moodler>
Sun, 6 Jul 2003 04:00:05 +0000 (04:00 +0000)
text and/or an image, without requiring an answer.  Can be used
to provide text for a following group of questions, or to insert
a joke in the quiz etc ...

This code is based on code sent in by Ursula Raab.  Thanks!

See: http://moodle.org/mod/forum/discuss.php?d=508

lang/en/help/quiz/description.html [new file with mode: 0644]
lang/en/moodle.php
lang/en/quiz.php
mod/quiz/description.html [new file with mode: 0644]
mod/quiz/edit.php
mod/quiz/lib.php
mod/quiz/pix/de.gif [new file with mode: 0755]
mod/quiz/question.php

diff --git a/lang/en/help/quiz/description.html b/lang/en/help/quiz/description.html
new file mode 100644 (file)
index 0000000..f15c672
--- /dev/null
@@ -0,0 +1,7 @@
+<P ALIGN=CENTER><B>Description</B></P>\r
+\r
+<P>This type of question is not really a question.  </p>\r
+\r
+<p>All it does is print some text without requiring any answers.</p>\r
+\r
+<P>It can be used to print a descriptive text to be used by a following group of questions.</p>\r
index a346b998838284ab59384fecb94483ec3369479d..3aa62257fd19b70c4acf23ceccc7acf583996a12 100644 (file)
@@ -9,6 +9,7 @@ $string['activity'] = "Activity";
 $string['activityiscurrentlyhidden'] = "Sorry, this activity is currently hidden";
 $string['activitymodule'] = "Activity module";
 $string['activityreport'] = "Activity report";
+$string['activitysince'] = "Activity since \$a";
 $string['add'] = "Add";
 $string['added'] = "Added \$a";
 $string['addinganew'] = "Adding a new \$a";
index d8d10730094730bc64b96ad35d3291f1f09f0849..5b017f882eb37d2caaedfc60b927bbd08fb6f582 100644 (file)
@@ -46,7 +46,9 @@ $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['description'] = "Description";
 $string['editcategories'] = "Edit categories";
+$string['editingdescription'] = "Editing a Description";
 $string['editingmatch'] = "Editing a Matching Question";
 $string['editingmultichoice'] = "Editing a Multiple Choice question";
 $string['editingquiz'] = "Editing quiz";
diff --git a/mod/quiz/description.html b/mod/quiz/description.html
new file mode 100644 (file)
index 0000000..7aaaf9a
--- /dev/null
@@ -0,0 +1,57 @@
+<FORM name="theform" method="post" <?=$onsubmit ?> action="question.php">\r
+<CENTER>\r
+<TABLE cellpadding=5>\r
+<TR valign=top>\r
+    <TD align=right><P><B><? print_string("category", "quiz") ?>:</B></P></TD>\r
+    <TD>\r
+    <?  choose_from_menu($categories, "category", "$question->category", ""); ?>\r
+    </TD>\r
+</TR>\r
+<TR valign=top>\r
+    <TD align=right><P><B><? print_string("questionname", "quiz") ?>:</B></P></TD>\r
+    <TD>\r
+        <INPUT type="text" name="name" size=40 value="<? p($question->name) ?>">\r
+        <? if (isset($err["name"])) formerr($err["name"]); ?>\r
+    </TD>\r
+</TR>\r
+<TR valign=top>\r
+    <TD align=right><P><B><? print_string("question", "quiz") ?>:</B></P></TD>\r
+    <TD>\r
+        <? if (isset($err["questiontext"])) {\r
+               formerr($err["questiontext"]); \r
+               echo "<BR \>";\r
+           }\r
+           print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);\r
+           if ($usehtmleditor) {\r
+               helpbutton("richtext", get_string("helprichtext"), "moodle");\r
+           } else {\r
+               helpbutton("text", get_string("helptext"), "moodle");\r
+           }\r
+        ?>\r
+    </TD>\r
+</TR>\r
+<TR valign=top>\r
+    <TD align=right><P><B><? print_string("imagedisplay", "quiz") ?>:</B></P></TD>\r
+    <TD>\r
+    <?  if (empty($images)) {\r
+            print_string("noimagesyet");\r
+        } else {\r
+            choose_from_menu($images, "image", "$question->image", get_string("none"),"","");\r
+        }\r
+    ?>\r
+    </TD>\r
+</TR>\r
+</TABLE>\r
+\r
+<INPUT type="hidden" name=id value="<? p($question->id) ?>">\r
+<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">\r
+<INPUT type="hidden" name=defaultgrade value="0">\r
+<INPUT type="submit" value="<? print_string("savechanges") ?>">\r
+\r
+</CENTER>\r
+</FORM>\r
+<? \r
+   if ($usehtmleditor) { \r
+       print_richedit_javascript("theform", "questiontext", "no");\r
+   }\r
+?>\r
index c2ebdd927032747e4e8f4d0397b4205d3f9d9fb6..8d4dd4427019e5477d482354c245b65f6283a88b 100644 (file)
                 $questions[] = $key;
 
                 $questionrecord = get_record("quiz_questions", "id", $key);
+
                 if (!empty($questionrecord->defaultgrade)) {
                     $modform->grades[$key] = $questionrecord->defaultgrade; 
+                } else if ($questionrecord->qtype == DESCRIPTION){
+                    $modform->grades[$key] = 0; 
                 } else {
                     $modform->grades[$key] = 1; 
                 }
index f5e7c652772868d6e5802c92f58e90779b3c835b..585b2b0cb0b5cd7f51ec3085623c2d17e81b7af7 100644 (file)
@@ -19,13 +19,15 @@ define("MULTICHOICE",   "3");
 define("RANDOM",        "4");
 define("MATCH",         "5");
 define("RANDOMSAMATCH", "6");
+define("DESCRIPTION",   "7");
 
 $QUIZ_QUESTION_TYPE = array ( MULTICHOICE   => get_string("multichoice", "quiz"),
                               TRUEFALSE     => get_string("truefalse", "quiz"),
                               SHORTANSWER   => get_string("shortanswer", "quiz"),
                               MATCH         => get_string("match", "quiz"),
                               RANDOM        => get_string("random", "quiz"),
-                              RANDOMSAMATCH => get_string("randomsamatch", "quiz") );
+                              RANDOMSAMATCH => get_string("randomsamatch", "quiz"),
+                              DESCRIPTION   => get_string("description", "quiz") );
 
 $QUIZ_FILE_FORMAT = array ( "custom"   => get_string("custom", "quiz"),
                             "missingword" => get_string("missingword", "quiz"),
@@ -60,7 +62,7 @@ function quiz_add_instance($quiz) {
     // The grades for every question in this quiz are stored in an array
     if ($quiz->grades) {
         foreach ($quiz->grades as $question => $grade) {
-            if ($question and $grade) {
+            if ($question) {
                 unset($questiongrade);
                 $questiongrade->quiz = $quiz->id;
                 $questiongrade->question = $question;
@@ -100,7 +102,7 @@ function quiz_update_instance($quiz) {
 
     if ($quiz->grades) {
         foreach ($quiz->grades as $question => $grade) {
-            if ($question and $grade) {
+            if ($question) {
                 unset($questiongrade);
                 $questiongrade->quiz = $quiz->id;
                 $questiongrade->question = $question;
@@ -376,6 +378,9 @@ function quiz_print_question_icon($question, $editlink=true) {
         case RANDOMSAMATCH:
             echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/rm.gif\">";
             break;
+        case DESCRIPTION:
+            echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/de.gif\">";
+            break;
     }
     if ($editlink) {
         echo "</A>\n";
@@ -391,6 +396,16 @@ function quiz_print_question($number, $question, $grade, $courseid,
 /// Prints a quiz question, any format
 /// $question is provided as an object
 
+    if ($question->qtype == DESCRIPTION) {  // Special case question - has no answers etc
+        echo '<p align="center">';
+        echo text_to_html($question->questiontext);
+        if ($question->image) {
+            print_file_picture($question->image, $courseid);
+        }
+        echo '</p>';
+        return true;
+    }
+
     if (empty($actualgrade)) {
         $actualgrade = 0;
     }
@@ -778,7 +793,10 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff
     $questionorder = array();
 
     foreach ($questions as $question) {
-        $count++;
+
+        if ($question->qtype != DESCRIPTION) {    // Description questions are not counted
+            $count++;
+        }
 
         $questionorder[] = $question->id;
 
@@ -1377,8 +1395,10 @@ function quiz_grade_attempt_results($quiz, $questions) {
             $question->grade = $grades[$question->id];
         }
         
-        if (!$answers = quiz_get_answers($question)) {
-            error("No answers defined for question id $question->id!");
+        if ($question->qtype != DESCRIPTION) {    // All real questions need answers defined
+            if (!$answers = quiz_get_answers($question)) {
+                error("No answers defined for question id $question->id!");
+            }
         }
 
         $grade    = 0;   // default
@@ -1839,6 +1859,9 @@ function quiz_save_question_options($question) {
         case RANDOM:
         break;
 
+        case DESCRIPTION:
+        break;
+
         default:
             $result->error = "Unsupported question type ($question->qtype)!";
             return $result;
diff --git a/mod/quiz/pix/de.gif b/mod/quiz/pix/de.gif
new file mode 100755 (executable)
index 0000000..550df5d
Binary files /dev/null and b/mod/quiz/pix/de.gif differ
index 92846eef83b103ace6478067e2498ee579e99b7d..2c3b63d015b945a3570604a286a2e2245c9a01fc 100644 (file)
             $question->image = $form->image;
         }
 
+        if (isset($form->defaultgrade)) {
+            $question->defaultgrade = $form->defaultgrade;
+        }
+
         if ($err = formcheck($question)) {
             notify(get_string("someerrorswerefound"));
 
             require("random.html");
         break;
 
+        case DESCRIPTION:
+            print_heading(get_string("editingdescription", "quiz"));
+            require("description.html");
+        break;
+
         default:
             error("Invalid question type");
         break;