MDL-79863 qtype_ordering: qtype_ordering allow images in backup/restore of ordering questions - thanks vadimonus \!

This commit is contained in:
Gordon Bateson 2016-05-02 08:00:39 +09:00 committed by Mathew May
parent df832e8340
commit ef225b4c69
5 changed files with 35 additions and 38 deletions

View file

@ -17,8 +17,8 @@
<FIELD NAME="partiallycorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="partiallycorrectfeedback"/> <FIELD NAME="partiallycorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="partiallycorrectfeedback"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_ordering" NEXT="questionid"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_ordering" NEXT="question"/>
<KEY NAME="qtypordeopti_que_uix" TYPE="foreign-unique" FIELDS="questionid" REFTABLE="question" REFFIELDS="id"/> <KEY NAME="question" TYPE="foreign-unique" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS> </KEYS>
</TABLE> </TABLE>
</TABLES> </TABLES>

View file

@ -44,10 +44,6 @@ class qtype_ordering_edit_form extends question_edit_form {
const NUM_ANS_MIN = 3; const NUM_ANS_MIN = 3;
const NUM_ANS_ADD = 3; const NUM_ANS_ADD = 3;
// this functionality is currently disabled
// because it is not fully functional
protected $use_editor_for_answers = true;
/** /**
* unique name for this question type * unique name for this question type
*/ */
@ -113,13 +109,8 @@ class qtype_ordering_edit_form extends question_edit_form {
$options[$name] = array('expanded' => true); $options[$name] = array('expanded' => true);
$name = 'answer'; $name = 'answer';
if (isset($this->question->id)) { $elements[] = $mform->createElement('editor', $name, $label, $this->get_editor_attributes(), $this->get_editor_options());
$elements[] = $mform->createElement('editor', $name, $label, $this->get_editor_attributes(), $this->get_editor_options()); $elements[] = $mform->createElement('submit', $name.'removeeditor', get_string('removeeditor', $plugin), array('onclick' => 'skipClientValidation = true;'));
$elements[] = $mform->createElement('submit', $name.'removeeditor', get_string('removeeditor', $plugin), array('onclick' => 'skipClientValidation = true;'));
//$elements[] = $mform->createElement('submit', $name.'removeitem', get_string('removeitem', $plugin));
} else {
$elements[] = $mform->createElement('textarea', $name, $label, $this->get_editor_attributes());
}
$options[$name] = array('type' => PARAM_RAW); $options[$name] = array('type' => PARAM_RAW);
$repeats = $this->get_answer_repeats($this->question); $repeats = $this->get_answer_repeats($this->question);
@ -134,10 +125,10 @@ class qtype_ordering_edit_form extends question_edit_form {
$this->adjust_html_editors($mform, $name, $repeats); $this->adjust_html_editors($mform, $name, $repeats);
// feedback // feedback
$this->add_ordering_feedback_fields(true); $this->add_ordering_feedback_fields(false);
// interactive // interactive
$this->add_ordering_interactive_settings(true, true); $this->add_ordering_interactive_settings(false, false);
} }
protected function get_answer_repeats($question) { protected function get_answer_repeats($question) {
@ -198,6 +189,8 @@ class qtype_ordering_edit_form extends question_edit_form {
$ids = array(); $ids = array();
} }
$defaultanswerformat = get_config('qtype_ordering', 'defaultanswerformat');
for ($i=0; $i<$repeats; $i++) { for ($i=0; $i<$repeats; $i++) {
$editor = $name.'['.$i.']'; $editor = $name.'['.$i.']';
@ -219,12 +212,12 @@ class qtype_ordering_edit_form extends question_edit_form {
// remove HTML editor, if necessary // remove HTML editor, if necessary
if (optional_param($newname, 0, PARAM_RAW)) { if (optional_param($newname, 0, PARAM_RAW)) {
$format = $this->reset_editor_format($editor); $format = $this->reset_editor_format($editor, FORMAT_MOODLE);
$_POST['answer'][$i]['format'] = $format; // overwrite incoming data $_POST['answer'][$i]['format'] = $format; // overwrite incoming data
} else if ($id) { } else if ($id) {
$format = $this->question->options->answers[$id]->answerformat; $format = $this->question->options->answers[$id]->answerformat;
} else { } else {
$format = $this->reset_editor_format($editor); $format = $this->reset_editor_format($editor, $defaultanswerformat);
} }
// check we have a submit button - it should always be there !! // check we have a submit button - it should always be there !!
@ -256,6 +249,7 @@ class qtype_ordering_edit_form extends question_edit_form {
// feedback // feedback
$question = $this->data_preprocessing_ordering_feedback($question); $question = $this->data_preprocessing_ordering_feedback($question);
$question = $this->data_preprocessing_hints($question, false, false);
// answers and fractions // answers and fractions
$question->answer = array(); $question->answer = array();
@ -267,6 +261,7 @@ class qtype_ordering_edit_form extends question_edit_form {
$answerids = array_keys($question->options->answers); $answerids = array_keys($question->options->answers);
} }
$defaultanswerformat = get_config('qtype_ordering', 'defaultanswerformat');
$repeats = $this->get_answer_repeats($question); $repeats = $this->get_answer_repeats($question);
for ($i=0; $i<$repeats; $i++) { for ($i=0; $i<$repeats; $i++) {
@ -274,7 +269,7 @@ class qtype_ordering_edit_form extends question_edit_form {
$answer = $question->options->answers[$answerid]; $answer = $question->options->answers[$answerid];
} else { } else {
$answer = (object)array('answer' => '', $answer = (object)array('answer' => '',
'answerformat' => FORMAT_MOODLE); 'answerformat' => $defaultanswerformat);
$answerid = 0; $answerid = 0;
} }

View file

@ -15,12 +15,16 @@ $string['pluginnameadding'] = 'Adding an Ordering question';
$string['pluginnameediting'] = 'Editing an Ordering question'; $string['pluginnameediting'] = 'Editing an Ordering question';
$string['pluginnamesummary'] = 'Put jumbled items into a meaningful order.'; $string['pluginnamesummary'] = 'Put jumbled items into a meaningful order.';
$string['editingordering'] = 'Editing ordering question';
$string['addingordering'] = 'Adding a Ordering question';
$string['absoluteposition'] = 'Absolute position'; $string['absoluteposition'] = 'Absolute position';
$string['addmoreanswers'] = 'Add {$a} more items'; $string['addmoreanswers'] = 'Add {$a} more items';
$string['allornothing'] = 'All or nothing'; $string['allornothing'] = 'All or nothing';
$string['answer'] = 'Item text'; $string['answer'] = 'Item text';
$string['answerheader'] = 'Draggable item {no}'; $string['answerheader'] = 'Draggable item {no}';
$string['correctorder'] = 'The correct order for these items is as follows:'; $string['correctorder'] = 'The correct order for these items is as follows:';
$string['defaultanswerformat'] = 'Default answer format';
$string['defaultquestionname'] = 'Drag the following items into the correct order.'; $string['defaultquestionname'] = 'Drag the following items into the correct order.';
$string['gradedetails'] = 'Grade details'; $string['gradedetails'] = 'Grade details';
$string['gradingtype'] = 'Grading type'; $string['gradingtype'] = 'Grading type';

View file

@ -150,16 +150,12 @@ class qtype_ordering extends question_type {
foreach ($question->answer as $i => $answer) { foreach ($question->answer as $i => $answer) {
// extract $answer fields // extract $answer fields
if (is_array($answer)) { $answertext = $answer['text'];
// editor $answerformat = $answer['format'];
$answertext = $answer['text']; if (!empty($answer['itemid'])) {
$answerformat = $answer['format'];
$answeritemid = $answer['itemid']; $answeritemid = $answer['itemid'];
} else { } else {
// textarea $answeritemid = null;
$answertext = $answer;
$answerformat = FORMAT_MOODLE;
$answeritemid = 0; // i.e. no editor
} }
// reduce simple <p>...</p> to plain text // reduce simple <p>...</p> to plain text
@ -218,6 +214,7 @@ class qtype_ordering extends question_type {
'gradingtype' => $question->gradingtype 'gradingtype' => $question->gradingtype
); );
$options = $this->save_ordering_feedback_helper($options, $question, $context, true); $options = $this->save_ordering_feedback_helper($options, $question, $context, true);
$this->save_hints($question, false);
// add/update $options for this ordering question // add/update $options for this ordering question
if ($options->id = $DB->get_field('qtype_ordering_options', 'id', array('questionid' => $question->id))) { if ($options->id = $DB->get_field('qtype_ordering_options', 'id', array('questionid' => $question->id))) {
@ -318,7 +315,7 @@ class qtype_ordering extends question_type {
return false; return false;
} }
//parent::get_question_options($question); parent::get_question_options($question);
return true; return true;
} }
@ -549,13 +546,16 @@ class qtype_ordering extends question_type {
$output .= " <selecttype>$selecttype</selecttype>\n"; $output .= " <selecttype>$selecttype</selecttype>\n";
$output .= " <selectcount>$selectcount</selectcount>\n"; $output .= " <selectcount>$selectcount</selectcount>\n";
$output .= " <gradingtype>$gradingtype</gradingtype>\n"; $output .= " <gradingtype>$gradingtype</gradingtype>\n";
$output .= $format->write_combined_feedback($question->options, $question->id, $question->contextid);
foreach($question->options->answers as $answer) { foreach($question->options->answers as $answer) {
$output .= ' <answer fraction="'.$answer->fraction.'" '.$format->format($answer->answerformat).">\n"; $output .= ' <answer fraction="'.$answer->fraction.'" '.$format->format($answer->answerformat).">\n";
$output .= $format->writetext($answer->answer, 3); $output .= $format->writetext($answer->answer, 3);
$output .= $format->write_files($answer->answerfiles);
if ($feedback = trim($answer->feedback)) { // usually there is no feedback if ($feedback = trim($answer->feedback)) { // usually there is no feedback
$output .= ' <feedback '.$format->format($answer->feedbackformat).">\n"; $output .= ' <feedback '.$format->format($answer->feedbackformat).">\n";
$output .= $format->writetext($answer->feedback, 4); $output .= $format->writetext($answer->feedback, 4);
$output .= $format->write_files($answer->feedbackfiles);
$output .= " </feedback>\n"; $output .= " </feedback>\n";
} }
$output .= " </answer>\n"; $output .= " </answer>\n";
@ -614,21 +614,19 @@ class qtype_ordering extends question_type {
$i = 0; $i = 0;
while ($answer = $format->getpath($data, array('#', 'answer', $i), '')) { while ($answer = $format->getpath($data, array('#', 'answer', $i), '')) {
if ($text = $format->getpath($answer, array('#', 'text', 0, '#'), '')) { $ans = $format->import_answer($answer, true, $format->get_format($newquestion->questiontextformat));
$newquestion->answer[] = $text; $newquestion->answer[$i] = $ans->answer;
$answerformat = $format->getpath($answer, array('@', 'format'), 'moodle_auto_format'); $newquestion->fraction[$i] = 1; // will be reset later in save_question_options()
$newquestion->answerformat[] = $format->trans_format($answerformat); $newquestion->feedback[$i] = $ans->feedback;
$newquestion->fraction[] = 1; // will be reset later in save_question_options()
$newquestion->feedback[] = $format->getpath($answer, array('#', 'feedback', 0, '#', 'text', 0, '#'), '');
$feedbackformat = $format->getpath($answer, array('#', 'format', 0, '@', 'format'), 'moodle_auto_format');
$newquestion->feedbackformat[] = $format->trans_format($feedbackformat);
}
$i++; $i++;
} }
$format->import_combined_feedback($newquestion, $data, false);
// check that the required feedback fields exist // check that the required feedback fields exist
$this->check_ordering_combined_feedback($newquestion); $this->check_ordering_combined_feedback($newquestion);
$format->import_hints($newquestion, $data, false);
return $newquestion; return $newquestion;
} }

View file

@ -31,5 +31,5 @@ $plugin->cron = 0;
$plugin->component = 'qtype_ordering'; $plugin->component = 'qtype_ordering';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->requires = 2010112400; // Moodle 2.0 $plugin->requires = 2010112400; // Moodle 2.0
$plugin->version = 2016042750; $plugin->version = 2016050251;
$plugin->release = '2016-04-27 (50)'; $plugin->release = '2016-05-02 (51)';