From 401c8de6c55a348b3de7d2e8d785d59e1d5f6712 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 6 Jul 2003 04:00:05 +0000 Subject: [PATCH] New question type called "Description". All it does is print some 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 | 7 ++++ lang/en/moodle.php | 1 + lang/en/quiz.php | 2 + mod/quiz/description.html | 57 +++++++++++++++++++++++++++++ mod/quiz/edit.php | 3 ++ mod/quiz/lib.php | 35 +++++++++++++++--- mod/quiz/pix/de.gif | Bin 0 -> 128 bytes mod/quiz/question.php | 9 +++++ 8 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 lang/en/help/quiz/description.html create mode 100644 mod/quiz/description.html create mode 100755 mod/quiz/pix/de.gif diff --git a/lang/en/help/quiz/description.html b/lang/en/help/quiz/description.html new file mode 100644 index 0000000000..f15c672f8e --- /dev/null +++ b/lang/en/help/quiz/description.html @@ -0,0 +1,7 @@ +

Description

+ +

This type of question is not really a question.

+ +

All it does is print some text without requiring any answers.

+ +

It can be used to print a descriptive text to be used by a following group of questions.

diff --git a/lang/en/moodle.php b/lang/en/moodle.php index a346b99883..3aa62257fd 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -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"; diff --git a/lang/en/quiz.php b/lang/en/quiz.php index d8d1073009..5b017f882e 100644 --- a/lang/en/quiz.php +++ b/lang/en/quiz.php @@ -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 index 0000000000..7aaaf9a0a3 --- /dev/null +++ b/mod/quiz/description.html @@ -0,0 +1,57 @@ +
action="question.php"> +
+ + + + + + + + + + + + + + + + + +

:

+ category", ""); ?> +

:

+ + +

:

+ "; + } + print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); + if ($usehtmleditor) { + helpbutton("richtext", get_string("helprichtext"), "moodle"); + } else { + helpbutton("text", get_string("helptext"), "moodle"); + } + ?> +

:

+ image", get_string("none"),"",""); + } + ?> +
+ + + + +"> + +
+
+ diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index c2ebdd9270..8d4dd44270 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -93,8 +93,11 @@ $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; } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index f5e7c65277..585b2b0cb0 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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 ""; break; + case DESCRIPTION: + echo ""; + break; } if ($editlink) { echo "\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 '

'; + echo text_to_html($question->questiontext); + if ($question->image) { + print_file_picture($question->image, $courseid); + } + echo '

'; + 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 index 0000000000000000000000000000000000000000..550df5db8c43d778c40a1290f1d3a724d0e88133 GIT binary patch literal 128 zcmZ?wbhEHb6krfwSoEKPf#I&Pahh>jn(@rE0|yTL|Np+Z^fq{iV2gnAh z6kuRrcJimage = $form->image; } + if (isset($form->defaultgrade)) { + $question->defaultgrade = $form->defaultgrade; + } + if ($err = formcheck($question)) { notify(get_string("someerrorswerefound")); @@ -309,6 +313,11 @@ require("random.html"); break; + case DESCRIPTION: + print_heading(get_string("editingdescription", "quiz")); + require("description.html"); + break; + default: error("Invalid question type"); break; -- 2.39.5