diff --git a/question/type/ddmarker/edit_ddmarker_form.php b/question/type/ddmarker/edit_ddmarker_form.php index a020313ccef..bbc4845b0ee 100644 --- a/question/type/ddmarker/edit_ddmarker_form.php +++ b/question/type/ddmarker/edit_ddmarker_form.php @@ -136,7 +136,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { $repeated[] = $mform->createElement('checkbox', 'hintshownumcorrect', get_string('options', 'question'), get_string('shownumpartscorrect', 'question')); - $repeated[] = $mform->createElement('checkbox', 'hintstatewhichincorrect', + $repeated[] = $mform->createElement('checkbox', 'hintoptions', '', get_string('stateincorrectlyplaced', 'qtype_ddmarker')); $repeated[] = $mform->createElement('checkbox', 'hintclearwrong', @@ -198,7 +198,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { $question->hintoptions = array(); foreach ($question->hints as $hint) { - $question->hintstatewhichincorrect[] = $hint->options; + $question->hintoptions[] = $hint->options; } return $question; diff --git a/question/type/ddmarker/questiontype.php b/question/type/ddmarker/questiontype.php index e11938e8924..7d50dfe38b5 100644 --- a/question/type/ddmarker/questiontype.php +++ b/question/type/ddmarker/questiontype.php @@ -192,7 +192,7 @@ class qtype_ddmarker extends qtype_ddtoimage_base { if ($withparts) { $clearwrong = !empty($formdata->hintclearwrong[$i]); $shownumcorrect = !empty($formdata->hintshownumcorrect[$i]); - $statewhichincorrect = !empty($formdata->hintstatewhichincorrect[$i]); + $statewhichincorrect = !empty($formdata->hintoptions[$i]); } if (empty($formdata->hint[$i]['text']) && empty($clearwrong) && @@ -271,4 +271,92 @@ class qtype_ddmarker extends qtype_ddtoimage_base { $this->delete_files_in_combined_feedback($questionid, $contextid); } + public function export_to_xml($question, qformat_xml $format, $extra = null) { + $fs = get_file_storage(); + $contextid = $question->contextid; + $output = ''; + + if ($question->options->shuffleanswers) { + $output .= " \n"; + } + if ($question->options->showmisplaced) { + $output .= " \n"; + } + $output .= $format->write_combined_feedback($question->options, + $question->id, + $question->contextid); + $files = $fs->get_area_files($contextid, 'qtype_ddmarker', 'bgimage', $question->id); + $output .= " ".$this->write_files($files, 2)."\n";; + + foreach ($question->options->drags as $drag) { + $files = + $fs->get_area_files($contextid, 'qtype_ddmarker', 'dragimage', $drag->id); + $output .= " \n"; + $output .= " {$drag->no}\n"; + $output .= $format->writetext($drag->label, 3)."\n"; + if ($drag->infinite) { + $output .= " \n"; + } + $output .= " \n"; + } + foreach ($question->options->drops as $drop) { + $output .= " \n"; + $output .= " {$drop->no}\n"; + $output .= " {$drop->shape}\n"; + $output .= " {$drop->coords}\n"; + $output .= " {$drop->choice}\n"; + $output .= " \n"; + } + + return $output; + } + + public function import_from_xml($data, $question, qformat_xml $format, $extra=null) { + if (!isset($data['@']['type']) || $data['@']['type'] != 'ddmarker') { + return false; + } + + $question = $format->import_headers($data); + $question->qtype = 'ddmarker'; + + $question->shuffleanswers = array_key_exists('shuffleanswers', + $format->getpath($data, array('#'), array())); + $question->showmisplaced = array_key_exists('showmisplaced', + $format->getpath($data, array('#'), array())); + + $filexml = $format->getpath($data, array('#', 'file'), array()); + $question->bgimage = $this->import_files_to_draft_file_area($format, $filexml); + $drags = $data['#']['drag']; + $question->drags = array(); + + foreach ($drags as $dragxml) { + $dragno = $format->getpath($dragxml, array('#', 'no', 0, '#'), 0); + $dragindex = $dragno -1; + $question->drags[$dragindex] = array(); + $question->drags[$dragindex]['label'] = + $format->getpath($dragxml, array('#', 'text', 0, '#'), '', true); + $question->drags[$dragindex]['infinite'] = array_key_exists('infinite', $dragxml['#']); + + } + + $drops = $data['#']['drop']; + $question->drops = array(); + foreach ($drops as $dropxml) { + $dropno = $format->getpath($dropxml, array('#', 'no', 0, '#'), 0); + $dropindex = $dropno -1; + $question->drops[$dropindex] = array(); + $question->drops[$dropindex]['choice'] = + $format->getpath($dropxml, array('#', 'choice', 0, '#'), 0); + $question->drops[$dropindex]['shape'] = + $format->getpath($dropxml, array('#', 'shape', 0, '#'), ''); + $question->drops[$dropindex]['coords'] = + $format->getpath($dropxml, array('#', 'coords', 0, '#'), ''); + } + + $format->import_combined_feedback($question, $data, true); + $format->import_hints($question, $data, true, true); + + return $question; + } + }