protected function display_content($question, $rowclasses) { $text = question_rewrite_questiontext_preview_urls($question->questiontext, $question->contextid, 'question', $question->id); $text = format_text($text, $question->questiontextformat, $this->formatoptions); if ($text == '') { $text = ' '; } echo $text; }
/** * @param object $question question data. * @return string HTML of question text, ready for display. */ protected function render_question_text($question) { global $OUTPUT; $text = question_rewrite_questiontext_preview_urls($question->questiontext, $this->context->id, 'quiz_statistics', $question->id); return $OUTPUT->box(format_text($text, $question->questiontextformat, array('noclean' => true, 'para' => false, 'overflowdiv' => true)), 'questiontext boxaligncenter generalbox boxwidthnormal mdl-align'); }
protected function writequestion($question) { global $OUTPUT; // turns question into string // question reflects database fields for general question and specific to type // if a category switch, just ignore if ($question->qtype=='category') { return ''; } // initial string; $expout = ""; $id = $question->id; // add comment and div tags $expout .= "<!-- question: $id name: $question->name -->\n"; $expout .= "<div class=\"question\">\n"; // add header $expout .= "<h3>$question->name</h3>\n"; // Format and add the question text. $text = question_rewrite_questiontext_preview_urls($question->questiontext, $question->contextid, 'qformat_xhtml', $question->id); $expout .= '<p class="questiontext">' . format_text($text, $question->questiontextformat, array('noclean' => true)) . "</p>\n"; // selection depends on question type switch($question->qtype) { case 'truefalse': $st_true = get_string('true', 'qtype_truefalse'); $st_false = get_string('false', 'qtype_truefalse'); $expout .= "<ul class=\"truefalse\">\n"; $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"$st_true\" />$st_true</li>\n"; $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"$st_false\" />$st_false</li>\n"; $expout .= "</ul>\n"; break; case 'multichoice': $expout .= "<ul class=\"multichoice\">\n"; foreach($question->options->answers as $answer) { $ans_text = $this->repchar( $answer->answer ); if ($question->options->single) { $expout .= " <li><input name=\"quest_$id\" type=\"radio\" value=\"" . s($ans_text) . "\" />$ans_text</li>\n"; } else { $expout .= " <li><input name=\"quest_$id\" type=\"checkbox\" value=\"" . s($ans_text) . "\" />$ans_text</li>\n"; } } $expout .= "</ul>\n"; break; case 'shortanswer': $expout .= html_writer::start_tag('ul', array('class' => 'shortanswer')); $expout .= html_writer::start_tag('li'); $expout .= html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide')); $expout .= html_writer::empty_tag('input', array('id' => "quest_$id", 'name' => "quest_$id", 'type' => 'text')); $expout .= html_writer::end_tag('li'); $expout .= html_writer::end_tag('ul'); break; case 'numerical': $expout .= html_writer::start_tag('ul', array('class' => 'numerical')); $expout .= html_writer::start_tag('li'); $expout .= html_writer::label(get_string('answer'), 'quest_'.$id, false, array('class' => 'accesshide')); $expout .= html_writer::empty_tag('input', array('id' => "quest_$id", 'name' => "quest_$id", 'type' => 'text')); $expout .= html_writer::end_tag('li'); $expout .= html_writer::end_tag('ul'); break; case 'match': $expout .= html_writer::start_tag('ul', array('class' => 'match')); // build answer list $ans_list = array(); foreach($question->options->subquestions as $subquestion) { $ans_list[] = $this->repchar( $subquestion->answertext ); } shuffle( $ans_list ); // random display order // Build select options. $selectoptions = array(); foreach($ans_list as $ans) { $selectoptions[s($ans)] = s($ans); } // display $option = 0; foreach($question->options->subquestions as $subquestion) { // build drop down for answers $quest_text = $this->repchar( $subquestion->questiontext ); if ($quest_text != '') { $dropdown = html_writer::label(get_string('answer', 'qtype_match', $option+1), 'quest_'.$id.'_'.$option, false, array('class' => 'accesshide')); $dropdown .= html_writer::select($selectoptions, "quest_{$id}_{$option}", '', false, array('id' => "quest_{$id}_{$option}")); $expout .= html_writer::tag('li', $quest_text); $expout .= $dropdown; $option++; } } $expout .= html_writer::end_tag('ul'); break; case 'description': break; case 'multianswer': default: $expout .= "<!-- export of $question->qtype type is not supported -->\n"; } // close off div $expout .= "</div>\n\n\n"; return $expout; }