mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-24594_wip' of git://github.com/timhunt/moodle
This commit is contained in:
commit
8edbfba909
12 changed files with 122 additions and 66 deletions
|
@ -2513,6 +2513,8 @@ class restore_create_question_files extends restore_execution_step {
|
||||||
$oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true);
|
$oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true);
|
||||||
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'generalfeedback',
|
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'generalfeedback',
|
||||||
$oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true);
|
$oldctxid, $this->task->get_userid(), 'question_created', $question->itemid, $newctxid, true);
|
||||||
|
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'answer',
|
||||||
|
$oldctxid, $this->task->get_userid(), 'question_answer', null, $newctxid, true);
|
||||||
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'answerfeedback',
|
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'answerfeedback',
|
||||||
$oldctxid, $this->task->get_userid(), 'question_answer', null, $newctxid, true);
|
$oldctxid, $this->task->get_userid(), 'question_answer', null, $newctxid, true);
|
||||||
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'hint',
|
restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'question', 'hint',
|
||||||
|
|
|
@ -218,34 +218,28 @@ class qformat_xml extends qformat_default {
|
||||||
* @param array answer xml tree for single answer
|
* @param array answer xml tree for single answer
|
||||||
* @return object answer object
|
* @return object answer object
|
||||||
*/
|
*/
|
||||||
public function import_answer($answer) {
|
public function import_answer($answer, $withanswerfiles = false) {
|
||||||
$fraction = $this->getpath($answer, array('@', 'fraction'), 0);
|
|
||||||
$answertext = $this->getpath($answer, array('#', 'text', 0, '#'), '', true);
|
|
||||||
$answerformat = $this->trans_format($this->getpath($answer,
|
|
||||||
array('@', 'format'), 'moodle_auto_format'));
|
|
||||||
$answerfiles = $this->import_files($this->getpath($answer,
|
|
||||||
array('#', 'file'), array()));
|
|
||||||
|
|
||||||
$feedbacktext = $this->getpath($answer,
|
|
||||||
array('#', 'feedback', 0, '#', 'text', 0, '#'), '', true);
|
|
||||||
$feedbackformat = $this->trans_format($this->getpath($answer,
|
|
||||||
array('#', 'feedback', 0, '@', 'format'), 'moodle_auto_format'));
|
|
||||||
$feedbackfiles = $this->import_files($this->getpath($answer,
|
|
||||||
array('#', 'feedback', 0, '#', 'file'), array()));
|
|
||||||
|
|
||||||
$ans = new stdClass();
|
$ans = new stdClass();
|
||||||
|
|
||||||
$ans->answer = array();
|
$ans->answer = array();
|
||||||
$ans->answer['text'] = $answertext;
|
$ans->answer['text'] = $this->getpath($answer, array('#', 'text', 0, '#'), '', true);
|
||||||
$ans->answer['format'] = $answerformat;
|
$ans->answer['format'] = $this->trans_format($this->getpath($answer,
|
||||||
$ans->answer['files'] = $answerfiles;
|
array('@', 'format'), 'moodle_auto_format'));
|
||||||
|
if ($withanswerfiles) {
|
||||||
|
$ans->answer['files'] = $this->import_files($this->getpath($answer,
|
||||||
|
array('#', 'file'), array()));
|
||||||
|
}
|
||||||
|
|
||||||
$ans->feedback = array();
|
$ans->feedback = array();
|
||||||
$ans->feedback['text'] = $feedbacktext;
|
$ans->feedback['text'] = $this->getpath($answer,
|
||||||
$ans->feedback['format'] = $feedbackformat;
|
array('#', 'feedback', 0, '#', 'text', 0, '#'), '', true);
|
||||||
$ans->feedback['files'] = $feedbackfiles;
|
$ans->feedback['format'] = $this->trans_format($this->getpath($answer,
|
||||||
|
array('#', 'feedback', 0, '@', 'format'), 'moodle_auto_format'));
|
||||||
|
$ans->feedback['files'] = $this->import_files($this->getpath($answer,
|
||||||
|
array('#', 'feedback', 0, '#', 'file'), array()));
|
||||||
|
|
||||||
|
$ans->fraction = $this->getpath($answer, array('@', 'fraction'), 0) / 100;
|
||||||
|
|
||||||
$ans->fraction = $fraction / 100;
|
|
||||||
return $ans;
|
return $ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,19 +297,13 @@ class qformat_xml extends qformat_default {
|
||||||
return $hint;
|
return $hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
$hint->hint = $this->getpath($hintxml,
|
|
||||||
array('#', 'text', 0, '#'), '', true);
|
|
||||||
$hinttext = array();
|
|
||||||
$hinttext['text'] = $this->getpath($hintxml,
|
|
||||||
array('#', 'text', 0, '#'), '', true);
|
|
||||||
$hinttext['format'] = $this->trans_format($this->getpath($hintxml,
|
|
||||||
array('@', 'format'), 'moodle_auto_format'));
|
|
||||||
|
|
||||||
$hinttext['files'] = $this->import_files($this->getpath($hintxml,
|
|
||||||
array('#', 'file'), array(), false));
|
|
||||||
|
|
||||||
$hint = new stdClass();
|
$hint = new stdClass();
|
||||||
$hint->hint = $hinttext;
|
$hint->hint['text'] = $this->getpath($hintxml,
|
||||||
|
array('#', 'text', 0, '#'), '', true);
|
||||||
|
$hint->hint['format'] = $this->trans_format($this->getpath($hintxml,
|
||||||
|
array('@', 'format'), 'moodle_auto_format'));
|
||||||
|
$hint->hint['files'] = $this->import_files($this->getpath($hintxml,
|
||||||
|
array('#', 'file'), array(), false));
|
||||||
$hint->shownumcorrect = array_key_exists('shownumcorrect', $hintxml['#']);
|
$hint->shownumcorrect = array_key_exists('shownumcorrect', $hintxml['#']);
|
||||||
$hint->clearwrong = array_key_exists('clearwrong', $hintxml['#']);
|
$hint->clearwrong = array_key_exists('clearwrong', $hintxml['#']);
|
||||||
$hint->options = $this->getpath($hintxml, array('#', 'options', 0, '#'), '', true);
|
$hint->options = $this->getpath($hintxml, array('#', 'options', 0, '#'), '', true);
|
||||||
|
@ -395,7 +383,7 @@ class qformat_xml extends qformat_default {
|
||||||
$answers = $question['#']['answer'];
|
$answers = $question['#']['answer'];
|
||||||
$acount = 0;
|
$acount = 0;
|
||||||
foreach ($answers as $answer) {
|
foreach ($answers as $answer) {
|
||||||
$ans = $this->import_answer($answer);
|
$ans = $this->import_answer($answer, true);
|
||||||
$qo->answer[$acount] = $ans->answer;
|
$qo->answer[$acount] = $ans->answer;
|
||||||
$qo->fraction[$acount] = $ans->fraction;
|
$qo->fraction[$acount] = $ans->fraction;
|
||||||
$qo->feedback[$acount] = $ans->feedback;
|
$qo->feedback[$acount] = $ans->feedback;
|
||||||
|
@ -768,7 +756,7 @@ class qformat_xml extends qformat_default {
|
||||||
$qo->correctanswerlength = array();
|
$qo->correctanswerlength = array();
|
||||||
$qo->feedback = array();
|
$qo->feedback = array();
|
||||||
foreach ($answers as $answer) {
|
foreach ($answers as $answer) {
|
||||||
$ans = $this->import_answer($answer);
|
$ans = $this->import_answer($answer, true);
|
||||||
// answer outside of <text> is deprecated
|
// answer outside of <text> is deprecated
|
||||||
if (empty($ans->answer['text'])) {
|
if (empty($ans->answer['text'])) {
|
||||||
$ans->answer['text'] = '*';
|
$ans->answer['text'] = '*';
|
||||||
|
@ -1065,6 +1053,8 @@ class qformat_xml extends qformat_default {
|
||||||
$contextid, 'question', 'generalfeedback', $question->id);
|
$contextid, 'question', 'generalfeedback', $question->id);
|
||||||
if (!empty($question->options->answers)) {
|
if (!empty($question->options->answers)) {
|
||||||
foreach ($question->options->answers as $answer) {
|
foreach ($question->options->answers as $answer) {
|
||||||
|
$answer->answerfiles = $fs->get_area_files(
|
||||||
|
$contextid, 'question', 'answer', $answer->id);
|
||||||
$answer->feedbackfiles = $fs->get_area_files(
|
$answer->feedbackfiles = $fs->get_area_files(
|
||||||
$contextid, 'question', 'answerfeedback', $answer->id);
|
$contextid, 'question', 'answerfeedback', $answer->id);
|
||||||
}
|
}
|
||||||
|
@ -1429,6 +1419,7 @@ class qformat_xml extends qformat_default {
|
||||||
$output = '';
|
$output = '';
|
||||||
$output .= " <answer fraction=\"$percent\" {$this->format($answer->answerformat)}>\n";
|
$output .= " <answer fraction=\"$percent\" {$this->format($answer->answerformat)}>\n";
|
||||||
$output .= $this->writetext($answer->answer, 3);
|
$output .= $this->writetext($answer->answer, 3);
|
||||||
|
$output .= $this->writefiles($answer->answerfiles);
|
||||||
$output .= " <feedback {$this->format($answer->feedbackformat)}>\n";
|
$output .= " <feedback {$this->format($answer->feedbackformat)}>\n";
|
||||||
$output .= $this->writetext($answer->feedback, 4);
|
$output .= $this->writetext($answer->feedback, 4);
|
||||||
$output .= $this->writefiles($answer->feedbackfiles);
|
$output .= $this->writefiles($answer->feedbackfiles);
|
||||||
|
|
|
@ -282,7 +282,7 @@ abstract class question_edit_form extends moodleform {
|
||||||
* field holding an array of answers
|
* field holding an array of answers
|
||||||
* @return array of form fields.
|
* @return array of form fields.
|
||||||
*/
|
*/
|
||||||
protected function get_per_answer_fields(&$mform, $label, $gradeoptions,
|
protected function get_per_answer_fields($mform, $label, $gradeoptions,
|
||||||
&$repeatedoptions, &$answersoption) {
|
&$repeatedoptions, &$answersoption) {
|
||||||
$repeated = array();
|
$repeated = array();
|
||||||
$repeated[] = $mform->createElement('header', 'answerhdr', $label);
|
$repeated[] = $mform->createElement('header', 'answerhdr', $label);
|
||||||
|
@ -498,14 +498,31 @@ abstract class question_edit_form extends moodleform {
|
||||||
* @param object $question the data being passed to the form.
|
* @param object $question the data being passed to the form.
|
||||||
* @return object $question the modified data.
|
* @return object $question the modified data.
|
||||||
*/
|
*/
|
||||||
protected function data_preprocessing_answers($question) {
|
protected function data_preprocessing_answers($question, $withanswerfiles = false) {
|
||||||
if (empty($question->options->answers)) {
|
if (empty($question->options->answers)) {
|
||||||
return $question;
|
return $question;
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = 0;
|
$key = 0;
|
||||||
foreach ($question->options->answers as $answer) {
|
foreach ($question->options->answers as $answer) {
|
||||||
$question->answer[$key] = $answer->answer;
|
if ($withanswerfiles) {
|
||||||
|
// Prepare the feedback editor to display files in draft area
|
||||||
|
$draftitemid = file_get_submitted_draft_itemid('answer['.$key.']');
|
||||||
|
$question->answer[$key]['text'] = file_prepare_draft_area(
|
||||||
|
$draftitemid, // draftid
|
||||||
|
$this->context->id, // context
|
||||||
|
'question', // component
|
||||||
|
'answer', // filarea
|
||||||
|
!empty($answer->id) ? (int) $answer->id : null, // itemid
|
||||||
|
$this->fileoptions, // options
|
||||||
|
$answer->answer // text
|
||||||
|
);
|
||||||
|
$question->answer[$key]['itemid'] = $draftitemid;
|
||||||
|
$question->answer[$key]['format'] = $answer->answerformat;
|
||||||
|
} else {
|
||||||
|
$question->answer[$key] = $answer->answer;
|
||||||
|
}
|
||||||
|
|
||||||
$question->fraction[$key] = 0 + $answer->fraction;
|
$question->fraction[$key] = 0 + $answer->fraction;
|
||||||
$question->feedback[$key] = array();
|
$question->feedback[$key] = array();
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,22 @@ class qtype_multichoice_edit_form extends question_edit_form {
|
||||||
$this->add_interactive_settings(true, true);
|
$this->add_interactive_settings(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function get_per_answer_fields($mform, $label, $gradeoptions,
|
||||||
|
&$repeatedoptions, &$answersoption) {
|
||||||
|
$repeated = array();
|
||||||
|
$repeated[] = $mform->createElement('header', 'answerhdr', $label);
|
||||||
|
$repeated[] = $mform->createElement('editor', 'answer',
|
||||||
|
get_string('answer', 'question'), array('rows' => 1), $this->editoroptions);
|
||||||
|
$repeated[] = $mform->createElement('select', 'fraction',
|
||||||
|
get_string('grade'), $gradeoptions);
|
||||||
|
$repeated[] = $mform->createElement('editor', 'feedback',
|
||||||
|
get_string('feedback', 'question'), array('rows' => 1), $this->editoroptions);
|
||||||
|
$repeatedoptions['answer']['type'] = PARAM_RAW;
|
||||||
|
$repeatedoptions['fraction']['default'] = 0;
|
||||||
|
$answersoption = 'answers';
|
||||||
|
return $repeated;
|
||||||
|
}
|
||||||
|
|
||||||
protected function data_preprocessing($question) {
|
protected function data_preprocessing($question) {
|
||||||
$question = parent::data_preprocessing($question);
|
$question = parent::data_preprocessing($question);
|
||||||
$question = $this->data_preprocessing_answers($question, true);
|
$question = $this->data_preprocessing_answers($question, true);
|
||||||
|
@ -92,7 +108,7 @@ class qtype_multichoice_edit_form extends question_edit_form {
|
||||||
|
|
||||||
foreach ($answers as $key => $answer) {
|
foreach ($answers as $key => $answer) {
|
||||||
//check no of choices
|
//check no of choices
|
||||||
$trimmedanswer = trim($answer);
|
$trimmedanswer = trim($answer['text']);
|
||||||
if (empty($trimmedanswer)) {
|
if (empty($trimmedanswer)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,10 @@ abstract class qtype_multichoice_base extends question_graded_automatically {
|
||||||
array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'))) {
|
array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'))) {
|
||||||
return $this->check_combined_feedback_file_access($qa, $options, $filearea);
|
return $this->check_combined_feedback_file_access($qa, $options, $filearea);
|
||||||
|
|
||||||
|
} else if ($component == 'question' && $filearea == 'answer') {
|
||||||
|
$answerid = reset($args); // itemid is answer id.
|
||||||
|
return in_array($answerid, $this->order);
|
||||||
|
|
||||||
} else if ($component == 'question' && $filearea == 'answerfeedback') {
|
} else if ($component == 'question' && $filearea == 'answerfeedback') {
|
||||||
$answerid = reset($args); // itemid is answer id.
|
$answerid = reset($args); // itemid is answer id.
|
||||||
$response = $this->get_response($qa);
|
$response = $this->get_response($qa);
|
||||||
|
@ -120,6 +124,13 @@ abstract class qtype_multichoice_base extends question_graded_automatically {
|
||||||
$args, $forcedownload);
|
$args, $forcedownload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function make_html_inline($html) {
|
||||||
|
$html = preg_replace('~\s*<p>\s*~', '', $html);
|
||||||
|
$html = preg_replace('~\s*</p>\s*~', '<br />', $html);
|
||||||
|
$html = preg_replace('~<br />$~', '', $html);
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class qtype_multichoice extends question_type {
|
||||||
$maxfraction = -1;
|
$maxfraction = -1;
|
||||||
$answers = array();
|
$answers = array();
|
||||||
foreach ($question->answer as $key => $answerdata) {
|
foreach ($question->answer as $key => $answerdata) {
|
||||||
if ($answerdata == '') {
|
if (trim($answerdata['text']) == '') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,16 +80,10 @@ class qtype_multichoice extends question_type {
|
||||||
$answer->id = $DB->insert_record('question_answers', $answer);
|
$answer->id = $DB->insert_record('question_answers', $answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($answerdata)) {
|
// Doing an import
|
||||||
// Doing an import
|
$answer->answer = $this->import_or_save_files($answerdata,
|
||||||
$answer->answer = $this->import_or_save_files($answerdata,
|
$context, 'question', 'answer', $answer->id);
|
||||||
$context, 'question', 'answer', $answer->id);
|
$answer->answerformat = $answerdata['format'];
|
||||||
$answer->answerformat = $answerdata['format'];
|
|
||||||
} else {
|
|
||||||
// Saving the form
|
|
||||||
$answer->answer = $answerdata;
|
|
||||||
$answer->answerformat = FORMAT_HTML;
|
|
||||||
}
|
|
||||||
$answer->fraction = $question->fraction[$key];
|
$answer->fraction = $question->fraction[$key];
|
||||||
$answer->feedback = $this->import_or_save_files($question->feedback[$key],
|
$answer->feedback = $this->import_or_save_files($question->feedback[$key],
|
||||||
$context, 'question', 'answerfeedback', $answer->id);
|
$context, 'question', 'answerfeedback', $answer->id);
|
||||||
|
@ -177,7 +171,7 @@ class qtype_multichoice extends question_type {
|
||||||
}
|
}
|
||||||
$this->initialise_combined_feedback($question, $questiondata, true);
|
$this->initialise_combined_feedback($question, $questiondata, true);
|
||||||
|
|
||||||
$this->initialise_question_answers($question, $questiondata);
|
$this->initialise_question_answers($question, $questiondata, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete_question($questionid, $contextid) {
|
public function delete_question($questionid, $contextid) {
|
||||||
|
@ -200,8 +194,9 @@ class qtype_multichoice extends question_type {
|
||||||
$responses = array();
|
$responses = array();
|
||||||
|
|
||||||
foreach ($questiondata->options->answers as $aid => $answer) {
|
foreach ($questiondata->options->answers as $aid => $answer) {
|
||||||
$responses[$aid] = new question_possible_response($answer->answer,
|
$responses[$aid] = new question_possible_response(html_to_text(format_text(
|
||||||
$answer->fraction);
|
$answer->answer, $answer->answerformat, array('noclean' => true)),
|
||||||
|
0, false), $answer->fraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
$responses[null] = question_possible_response::no_response();
|
$responses[null] = question_possible_response::no_response();
|
||||||
|
@ -211,7 +206,9 @@ class qtype_multichoice extends question_type {
|
||||||
|
|
||||||
foreach ($questiondata->options->answers as $aid => $answer) {
|
foreach ($questiondata->options->answers as $aid => $answer) {
|
||||||
$parts[$aid] = array($aid =>
|
$parts[$aid] = array($aid =>
|
||||||
new question_possible_response($answer->answer, $answer->fraction));
|
new question_possible_response(html_to_text(format_text(
|
||||||
|
$answer->answer, $answer->answerformat, array('noclean' => true)),
|
||||||
|
0, false), $answer->fraction));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $parts;
|
return $parts;
|
||||||
|
|
|
@ -94,8 +94,9 @@ abstract class qtype_multichoice_renderer_base extends qtype_with_combined_feedb
|
||||||
$radiobuttons[] = $hidden . html_writer::empty_tag('input', $inputattributes) .
|
$radiobuttons[] = $hidden . html_writer::empty_tag('input', $inputattributes) .
|
||||||
html_writer::tag('label',
|
html_writer::tag('label',
|
||||||
$this->number_in_style($value, $question->answernumbering) .
|
$this->number_in_style($value, $question->answernumbering) .
|
||||||
$question->format_text($ans->answer, $ans->answerformat,
|
$question->make_html_inline($question->format_text(
|
||||||
$qa, 'question', 'answer', $ansid),
|
$ans->answer, $ans->answerformat,
|
||||||
|
$qa, 'question', 'answer', $ansid)),
|
||||||
array('for' => $inputattributes['id']));
|
array('for' => $inputattributes['id']));
|
||||||
|
|
||||||
// $options->suppresschoicefeedback is a hack specific to the
|
// $options->suppresschoicefeedback is a hack specific to the
|
||||||
|
@ -104,8 +105,9 @@ abstract class qtype_multichoice_renderer_base extends qtype_with_combined_feedb
|
||||||
if ($options->feedback && empty($options->suppresschoicefeedback) &&
|
if ($options->feedback && empty($options->suppresschoicefeedback) &&
|
||||||
$isselected && trim($ans->feedback)) {
|
$isselected && trim($ans->feedback)) {
|
||||||
$feedback[] = html_writer::tag('div',
|
$feedback[] = html_writer::tag('div',
|
||||||
$question->format_text($ans->feedback, $ans->feedbackformat,
|
$question->make_html_inline($question->format_text(
|
||||||
$qa, 'question', 'answerfeedback', $ansid),
|
$ans->feedback, $ans->feedbackformat,
|
||||||
|
$qa, 'question', 'answerfeedback', $ansid)),
|
||||||
array('class' => 'specificfeedback'));
|
array('class' => 'specificfeedback'));
|
||||||
} else {
|
} else {
|
||||||
$feedback[] = '';
|
$feedback[] = '';
|
||||||
|
|
|
@ -135,6 +135,18 @@ class qtype_multichoice_single_question_test extends UnitTestCase {
|
||||||
$mc->id => question_classified_response::no_response(),
|
$mc->id => question_classified_response::no_response(),
|
||||||
), $mc->classify_response(array()));
|
), $mc->classify_response(array()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_make_html_inline() {
|
||||||
|
$mc = test_question_maker::make_a_multichoice_single_question();
|
||||||
|
$this->assertEqual('Frog', $mc->make_html_inline('<p>Frog</p>'));
|
||||||
|
$this->assertEqual('Frog<br />Toad', $mc->make_html_inline("<p>Frog</p>\n<p>Toad</p>"));
|
||||||
|
$this->assertEqual('<img src="http://example.com/pic.png" alt="Graph" />',
|
||||||
|
$mc->make_html_inline(
|
||||||
|
'<p><img src="http://example.com/pic.png" alt="Graph" /></p>'));
|
||||||
|
$this->assertEqual("Frog<br />XXX <img src='http://example.com/pic.png' alt='Graph' />",
|
||||||
|
$mc->make_html_inline(" <p> Frog </p> \n\r
|
||||||
|
<p> XXX <img src='http://example.com/pic.png' alt='Graph' /> </p> "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,10 @@ class qtype_multichoice_test extends UnitTestCase {
|
||||||
$q = new stdClass();
|
$q = new stdClass();
|
||||||
$q->id = 1;
|
$q->id = 1;
|
||||||
$q->options->single = true;
|
$q->options->single = true;
|
||||||
$q->options->answers[1] = (object) array('answer' => 'frog', 'fraction' => 1);
|
$q->options->answers[1] = (object) array('answer' => 'frog',
|
||||||
$q->options->answers[2] = (object) array('answer' => 'toad', 'fraction' => 0);
|
'answerformat' => FORMAT_HTML, 'fraction' => 1);
|
||||||
|
$q->options->answers[2] = (object) array('answer' => 'toad',
|
||||||
|
'answerformat' => FORMAT_HTML, 'fraction' => 0);
|
||||||
|
|
||||||
return $q;
|
return $q;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
.que.multichoice .answer .specificfeedback {
|
.que.multichoice .answer .specificfeedback {
|
||||||
display: inline;
|
|
||||||
padding: 0 0.7em;
|
padding: 0 0.7em;
|
||||||
background: #FFF3BF;
|
background: #FFF3BF;
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,9 +298,7 @@ abstract class question_definition {
|
||||||
* @return string the equivalent plain text.
|
* @return string the equivalent plain text.
|
||||||
*/
|
*/
|
||||||
public function html_to_text($text, $format) {
|
public function html_to_text($text, $format) {
|
||||||
$formatoptions = new stdClass();
|
return html_to_text(format_text($text, $format, array('noclean' => true)), 0, false);
|
||||||
$formatoptions->noclean = true;
|
|
||||||
return html_to_text(format_text($text, $format, $formatoptions), 0, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the result of applying {@link format_text()} to the question text. */
|
/** @return the result of applying {@link format_text()} to the question text. */
|
||||||
|
|
|
@ -751,8 +751,14 @@ class question_type {
|
||||||
* Initialise question_definition::answers field.
|
* Initialise question_definition::answers field.
|
||||||
* @param question_definition $question the question_definition we are creating.
|
* @param question_definition $question the question_definition we are creating.
|
||||||
* @param object $questiondata the question data loaded from the database.
|
* @param object $questiondata the question data loaded from the database.
|
||||||
|
* @param bool $forceplaintextanswers most qtypes assume that answers are
|
||||||
|
* FORMAT_PLAIN, and dont use the answerformat DB column (it contains
|
||||||
|
* the default 0 = FORMAT_MOODLE). Therefore, by default this method
|
||||||
|
* ingores answerformat. Pass false here to use answerformat. For example
|
||||||
|
* multichoice does this.
|
||||||
*/
|
*/
|
||||||
protected function initialise_question_answers(question_definition $question, $questiondata) {
|
protected function initialise_question_answers(question_definition $question,
|
||||||
|
$questiondata, $forceplaintextanswers = true) {
|
||||||
$question->answers = array();
|
$question->answers = array();
|
||||||
if (empty($questiondata->options->answers)) {
|
if (empty($questiondata->options->answers)) {
|
||||||
return;
|
return;
|
||||||
|
@ -760,6 +766,9 @@ class question_type {
|
||||||
foreach ($questiondata->options->answers as $a) {
|
foreach ($questiondata->options->answers as $a) {
|
||||||
$question->answers[$a->id] = new question_answer($a->id, $a->answer,
|
$question->answers[$a->id] = new question_answer($a->id, $a->answer,
|
||||||
$a->fraction, $a->feedback, $a->feedbackformat);
|
$a->fraction, $a->feedback, $a->feedbackformat);
|
||||||
|
if (!$forceplaintextanswers) {
|
||||||
|
$question->answers[$a->id]->answerformat = $a->answerformat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue