$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);
}
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);
}
$namestr = get_string($question->qtype, 'quiz');
$html = '<img border="0" height="16" width="16" src="'.$CFG->wwwroot.'/question/type/'.
- $QTYPES[$question->qtype]->name().'/icon.gif" alt="'.
+ $question->qtype.'/icon.gif" alt="'.
$namestr.'" title="'.$namestr.'" />';
if ($editlink) {
$html = "<a href=\"$CFG->wwwroot/question/question.php?id=$question->id\" title=\""
- .$QTYPES[$question->qtype]->name()."\">".
+ .$question->qtype."\">".
$html."</a>\n";
}
if ($return) {
echo "<tr><th colspan=\"3\" nowrap=\"nowrap\" class=\"header\">$strorder</th><th class=\"header\">#</th><th align=\"left\" width=\"100%\" nowrap=\"nowrap\" class=\"header\">$strquestionname</th><th nowrap=\"nowrap\" class=\"header\">$strtype</th><th nowrap=\"nowrap\" class=\"header\">$strgrade</th><th align=\"center\" width=\"60\" nowrap=\"nowrap\" class=\"header\">$straction</th></tr>\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) {
}
$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)) {
echo '<br />';
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) {
-<table id="q<?php echo $question->id; ?>" class="question <?php echo $this->name(); ?>"><tr><td>
+<table id="q<?php echo $question->id; ?>" class="question <?php echo $question->qtype; ?>"><tr><td>
<div class="info">
<span class="edit"><?php echo $editlink; ?></span>
</div>
--- /dev/null
+<?php notify('This question is of a type that has not been installed on your Moodle yet.<br />Please alert your Moodle administrator.'); ?>
+<div class="qtext">
+ <?php echo $questiontext; ?>
+</div>
+
+<?php if ($image) { ?>
+ <img class="qimage" src="<?php echo $q->imageurl; ?>" alt="" />
+<?php } ?>
+
+<div class="ablock clearfix">
+ <div class="prompt">
+ <?php print_string('answers', 'quiz'); ?>
+ </div>
+
+ <table class="answer">
+ <?php $row = 1; foreach ($anss as $answer) { ?>
+ <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
+ <td class="c1 text">
+ <?php echo $answer->text; ?>
+ </td>
+ </tr>
+ <?php } ?>
+ </table>
+</div>
\ No newline at end of file
--- /dev/null
+<form name="theform" method="post" action="question.php">
+<center>
+<table cellpadding="5">
+
+ <tr valign="top">
+ <td align="right"><b><?php print_string("category", "quiz") ?>:</b></td>
+ <td align="left">
+ <?php question_category_select_menu($course->id, true, true, $question->category); ?>
+ </td>
+ </tr>
+
+ <tr valign="top">
+ <td align="right"><b><?php print_string("questionname", "quiz") ?>:</b></td>
+ <td align="left">
+ <input type="text" name="name" size="40" value="<?php p($question->name) ?>" alt="<?php print_string("questionname", "quiz") ?>" />
+ <?php if (isset($err["name"])) formerr($err["name"]); ?>
+ </td>
+ </tr>
+
+ <tr valign="top">
+ <td align="right"><b><?php print_string("question", "quiz") ?>:</b>
+ <br /><br /><br /><font size="1">
+ <?php
+ if ($usehtmleditor) {
+ helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
+ } else {
+ helpbutton("text", get_string("helptext"), "moodle", true, true);
+ }
+ ?>
+ </font>
+ </td>
+ <td align="left">
+ <?php
+ if (isset($err["questiontext"])) {
+ formerr($err["questiontext"]);
+ echo "<br />";
+ }
+ print_textarea($usehtmleditor, 15, 60, 630, 300, "questiontext", $question->questiontext);
+ if ($usehtmleditor) {
+ echo '<input type="hidden" name="questiontextformat" value="'.FORMAT_HTML.'" />';
+ } else {
+ echo "<div align=\"right\">";
+ 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 "</div>";
+ }
+ ?>
+ </td>
+ </tr>
+
+ <tr valign="top">
+ <td align="right"><b><?php print_string("imagedisplay", "quiz") ?>:</b></td>
+ <td align="left">
+ <?php
+ if (empty($images)) {
+ print_string("noimagesyet");
+ } else {
+ choose_from_menu($images, "image", "$question->image", get_string("none"),"","");
+ }
+ ?>
+ </td>
+ </tr>
+<tr valign="top">
+ <td align="right"><b><?php print_string("defaultgrade", "quiz") ?>:</b></td>
+ <td align="left">
+ <input type="text" name="defaultgrade" size="3" value="<?php p($question->defaultgrade) ?>" alt="<?php print_string("defaultgrade", "quiz") ?>" />
+
+ <?php if (isset($err["defaultgrade"])) formerr($err["defaultgrade"]); ?>
+ </td>
+</tr>
+<tr valign="top">
+ <td align="right"><b><?php print_string("penaltyfactor", "quiz") ?>:</b></td>
+ <td align="left">
+ <input type="text" name="penalty" size="3" value="<?php p($question->penalty) ?>" alt="<?php print_string("penaltyfactor", "quiz") ?>" />
+ <?php helpbutton('penalty', get_string('penalty', 'quiz'), 'quiz'); ?>
+ <?php if (isset($err["penalty"])) formerr($err["penalty"]); ?>
+ </td>
+</tr>
+
+<?php
+ for ($i=1; $i<=count($answers); $i++) {
+ if (!isset($answers[$i-1]->fraction)) {
+ $answers[$i-1]->answer = '';
+ $answers[$i-1]->fraction = 0;
+ $answers[$i-1]->feedback = '';
+ }
+?>
+
+ <tr valign="top">
+ <td align="right"><b><?php echo get_string("choice", "quiz")." $i"; ?>:</b></td>
+ <td align="left">
+ <input type="text" name="answer[]" size="50" value="<?php p($answers[$i-1]->answer) ?>" alt="<?php echo get_string("choice", "quiz")." $i"; ?>"/>
+ <?php
+ print_string("grade");
+ echo ": ";
+ choose_from_menu($gradeoptionsfull, "fraction[]", $answers[$i-1]->fraction, "");
+ ?>
+ <br />
+ </td>
+ </tr>
+
+ <tr valign="top">
+ <td align="right"><b><?php print_string("feedback", "quiz") ?>:</b></td>
+ <td align="left">
+ <textarea name="feedback[]" rows="2" cols="50"><?php p($answers[$i-1]->feedback) ?></textarea>
+ </td>
+ </tr>
+
+ <tr valign="top">
+ <td colspan="2"> </td>
+ </tr>
+
+<?php
+ } /// End of loop, printing answers
+ $QTYPES['missingtype']->print_replacement_options($question, $course, $contextquiz);
+ $QTYPES['missingtype']->print_question_form_end($question);
+?>
+</table>
+
+</center>
+</form>
+
--- /dev/null
+<?php // $Id$
+
+ if (!empty($options->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");
+
+?>
--- /dev/null
+<?php // $Id$
+
+///////////////////
+/// missingtype ///
+///////////////////
+
+/// QUESTION TYPE CLASS //////////////////
+
+/**
+ * Missing question type class
+ *
+ * When a question is encountered with a type that is not installed then its
+ * type is changed to 'missingtype'. This questiontype just makes sure that the
+ * necessary information is printed about the question.
+ */
+class question_missingtype_qtype extends default_questiontype {
+
+ function name() {
+ return 'missingtype';
+ }
+
+ function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
+ global $CFG;
+
+ $answers = &$question->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();
+
+?>
* print_question() method.
*/
?>
-<table id="q<?php echo $question->id; ?>" class="question <?php echo $this->name(); ?>"><tr><td>
+<table id="q<?php echo $question->id; ?>" class="question <?php echo $question->qtype; ?>"><tr><td>
<div class="info">
<span class="no"><?php echo $number; ?></span>
<span class="edit"><?php echo $editlink; ?></span>
* 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;
}
/**
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;