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
This commit is contained in:
moodler
2003-07-06 04:00:05 +00:00
parent fcf74f5a80
commit 401c8de6c5
8 changed files with 108 additions and 6 deletions
+7
View File
@@ -0,0 +1,7 @@
<P ALIGN=CENTER><B>Description</B></P>
<P>This type of question is not really a question. </p>
<p>All it does is print some text without requiring any answers.</p>
<P>It can be used to print a descriptive text to be used by a following group of questions.</p>
+1
View 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";
+2
View 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";
+57
View File
@@ -0,0 +1,57 @@
<FORM name="theform" method="post" <?=$onsubmit ?> action="question.php">
<CENTER>
<TABLE cellpadding=5>
<TR valign=top>
<TD align=right><P><B><? print_string("category", "quiz") ?>:</B></P></TD>
<TD>
<? choose_from_menu($categories, "category", "$question->category", ""); ?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("questionname", "quiz") ?>:</B></P></TD>
<TD>
<INPUT type="text" name="name" size=40 value="<? p($question->name) ?>">
<? if (isset($err["name"])) formerr($err["name"]); ?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("question", "quiz") ?>:</B></P></TD>
<TD>
<? if (isset($err["questiontext"])) {
formerr($err["questiontext"]);
echo "<BR \>";
}
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");
}
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("imagedisplay", "quiz") ?>:</B></P></TD>
<TD>
<? if (empty($images)) {
print_string("noimagesyet");
} else {
choose_from_menu($images, "image", "$question->image", get_string("none"),"","");
}
?>
</TD>
</TR>
</TABLE>
<INPUT type="hidden" name=id value="<? p($question->id) ?>">
<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">
<INPUT type="hidden" name=defaultgrade value="0">
<INPUT type="submit" value="<? print_string("savechanges") ?>">
</CENTER>
</FORM>
<?
if ($usehtmleditor) {
print_richedit_javascript("theform", "questiontext", "no");
}
?>
+3
View File
@@ -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;
}
+29 -6
View 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;
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

+9
View File
@@ -107,6 +107,10 @@
$question->image = $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;