From ef225b4c697e21f768138a407f77dff522824e7d Mon Sep 17 00:00:00 2001 From: Gordon Bateson Date: Mon, 2 May 2016 08:00:39 +0900 Subject: [PATCH] MDL-79863 qtype_ordering: qtype_ordering allow images in backup/restore of ordering questions - thanks vadimonus \! --- question/type/ordering/db/install.xml | 4 +-- question/type/ordering/edit_ordering_form.php | 27 ++++++--------- .../type/ordering/lang/en/qtype_ordering.php | 4 +++ question/type/ordering/questiontype.php | 34 +++++++++---------- question/type/ordering/version.php | 4 +-- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/question/type/ordering/db/install.xml b/question/type/ordering/db/install.xml index 82bdf1432e8..d1126172d4a 100644 --- a/question/type/ordering/db/install.xml +++ b/question/type/ordering/db/install.xml @@ -17,8 +17,8 @@ - - + + diff --git a/question/type/ordering/edit_ordering_form.php b/question/type/ordering/edit_ordering_form.php index b5e07a16a22..6dc772ace2d 100644 --- a/question/type/ordering/edit_ordering_form.php +++ b/question/type/ordering/edit_ordering_form.php @@ -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; } diff --git a/question/type/ordering/lang/en/qtype_ordering.php b/question/type/ordering/lang/en/qtype_ordering.php index ded811e55ec..e6a6ecae5e3 100644 --- a/question/type/ordering/lang/en/qtype_ordering.php +++ b/question/type/ordering/lang/en/qtype_ordering.php @@ -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'; diff --git a/question/type/ordering/questiontype.php b/question/type/ordering/questiontype.php index 824ec0b6a55..7a7375476ca 100644 --- a/question/type/ordering/questiontype.php +++ b/question/type/ordering/questiontype.php @@ -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

...

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\n"; $output .= " $selectcount\n"; $output .= " $gradingtype\n"; + $output .= $format->write_combined_feedback($question->options, $question->id, $question->contextid); foreach($question->options->answers as $answer) { $output .= ' 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 .= ' format($answer->feedbackformat).">\n"; $output .= $format->writetext($answer->feedback, 4); + $output .= $format->write_files($answer->feedbackfiles); $output .= " \n"; } $output .= " \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; } diff --git a/question/type/ordering/version.php b/question/type/ordering/version.php index 28746156389..3e893a2d0c4 100644 --- a/question/type/ordering/version.php +++ b/question/type/ordering/version.php @@ -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)';