From 5cdb8a856a0d35c8cff17b5f093505286672fef5 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 13 Feb 2004 14:01:27 +0000 Subject: [PATCH] Quiz questions now have proper formatting controls. Any format can be used. This fixes a number of problems at once, but the latest one is Bug #1047 --- mod/quiz/db/mysql.php | 4 ++++ mod/quiz/db/mysql.sql | 1 + mod/quiz/db/postgres7.php | 4 ++++ mod/quiz/db/postgres7.sql | 1 + mod/quiz/description.html | 41 +++++++++++++++++++++++++++++-------- mod/quiz/lib.php | 14 ++++++------- mod/quiz/match.html | 41 +++++++++++++++++++++++++++++-------- mod/quiz/multichoice.html | 41 +++++++++++++++++++++++++++++-------- mod/quiz/numerical.html | 41 +++++++++++++++++++++++++++++-------- mod/quiz/question.php | 5 +++-- mod/quiz/randomsamatch.html | 41 +++++++++++++++++++++++++++++-------- mod/quiz/shortanswer.html | 41 +++++++++++++++++++++++++++++-------- mod/quiz/truefalse.html | 41 +++++++++++++++++++++++++++++-------- mod/quiz/version.php | 2 +- 14 files changed, 245 insertions(+), 73 deletions(-) diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index a081976110..3acd83986c 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -181,6 +181,10 @@ function quiz_upgrade($oldversion) { } } + if ($oldversion < 2004021300) { + table_column("quiz_questions", "", "questiontextformat", "integer", "2", "", "0", "not null", "questiontext"); + } + return true; } diff --git a/mod/quiz/db/mysql.sql b/mod/quiz/db/mysql.sql index 664bd7a2db..5d7b6ca88a 100644 --- a/mod/quiz/db/mysql.sql +++ b/mod/quiz/db/mysql.sql @@ -168,6 +168,7 @@ CREATE TABLE `prefix_quiz_questions` ( `category` int(10) NOT NULL default '0', `name` varchar(255) NOT NULL default '', `questiontext` text NOT NULL, + `questiontextformat` tinyint(2) NOT NULL default '0', `image` varchar(255) NOT NULL default '', `defaultgrade` INT UNSIGNED DEFAULT '1' NOT NULL, `qtype` smallint(6) NOT NULL default '0', diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index 6997247cd0..7a51e5baa9 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -136,6 +136,10 @@ function quiz_upgrade($oldversion) { } } + if ($oldversion < 2004021300) { + table_column("quiz_questions", "", "questiontextformat", "integer", "2", "", "0", "not null", "questiontext"); + } + return true; } diff --git a/mod/quiz/db/postgres7.sql b/mod/quiz/db/postgres7.sql index b83cbd122d..4a06590127 100644 --- a/mod/quiz/db/postgres7.sql +++ b/mod/quiz/db/postgres7.sql @@ -181,6 +181,7 @@ CREATE TABLE prefix_quiz_questions ( category integer NOT NULL default '0', name varchar(255) NOT NULL default '', questiontext text NOT NULL default '', + questiontextformat integer NOT NULL default '0', image varchar(255) NOT NULL default '', defaultgrade integer NOT NULL default '1', qtype integer NOT NULL default '0', diff --git a/mod/quiz/description.html b/mod/quiz/description.html index 050d12f321..5e1382d045 100644 --- a/mod/quiz/description.html +++ b/mod/quiz/description.html @@ -14,22 +14,45 @@ - -

:

- + +

:

+
+
+
+

+ +

+ + "; + echo "
"; } + print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle"); + + if ($usehtmleditor) { /// Trying this out for a while + echo ''; } else { - helpbutton("text", get_string("helptext"), "moodle"); + echo "
"; + print_string("formattexttype"); + echo ": "; + if (!$question->questiontextformat) { + $question->questiontextformat = FORMAT_MOODLE; + } + choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, ""); + helpbutton("textformat", get_string("helpformatting")); + echo "
"; } ?> - - + +

:

diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index a97679abb0..8be5f2c2eb 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -515,7 +515,7 @@ function quiz_print_question($number, $question, $grade, $quizid, if ($question->qtype == DESCRIPTION) { // Special case question - has no answers etc echo '

'; - echo format_text($question->questiontext, FORMAT_HTML, NULL, $courseid); + echo format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); quiz_print_possible_question_image($quizid, $question); echo '

'; return true; @@ -563,7 +563,7 @@ function quiz_print_question($number, $question, $grade, $quizid, case SHORTANSWER: case NUMERICAL: - echo format_text($question->questiontext, FORMAT_HTML, NULL, $courseid); + echo format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); quiz_print_possible_question_image($quizid, $question); if ($response) { $value = "value=\"$response[0]\""; @@ -596,7 +596,7 @@ function quiz_print_question($number, $question, $grade, $quizid, if (!$false->answer) { $false->answer = get_string("false", "quiz"); } - echo format_text($question->questiontext, FORMAT_HTML, NULL, $courseid); + echo format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); quiz_print_possible_question_image($quizid, $question); $truechecked = ""; @@ -639,7 +639,7 @@ function quiz_print_question($number, $question, $grade, $quizid, if (!$answers = get_records_list("quiz_answers", "id", $options->answers)) { notify("Error: Missing question answers!"); } - echo format_text($question->questiontext, FORMAT_HTML, NULL, $courseid); + echo format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); quiz_print_possible_question_image($quizid, $question); echo ""; echo " - - - + + - + + - - - + + - + + - - - + + - + + - - - + +
+
+
+

+ +

+ + - + + - - - + + - + + - - - + + - + +
$stranswer:  "; @@ -692,7 +692,7 @@ function quiz_print_question($number, $question, $grade, $quizid, notify("Error: Missing subquestions for this question!"); } if (!empty($question->questiontext)) { - echo format_text($question->questiontext, FORMAT_HTML, NULL, $courseid); + echo format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); } quiz_print_possible_question_image($quizid, $question); @@ -741,7 +741,7 @@ function quiz_print_question($number, $question, $grade, $quizid, if (!$options = get_record("quiz_randomsamatch", "question", $question->id)) { notify("Error: Missing question options!"); } - echo format_text($question->questiontext, FORMAT_HTML, NULL, $courseid); + echo format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); quiz_print_possible_question_image($quizid, $question); /// First, get all the questions available @@ -826,7 +826,7 @@ function quiz_print_question($number, $question, $grade, $quizid, // For this question type, we better print the image on top: quiz_print_possible_question_image($quizid, $question); - $qtextremaining = format_text($question->questiontext, FORMAT_HTML, NULL, $courseid); + $qtextremaining = format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); // The regex will recognize text snippets of type {#X} where the X can be any text not containg } or white-space characters. while (ereg('\{#([^[:space:]}]*)}', $qtextremaining, $regs)) { diff --git a/mod/quiz/match.html b/mod/quiz/match.html index 69ecfcf011..39723701f2 100644 --- a/mod/quiz/match.html +++ b/mod/quiz/match.html @@ -14,22 +14,45 @@

:

+

:

+
+
+
+

+ +

+
"; + echo "
"; } + print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle"); + + if ($usehtmleditor) { /// Trying this out for a while + echo ''; } else { - helpbutton("text", get_string("helptext"), "moodle"); + echo "
"; + print_string("formattexttype"); + echo ": "; + if (!$question->questiontextformat) { + $question->questiontextformat = FORMAT_MOODLE; + } + choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, ""); + helpbutton("textformat", get_string("helpformatting")); + echo "
"; } ?> -

:

diff --git a/mod/quiz/multichoice.html b/mod/quiz/multichoice.html index 379ab092da..29ec71bce2 100644 --- a/mod/quiz/multichoice.html +++ b/mod/quiz/multichoice.html @@ -14,22 +14,45 @@

:

+

:

+
+
+
+

+ +

+
"; + echo "
"; } + print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle"); + + if ($usehtmleditor) { /// Trying this out for a while + echo ''; } else { - helpbutton("text", get_string("helptext"), "moodle"); + echo "
"; + print_string("formattexttype"); + echo ": "; + if (!$question->questiontextformat) { + $question->questiontextformat = FORMAT_MOODLE; + } + choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, ""); + helpbutton("textformat", get_string("helpformatting")); + echo "
"; } ?> -

:

diff --git a/mod/quiz/numerical.html b/mod/quiz/numerical.html index 393f126c4f..6a9b4f41da 100644 --- a/mod/quiz/numerical.html +++ b/mod/quiz/numerical.html @@ -14,22 +14,45 @@

:

+

:

+
+
+
+

+ +

+
"; + echo "
"; } + print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle"); + + if ($usehtmleditor) { /// Trying this out for a while + echo ''; } else { - helpbutton("text", get_string("helptext"), "moodle"); + echo "
"; + print_string("formattexttype"); + echo ": "; + if (!$question->questiontextformat) { + $question->questiontextformat = FORMAT_MOODLE; + } + choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, ""); + helpbutton("textformat", get_string("helpformatting")); + echo "
"; } ?> -

:

diff --git a/mod/quiz/question.php b/mod/quiz/question.php index d367411a85..6af541209b 100644 --- a/mod/quiz/question.php +++ b/mod/quiz/question.php @@ -102,8 +102,9 @@ // First, save the basic question itself - $question->name = $form->name; - $question->questiontext = $form->questiontext; + $question->name = $form->name; + $question->questiontext = $form->questiontext; + $question->questiontextformat = $form->questiontextformat; if (empty($form->image)) { $question->image = ""; diff --git a/mod/quiz/randomsamatch.html b/mod/quiz/randomsamatch.html index 5cb2c4bd7a..e763e604cf 100644 --- a/mod/quiz/randomsamatch.html +++ b/mod/quiz/randomsamatch.html @@ -20,25 +20,48 @@

:

+

:

"; + echo "
"; } + if (empty($question->questiontext)) { $question->questiontext = get_string("randomsamatchintro", "quiz"); } print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle"); + + if ($usehtmleditor) { /// Trying this out for a while + echo ''; } else { - helpbutton("text", get_string("helptext"), "moodle"); + echo "
"; + print_string("formattexttype"); + echo ": "; + if (!$question->questiontextformat) { + $question->questiontextformat = FORMAT_MOODLE; + } + choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, ""); + helpbutton("textformat", get_string("helpformatting")); + echo "
"; } ?> -

:

diff --git a/mod/quiz/shortanswer.html b/mod/quiz/shortanswer.html index 1f799b3740..b17a15b654 100644 --- a/mod/quiz/shortanswer.html +++ b/mod/quiz/shortanswer.html @@ -14,22 +14,45 @@

:

+

:

+
+
+
+

+ +

+
"; + echo "
"; } + print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle"); + + if ($usehtmleditor) { /// Trying this out for a while + echo ''; } else { - helpbutton("text", get_string("helptext"), "moodle"); + echo "
"; + print_string("formattexttype"); + echo ": "; + if (!$question->questiontextformat) { + $question->questiontextformat = FORMAT_MOODLE; + } + choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, ""); + helpbutton("textformat", get_string("helpformatting")); + echo "
"; } ?> -

:

diff --git a/mod/quiz/truefalse.html b/mod/quiz/truefalse.html index 9ccef4b174..614bb3c62b 100644 --- a/mod/quiz/truefalse.html +++ b/mod/quiz/truefalse.html @@ -14,22 +14,45 @@

:

+

:

+
+
+
+

+ +

+
"; + echo "
"; } + print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); - if ($usehtmleditor) { - helpbutton("richtext", get_string("helprichtext"), "moodle"); + + if ($usehtmleditor) { /// Trying this out for a while + echo ''; } else { - helpbutton("text", get_string("helptext"), "moodle"); + echo "
"; + print_string("formattexttype"); + echo ": "; + if (!$question->questiontextformat) { + $question->questiontextformat = FORMAT_MOODLE; + } + choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, ""); + helpbutton("textformat", get_string("helpformatting")); + echo "
"; } ?> -

:

diff --git a/mod/quiz/version.php b/mod/quiz/version.php index 81810f6cca..fab4cb0ee7 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -5,7 +5,7 @@ // This fragment is called by moodle_needs_upgrading() and /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2004020500; // The (date) version of this module +$module->version = 2004021300; // The (date) version of this module $module->requires = 2004013101; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)? -- 2.39.5