mirror of
https://github.com/moodle/moodle.git
synced 2025-03-22 00:20:37 +01:00
MDL-79863 qtype_ordering: qtype_ordering allow images in backup/restore of ordering questions - thanks vadimonus \!
This commit is contained in:
parent
df832e8340
commit
ef225b4c69
@ -17,8 +17,8 @@
|
||||
<FIELD NAME="partiallycorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="partiallycorrectfeedback"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_ordering" NEXT="questionid"/>
|
||||
<KEY NAME="qtypordeopti_que_uix" TYPE="foreign-unique" FIELDS="questionid" REFTABLE="question" REFFIELDS="id"/>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_ordering" NEXT="question"/>
|
||||
<KEY NAME="question" TYPE="foreign-unique" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
|
@ -44,10 +44,6 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
const NUM_ANS_MIN = 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
|
||||
*/
|
||||
@ -113,13 +109,8 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$options[$name] = array('expanded' => true);
|
||||
|
||||
$name = 'answer';
|
||||
if (isset($this->question->id)) {
|
||||
$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.'removeitem', get_string('removeitem', $plugin));
|
||||
} else {
|
||||
$elements[] = $mform->createElement('textarea', $name, $label, $this->get_editor_attributes());
|
||||
}
|
||||
$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;'));
|
||||
$options[$name] = array('type' => PARAM_RAW);
|
||||
|
||||
$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);
|
||||
|
||||
// feedback
|
||||
$this->add_ordering_feedback_fields(true);
|
||||
$this->add_ordering_feedback_fields(false);
|
||||
|
||||
// interactive
|
||||
$this->add_ordering_interactive_settings(true, true);
|
||||
$this->add_ordering_interactive_settings(false, false);
|
||||
}
|
||||
|
||||
protected function get_answer_repeats($question) {
|
||||
@ -198,6 +189,8 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$ids = array();
|
||||
}
|
||||
|
||||
$defaultanswerformat = get_config('qtype_ordering', 'defaultanswerformat');
|
||||
|
||||
for ($i=0; $i<$repeats; $i++) {
|
||||
|
||||
$editor = $name.'['.$i.']';
|
||||
@ -219,12 +212,12 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
|
||||
// remove HTML editor, if necessary
|
||||
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
|
||||
} else if ($id) {
|
||||
$format = $this->question->options->answers[$id]->answerformat;
|
||||
} 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 !!
|
||||
@ -256,6 +249,7 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
|
||||
// feedback
|
||||
$question = $this->data_preprocessing_ordering_feedback($question);
|
||||
$question = $this->data_preprocessing_hints($question, false, false);
|
||||
|
||||
// answers and fractions
|
||||
$question->answer = array();
|
||||
@ -267,6 +261,7 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$answerids = array_keys($question->options->answers);
|
||||
}
|
||||
|
||||
$defaultanswerformat = get_config('qtype_ordering', 'defaultanswerformat');
|
||||
$repeats = $this->get_answer_repeats($question);
|
||||
for ($i=0; $i<$repeats; $i++) {
|
||||
|
||||
@ -274,7 +269,7 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$answer = $question->options->answers[$answerid];
|
||||
} else {
|
||||
$answer = (object)array('answer' => '',
|
||||
'answerformat' => FORMAT_MOODLE);
|
||||
'answerformat' => $defaultanswerformat);
|
||||
$answerid = 0;
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,16 @@ $string['pluginnameadding'] = 'Adding an Ordering question';
|
||||
$string['pluginnameediting'] = 'Editing an Ordering question';
|
||||
$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['addmoreanswers'] = 'Add {$a} more items';
|
||||
$string['allornothing'] = 'All or nothing';
|
||||
$string['answer'] = 'Item text';
|
||||
$string['answerheader'] = 'Draggable item {no}';
|
||||
$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['gradedetails'] = 'Grade details';
|
||||
$string['gradingtype'] = 'Grading type';
|
||||
|
@ -150,16 +150,12 @@ class qtype_ordering extends question_type {
|
||||
foreach ($question->answer as $i => $answer) {
|
||||
|
||||
// extract $answer fields
|
||||
if (is_array($answer)) {
|
||||
// editor
|
||||
$answertext = $answer['text'];
|
||||
$answerformat = $answer['format'];
|
||||
$answertext = $answer['text'];
|
||||
$answerformat = $answer['format'];
|
||||
if (!empty($answer['itemid'])) {
|
||||
$answeritemid = $answer['itemid'];
|
||||
} else {
|
||||
// textarea
|
||||
$answertext = $answer;
|
||||
$answerformat = FORMAT_MOODLE;
|
||||
$answeritemid = 0; // i.e. no editor
|
||||
$answeritemid = null;
|
||||
}
|
||||
|
||||
// reduce simple <p>...</p> to plain text
|
||||
@ -218,6 +214,7 @@ class qtype_ordering extends question_type {
|
||||
'gradingtype' => $question->gradingtype
|
||||
);
|
||||
$options = $this->save_ordering_feedback_helper($options, $question, $context, true);
|
||||
$this->save_hints($question, false);
|
||||
|
||||
// add/update $options for this ordering question
|
||||
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;
|
||||
}
|
||||
|
||||
//parent::get_question_options($question);
|
||||
parent::get_question_options($question);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -549,13 +546,16 @@ class qtype_ordering extends question_type {
|
||||
$output .= " <selecttype>$selecttype</selecttype>\n";
|
||||
$output .= " <selectcount>$selectcount</selectcount>\n";
|
||||
$output .= " <gradingtype>$gradingtype</gradingtype>\n";
|
||||
$output .= $format->write_combined_feedback($question->options, $question->id, $question->contextid);
|
||||
|
||||
foreach($question->options->answers as $answer) {
|
||||
$output .= ' <answer fraction="'.$answer->fraction.'" '.$format->format($answer->answerformat).">\n";
|
||||
$output .= $format->writetext($answer->answer, 3);
|
||||
$output .= $format->write_files($answer->answerfiles);
|
||||
if ($feedback = trim($answer->feedback)) { // usually there is no feedback
|
||||
$output .= ' <feedback '.$format->format($answer->feedbackformat).">\n";
|
||||
$output .= $format->writetext($answer->feedback, 4);
|
||||
$output .= $format->write_files($answer->feedbackfiles);
|
||||
$output .= " </feedback>\n";
|
||||
}
|
||||
$output .= " </answer>\n";
|
||||
@ -614,21 +614,19 @@ class qtype_ordering extends question_type {
|
||||
|
||||
$i = 0;
|
||||
while ($answer = $format->getpath($data, array('#', 'answer', $i), '')) {
|
||||
if ($text = $format->getpath($answer, array('#', 'text', 0, '#'), '')) {
|
||||
$newquestion->answer[] = $text;
|
||||
$answerformat = $format->getpath($answer, array('@', 'format'), 'moodle_auto_format');
|
||||
$newquestion->answerformat[] = $format->trans_format($answerformat);
|
||||
$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);
|
||||
}
|
||||
$ans = $format->import_answer($answer, true, $format->get_format($newquestion->questiontextformat));
|
||||
$newquestion->answer[$i] = $ans->answer;
|
||||
$newquestion->fraction[$i] = 1; // will be reset later in save_question_options()
|
||||
$newquestion->feedback[$i] = $ans->feedback;
|
||||
$i++;
|
||||
}
|
||||
|
||||
$format->import_combined_feedback($newquestion, $data, false);
|
||||
// check that the required feedback fields exist
|
||||
$this->check_ordering_combined_feedback($newquestion);
|
||||
|
||||
$format->import_hints($newquestion, $data, false);
|
||||
|
||||
return $newquestion;
|
||||
}
|
||||
|
||||
|
@ -31,5 +31,5 @@ $plugin->cron = 0;
|
||||
$plugin->component = 'qtype_ordering';
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
$plugin->requires = 2010112400; // Moodle 2.0
|
||||
$plugin->version = 2016042750;
|
||||
$plugin->release = '2016-04-27 (50)';
|
||||
$plugin->version = 2016050251;
|
||||
$plugin->release = '2016-05-02 (51)';
|
||||
|
Loading…
x
Reference in New Issue
Block a user