From: gustav_delius Date: Fri, 24 Mar 2006 21:21:59 +0000 (+0000) Subject: Added question type that is used if a question of unknown type is encountered. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4eda4eecbd1b7fd7dc64a95ed34d6e9ad97a4a48;p=moodle.git Added question type that is used if a question of unknown type is encountered. Also removed some of the unnecessary calls to name() --- diff --git a/lib/questionlib.php b/lib/questionlib.php index d24dc8017a..6029898a12 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -521,6 +521,10 @@ function get_question_options(&$questions) { $keys = array_keys($questions); // update each question object foreach ($keys as $i) { + if (!array_key_exists($questions[$i]->qtype, $QTYPES)) { + $questions[$i]->qtype = 'missingtype'; + } + // set name prefix $questions[$i]->name_prefix = question_make_name_prefix($i); @@ -529,6 +533,9 @@ function get_question_options(&$questions) { } return true; } else { // deal with single question + if (!array_key_exists($questions->qtype, $QTYPES)) { + $questions->qtype = 'missingtype'; + } $questions->name_prefix = question_make_name_prefix($questions->id); return $QTYPES[$questions->qtype]->get_question_options($questions); } @@ -1155,12 +1162,12 @@ function print_question_icon($question, $editlink=true, $return = false) { $namestr = get_string($question->qtype, 'quiz'); $html = ''.
+            $question->qtype.'/icon.gif'; if ($editlink) { $html = "wwwroot/question/question.php?id=$question->id\" title=\"" - .$QTYPES[$question->qtype]->name()."\">". + .$question->qtype."\">". $html."\n"; } if ($return) { diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index ff6d5c49ae..74bc183636 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -181,9 +181,15 @@ function quiz_print_question_list($quiz, $allowdelete=true, $showbreaks=true, $r echo "$strorder#$strquestionname$strtype$strgrade$straction\n"; foreach ($order as $i => $qnum) { - if ($qnum and empty($questions[$qnum])) { + if (!$qnum or empty($questions[$qnum])) { continue; } + + // If the questiontype is missing change the question type + if (!array_key_exists($questions[$qnum]->qtype, $QTYPES)) { + $questions[$qnum]->qtype = 'missingtype'; + } + // Show the re-ordering field if the tool is turned on. // But don't show it in front of pagebreaks if they are hidden. if ($reordertool) { diff --git a/question/question.php b/question/question.php index 49ff99cd4d..c4be99a428 100644 --- a/question/question.php +++ b/question/question.php @@ -52,6 +52,9 @@ } $qtype = $question->qtype; + if (!isset($QTYPES[$qtype])) { + $qtype = 'missingtype'; + } } else if ($category) { // only for creating new questions if (! $category = get_record("question_categories", "id", $category)) { @@ -346,7 +349,7 @@ echo '
'; print_simple_box_start('center'); - require_once('type/'.$QTYPES[$qtype]->name().'/editquestion.php'); + require_once('type/'.$qtype.'/editquestion.php'); print_simple_box_end(); if ($usehtmleditor) { diff --git a/question/type/description/question.html b/question/type/description/question.html index e805ffa68d..b57f49404d 100644 --- a/question/type/description/question.html +++ b/question/type/description/question.html @@ -1,4 +1,4 @@ -
+
diff --git a/question/type/missingtype/display.html b/question/type/missingtype/display.html new file mode 100644 index 0000000000..a833706696 --- /dev/null +++ b/question/type/missingtype/display.html @@ -0,0 +1,24 @@ +Please alert your Moodle administrator.'); ?> +
+ +
+ + + + + +
+
+ +
+ + + + + + + +
+ text; ?> +
+
\ No newline at end of file diff --git a/question/type/missingtype/editquestion.html b/question/type/missingtype/editquestion.html new file mode 100644 index 0000000000..85dfb37d68 --- /dev/null +++ b/question/type/missingtype/editquestion.html @@ -0,0 +1,127 @@ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +fraction)) { + $answers[$i-1]->answer = ''; + $answers[$i-1]->fraction = 0; + $answers[$i-1]->feedback = ''; + } +?> + + + + + + + + + + + + + + + +print_replacement_options($question, $course, $contextquiz); + $QTYPES['missingtype']->print_question_form_end($question); +?> +
: + id, true, true, $question->category); ?> +
: + " /> + +
: +


+ + +
+ "; + } + print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext); + if ($usehtmleditor) { + echo ''; + } else { + echo "
"; + print_string("formattexttype"); + echo ": "; + if (!isset($question->questiontextformat)) { + $question->questiontextformat = FORMAT_MOODLE; + } + choose_from_menu(format_text_menu(), "questiontextformat", $question->questiontextformat, ""); + helpbutton("textformat", get_string("helpformatting")); + echo "
"; + } + ?> +
: + image", get_string("none"),"",""); + } + ?> +
: + " /> + + +
: + " /> + + +
: + "/>   + fraction, ""); + ?> +
+
: + +
 
+ +
+
+ diff --git a/question/type/missingtype/editquestion.php b/question/type/missingtype/editquestion.php new file mode 100644 index 0000000000..28710898c7 --- /dev/null +++ b/question/type/missingtype/editquestion.php @@ -0,0 +1,22 @@ +answers)) { + $answersraw = get_records_list("question_answers", "id", $options->answers); + + } + + $answers = array(); + if (!empty($answersraw)) { + foreach ($answersraw as $answer) { + $answers[] = $answer; // insert answers into slots + } + } + + $yesnooptions = array(); + $yesnooptions[0] = get_string("no"); + $yesnooptions[1] = get_string("yes"); + + print_heading_with_help(get_string("editingmissingtype", "quiz"), "multichoice", "quiz"); + require("$CFG->dirroot/question/type/missingtype/editquestion.html"); + +?> diff --git a/question/type/missingtype/icon.gif b/question/type/missingtype/icon.gif new file mode 100644 index 0000000000..d264c818ae Binary files /dev/null and b/question/type/missingtype/icon.gif differ diff --git a/question/type/missingtype/questiontype.php b/question/type/missingtype/questiontype.php new file mode 100644 index 0000000000..f759bbd6e2 --- /dev/null +++ b/question/type/missingtype/questiontype.php @@ -0,0 +1,57 @@ +options->answers; + + $formatoptions = new stdClass; + $formatoptions->noclean = true; + $formatoptions->para = false; + + // Print formulation + $questiontext = format_text($question->questiontext, + $question->questiontextformat, + $formatoptions, $cmoptions->course); + $image = get_question_image($question, $cmoptions->course); + + // Print each answer in a separate row + foreach ($answers as $answer) { + $a->text = format_text("$answer->answer", FORMAT_MOODLE, $formatoptions, $cmoptions->course); + + $anss[] = clone($a); + } + include("$CFG->dirroot/question/type/missingtype/display.html"); + } + + function grade_responses(&$question, &$state, $cmoptions) { + return true; + } +} +//// END OF CLASS //// + +////////////////////////////////////////////////////////////////////////// +//// INITIATION - Without this line the question type is not in use... /// +////////////////////////////////////////////////////////////////////////// +$QTYPES['missingtype']= new question_missingtype_qtype(); + +?> diff --git a/question/type/question.html b/question/type/question.html index 83b73a280e..8e438da455 100644 --- a/question/type/question.html +++ b/question/type/question.html @@ -3,7 +3,7 @@ * print_question() method. */ ?> -
+
diff --git a/question/type/questiontype.php b/question/type/questiontype.php index e70d93ebcd..cf9c6f6efd 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -126,10 +126,7 @@ class default_questiontype { * it is not a standard question object. */ function save_question_options($question) { - /// This default implementation must be overridden: - - $result->error = "Unsupported question type ($question->qtype)!"; - return $result; + return null; } /** @@ -330,9 +327,11 @@ class default_questiontype { function get_correct_responses(&$question, &$state) { /* The default implementation returns the response for the first answer that gives full marks. */ - foreach ($question->options->answers as $answer) { - if (((int) $answer->fraction) === 1) { - return array('' => $answer->answer); + if ($question->options->answers) { + foreach ($question->options->answers as $answer) { + if (((int) $answer->fraction) === 1) { + return array('' => $answer->answer); + } } } return null;