From b5cdc3e7a72dc0d217786aed10b4821094a1078f Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Fri, 4 Nov 2011 17:49:38 +0700 Subject: [PATCH 1/5] MDL-47494 ddimageortext: NOBUG adding some drop shadow to drags --- question/type/ddimageortext/styles.css | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/question/type/ddimageortext/styles.css b/question/type/ddimageortext/styles.css index bc9365df553..95287819957 100755 --- a/question/type/ddimageortext/styles.css +++ b/question/type/ddimageortext/styles.css @@ -74,3 +74,14 @@ form.mform fieldset#previewareaheader div.draghome, form.mform fieldset#previewa *font-size:small; /* for IE */ *font:x-small; /* for IE in quirks mode */ } +form.mform fieldset#previewareaheader div.drag.yui3-dd-dragging, +.que.ddimageortext div.drag.yui3-dd-dragging { + z-index: 3; + -moz-box-shadow: 3px 3px 4px #000; + -webkit-box-shadow: 3px 3px 4px #000; + box-shadow: 3px 3px 4px #000; + /* For IE 8 */ + -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')"; + /* For IE 5.5 - 7 */ + filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000'); +} \ No newline at end of file From c56c771f9e2e2aba2acd9cdd954a7d39c3748f31 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 4 Nov 2011 12:51:47 +0000 Subject: [PATCH 2/5] MDL-47494 ddimageortext: Tweak lang strings and fix file permissions. --- question/type/ddimageortext/db/install.xml | 0 .../ddimageortext/lang/en/qtype_ddimageortext.php | 8 ++++---- question/type/ddimageortext/pix/icon.gif | Bin question/type/ddimageortext/question.php | 0 question/type/ddimageortext/questiontype.php | 0 question/type/ddimageortext/renderer.php | 0 question/type/ddimageortext/simpletest/helper.php | 0 .../type/ddimageortext/simpletest/testquestion.php | 0 .../ddimageortext/simpletest/testquestiontype.php | 0 .../ddimageortext/simpletest/testwalkthrough.php | 0 question/type/ddimageortext/styles.css | 0 question/type/ddimageortext/version.php | 0 12 files changed, 4 insertions(+), 4 deletions(-) mode change 100755 => 100644 question/type/ddimageortext/db/install.xml mode change 100755 => 100644 question/type/ddimageortext/pix/icon.gif mode change 100755 => 100644 question/type/ddimageortext/question.php mode change 100755 => 100644 question/type/ddimageortext/questiontype.php mode change 100755 => 100644 question/type/ddimageortext/renderer.php mode change 100755 => 100644 question/type/ddimageortext/simpletest/helper.php mode change 100755 => 100644 question/type/ddimageortext/simpletest/testquestion.php mode change 100755 => 100644 question/type/ddimageortext/simpletest/testquestiontype.php mode change 100755 => 100644 question/type/ddimageortext/simpletest/testwalkthrough.php mode change 100755 => 100644 question/type/ddimageortext/styles.css mode change 100755 => 100644 question/type/ddimageortext/version.php diff --git a/question/type/ddimageortext/db/install.xml b/question/type/ddimageortext/db/install.xml old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/lang/en/qtype_ddimageortext.php b/question/type/ddimageortext/lang/en/qtype_ddimageortext.php index 0a27d38865e..9f8262bf1f5 100644 --- a/question/type/ddimageortext/lang/en/qtype_ddimageortext.php +++ b/question/type/ddimageortext/lang/en/qtype_ddimageortext.php @@ -22,15 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['addingddimageortext'] = 'Adding drag and drop onto images'; +$string['addingddimageortext'] = 'Adding drag and drop onto image'; $string['addmoredropzones'] = 'Blanks for {no} More Drop Zones'; $string['addmoreimages'] = 'Blanks for {no} More Draggable Items'; $string['answer'] = 'Answer'; $string['bgimage'] = 'Background Image'; $string['correctansweris'] = 'The correct answer is: {$a}'; -$string['ddimageortext'] = 'Drag and drop onto images'; +$string['ddimageortext'] = 'Drag and drop onto image'; $string['ddimageortext_help'] = 'Select a background image file, select draggable images or enter text and define the drop zones on the background image to which they must be dragged.'; -$string['ddimageortextsummary'] = 'Images or text labels are dragged and dropped into visible drop zones on a background image.'; +$string['ddimageortextsummary'] = 'Images or text labels are dragged and dropped into drop zones on a background image.'; $string['draggableimage'] = 'Draggable image'; $string['draggableitem'] = 'Draggable item'; $string['draggableitemheader'] = 'Draggable item {$a}'; @@ -38,7 +38,7 @@ $string['draggableitemtype'] = 'Type'; $string['draggableword'] = 'Draggable text'; $string['dropzone'] = 'Drop zone {$a}'; $string['dropzoneheader'] = 'Drop zones'; -$string['editingddimageortext'] = 'Editing drag and drop onto images'; +$string['editingddimageortext'] = 'Editing drag and drop onto image'; $string['formerror_disallowedtags'] = 'You have used html tags here that are not allowed in a draggable text drag item type.'; $string['formerror_noallowedtags'] = 'No html tags are allowed in this text which is the alt text for a draggable image'; $string['formerror_noytop'] = 'You must provide a value for the y coords for the top left corner of this drop area. You can drag and drop the drop area above to set the coordinates or enter them manually here.'; diff --git a/question/type/ddimageortext/pix/icon.gif b/question/type/ddimageortext/pix/icon.gif old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/question.php b/question/type/ddimageortext/question.php old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/questiontype.php b/question/type/ddimageortext/questiontype.php old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/renderer.php b/question/type/ddimageortext/renderer.php old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/simpletest/helper.php b/question/type/ddimageortext/simpletest/helper.php old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/simpletest/testquestion.php b/question/type/ddimageortext/simpletest/testquestion.php old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/simpletest/testquestiontype.php b/question/type/ddimageortext/simpletest/testquestiontype.php old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/simpletest/testwalkthrough.php b/question/type/ddimageortext/simpletest/testwalkthrough.php old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/styles.css b/question/type/ddimageortext/styles.css old mode 100755 new mode 100644 diff --git a/question/type/ddimageortext/version.php b/question/type/ddimageortext/version.php old mode 100755 new mode 100644 From 2b3e53b36f4a78e6593163bdc66c97f382f7cc74 Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Sat, 12 Nov 2011 15:48:37 +0700 Subject: [PATCH 3/5] MDL-47494 ddimageortext: NOBUG adding comments to identify keys for key numbers in keyboard listener --- question/type/ddimageortext/yui/dd/dd.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/question/type/ddimageortext/yui/dd/dd.js b/question/type/ddimageortext/yui/dd/dd.js index faff9418b30..06b5298039d 100644 --- a/question/type/ddimageortext/yui/dd/dd.js +++ b/question/type/ddimageortext/yui/dd/dd.js @@ -439,12 +439,12 @@ YUI.add('moodle-qtype_ddimageortext-dd', function(Y) { _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress', _keys: { - '32': 'next', - '37': 'previous', - '38': 'previous', - '39': 'next', - '40': 'next', - '27': 'remove' + '32': 'next', // Space + '37': 'previous', // Left arrow + '38': 'previous', // Up arrow + '39': 'next', // Right arrow + '40': 'next', // Down arrow + '27': 'remove' // Escape }, _keyHandler: function (e, notifier) { From b9640ba51f450c10e8e39b8797ff2a828df44188 Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Fri, 18 Nov 2011 10:01:55 +0700 Subject: [PATCH 4/5] MDL-47494 ddimageortext: NOBUG moving some methods from out of the question_type base class --- question/type/ddimageortext/questiontype.php | 237 +++++++++++++++++ .../type/ddimageortext/questiontypebase.php | 248 +----------------- 2 files changed, 242 insertions(+), 243 deletions(-) diff --git a/question/type/ddimageortext/questiontype.php b/question/type/ddimageortext/questiontype.php index 34879f0e244..d5f1cec0bef 100644 --- a/question/type/ddimageortext/questiontype.php +++ b/question/type/ddimageortext/questiontype.php @@ -41,4 +41,241 @@ define('QTYPE_DDIMAGEORTEXT_DRAGIMAGE_MAXHEIGHT', 100); */ class qtype_ddimageortext extends qtype_ddtoimage_base { + protected function make_choice($dragdata) { + return new qtype_ddimageortext_drag_item($dragdata->label, $dragdata->no, + $dragdata->draggroup, $dragdata->infinite, $dragdata->id); + } + + protected function make_place($dropzonedata) { + return new qtype_ddimageortext_drop_zone($dropzonedata->label, $dropzonedata->no, + $dropzonedata->group, + $dropzonedata->xleft, $dropzonedata->ytop); + } + + protected function make_hint($hint) { + return question_hint_with_parts::load_from_record($hint); + } + + public function save_question_options($formdata) { + global $DB, $USER; + $context = $formdata->context; + + $options = $DB->get_record('qtype_ddimageortext', array('questionid' => $formdata->id)); + if (!$options) { + $options = new stdClass(); + $options->questionid = $formdata->id; + $options->correctfeedback = ''; + $options->partiallycorrectfeedback = ''; + $options->incorrectfeedback = ''; + $options->id = $DB->insert_record('qtype_ddimageortext', $options); + } + + $options->shuffleanswers = !empty($formdata->shuffleanswers); + $options = $this->save_combined_feedback_helper($options, $formdata, $context, true); + $this->save_hints($formdata, true); + $DB->update_record('qtype_ddimageortext', $options); + $DB->delete_records('qtype_ddimageortext_drops', array('questionid' => $formdata->id)); + foreach (array_keys($formdata->drops) as $dropno) { + if ($formdata->drops[$dropno]['choice'] == 0) { + continue; + } + $drop = new stdClass(); + $drop->questionid = $formdata->id; + $drop->no = $dropno + 1; + $drop->xleft = $formdata->drops[$dropno]['xleft']; + $drop->ytop = $formdata->drops[$dropno]['ytop']; + $drop->choice = $formdata->drops[$dropno]['choice']; + $drop->label = $formdata->drops[$dropno]['droplabel']; + + $DB->insert_record('qtype_ddimageortext_drops', $drop); + } + + //an array of drag no -> drag id + $olddragids = $DB->get_records_menu('qtype_ddimageortext_drags', + array('questionid' => $formdata->id), + '', 'no, id'); + foreach (array_keys($formdata->drags) as $dragno) { + $info = file_get_draft_area_info($formdata->dragitem[$dragno]); + if ($info['filecount'] > 0 || (trim($formdata->drags[$dragno]['draglabel'])!='')) { + $draftitemid = $formdata->dragitem[$dragno]; + + $drag = new stdClass(); + $drag->questionid = $formdata->id; + $drag->no = $dragno + 1; + $drag->draggroup = $formdata->drags[$dragno]['draggroup']; + $drag->infinite = empty($formdata->drags[$dragno]['infinite'])? 0 : 1; + $drag->label = $formdata->drags[$dragno]['draglabel']; + + if (isset($olddragids[$dragno +1])) { + $drag->id = $olddragids[$dragno +1]; + unset($olddragids[$dragno +1]); + $DB->update_record('qtype_ddimageortext_drags', $drag); + } else { + $drag->id = $DB->insert_record('qtype_ddimageortext_drags', $drag); + } + + if ($formdata->dragitemtype[$dragno] == 'image') { + self::constrain_image_size_in_draft_area($draftitemid, + QTYPE_DDIMAGEORTEXT_DRAGIMAGE_MAXWIDTH, + QTYPE_DDIMAGEORTEXT_DRAGIMAGE_MAXHEIGHT); + file_save_draft_area_files($draftitemid, $formdata->context->id, + 'qtype_ddimageortext', 'dragimage', $drag->id, + array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1)); + } else { + //delete any existing files for draggable text item type + $fs = get_file_storage(); + $fs->delete_area_files($formdata->context->id, 'qtype_ddimageortext', + 'dragimage', $drag->id); + } + + } + + } + if (!empty($olddragids)) { + list($sql, $params) = $DB->get_in_or_equal(array_values($olddragids)); + $DB->delete_records_select('qtype_ddimageortext_drags', "id $sql", $params); + } + + self::constrain_image_size_in_draft_area($formdata->bgimage, + QTYPE_DDIMAGEORTEXT_BGIMAGE_MAXWIDTH, + QTYPE_DDIMAGEORTEXT_BGIMAGE_MAXHEIGHT); + file_save_draft_area_files($formdata->bgimage, $formdata->context->id, + 'qtype_ddimageortext', 'bgimage', $formdata->id, + array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1)); + } + public function move_files($questionid, $oldcontextid, $newcontextid) { + global $DB; + $fs = get_file_storage(); + + parent::move_files($questionid, $oldcontextid, $newcontextid); + $fs->move_area_files_to_new_context($oldcontextid, + $newcontextid, 'qtype_ddimageortext', 'bgimage', $questionid); + $dragids = $DB->get_records_menu('qtype_ddimageortext_drags', + array('questionid' => $questionid), 'id', 'id,1'); + foreach ($dragids as $dragid => $notused) { + $fs->move_area_files_to_new_context($oldcontextid, + $newcontextid, 'qtype_ddimageortext', 'dragimage', $dragid); + } + + $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid); + } + + /** + * Delete all the files belonging to this question. + * @param int $questionid the question being deleted. + * @param int $contextid the context the question is in. + */ + + protected function delete_files($questionid, $contextid) { + global $DB; + $fs = get_file_storage(); + + parent::delete_files($questionid, $contextid); + + $dragids = $DB->get_records_menu('qtype_ddimageortext_drags', + array('questionid' => $questionid), 'id', 'id,1'); + foreach ($dragids as $dragid => $notused) { + $fs->delete_area_files($contextid, 'qtype_ddimageortext', 'dragimage', $dragid); + } + + $this->delete_files_in_combined_feedback($questionid, $contextid); + } + + + public function export_to_xml($question, $format, $extra = null) { + $fs = get_file_storage(); + $contextid = $question->contextid; + $output = ''; + + if ($question->options->shuffleanswers) { + $output .= " \n"; + } + $output .= $format->write_combined_feedback($question->options); + $output .= $format->write_hints($question); + $files = $fs->get_area_files($contextid, 'qtype_ddimageortext', 'bgimage', $question->id); + $output .= " ".$this->write_files($files, 2)."\n";; + + foreach ($question->options->drags as $drag) { + $files = + $fs->get_area_files($contextid, 'qtype_ddimageortext', 'dragimage', $drag->id); + $output .= " \n"; + $output .= " {$drag->no}\n"; + $output .= $format->writetext($drag->label, 3)."\n"; + $output .= " {$drag->draggroup}\n"; + if ($drag->infinite) { + $output .= " \n"; + } + $output .= $this->write_files($files, 3); + $output .= " \n"; + } + foreach ($question->options->drops as $drop) { + $output .= " \n"; + $output .= $format->writetext($drop->label, 3); + $output .= " {$drop->no}\n"; + $output .= " {$drop->choice}\n"; + $output .= " {$drop->xleft}\n"; + $output .= " {$drop->ytop}\n"; + $output .= " \n"; + } + + return $output; + } + + public function import_from_xml($data, $question, $format, $extra=null) { + if (!isset($data['@']['type']) || $data['@']['type'] != 'ddimageortext') { + return false; + } + + $question = $format->import_headers($data); + $question->qtype = 'ddimageortext'; + + $question->shuffleanswers = array_key_exists('shuffleanswers', + $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]['draglabel'] = + $format->getpath($dragxml, array('#', 'text', 0, '#'), '', true); + $question->drags[$dragindex]['infinite'] = array_key_exists('infinite', $dragxml['#']); + $question->drags[$dragindex]['draggroup'] = + $format->getpath($dragxml, array('#', 'draggroup', 0, '#'), 1); + $filexml = $format->getpath($dragxml, array('#', 'file'), array()); + $question->dragitem[$dragindex] = + $this->import_files_to_draft_file_area($format, $filexml); + if (count($filexml)) { + $question->dragitemtype[$dragindex] = 'image'; + } else { + $question->dragitemtype[$dragindex] = 'word'; + } + } + + $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]['droplabel'] = + $format->getpath($dropxml, array('#', 'text', 0, '#'), '', true); + $question->drops[$dropindex]['xleft'] = + $format->getpath($dropxml, array('#', 'xleft', 0, '#'), ''); + $question->drops[$dropindex]['ytop'] = + $format->getpath($dropxml, array('#', 'ytop', 0, '#'), ''); + } + + $format->import_combined_feedback($question, $data, true); + $format->import_hints($question, $data, true); + + return $question; + } + } diff --git a/question/type/ddimageortext/questiontypebase.php b/question/type/ddimageortext/questiontypebase.php index ed46a7af32f..57248c3b591 100644 --- a/question/type/ddimageortext/questiontypebase.php +++ b/question/type/ddimageortext/questiontypebase.php @@ -42,10 +42,6 @@ class qtype_ddtoimage_base extends question_type { return 'draggroup'; } - public function requires_qtypes() { - return array_merge(parent::requires_qtypes()); - } - public function get_question_options($question) { global $DB; $dbprefix = 'qtype_'.$this->name(); @@ -58,21 +54,6 @@ class qtype_ddtoimage_base extends question_type { parent::get_question_options($question); } - protected function make_choice($dragdata) { - return new qtype_ddimageortext_drag_item($dragdata->label, $dragdata->no, - $dragdata->draggroup, $dragdata->infinite, $dragdata->id); - } - - protected function make_place($dropzonedata) { - return new qtype_ddimageortext_drop_zone($dropzonedata->label, $dropzonedata->no, - $dropzonedata->group, - $dropzonedata->xleft, $dropzonedata->ytop); - } - - protected function make_hint($hint) { - return question_hint_with_parts::load_from_record($hint); - } - protected function initialise_question_instance(question_definition $question, $questiondata) { parent::initialise_question_instance($question, $questiondata); $question->shufflechoices = $questiondata->options->shuffleanswers; @@ -111,95 +92,6 @@ class qtype_ddtoimage_base extends question_type { } } - public function save_question_options($formdata) { - global $DB, $USER; - $context = $formdata->context; - - $options = $DB->get_record('qtype_ddimageortext', array('questionid' => $formdata->id)); - if (!$options) { - $options = new stdClass(); - $options->questionid = $formdata->id; - $options->correctfeedback = ''; - $options->partiallycorrectfeedback = ''; - $options->incorrectfeedback = ''; - $options->id = $DB->insert_record('qtype_ddimageortext', $options); - } - - $options->shuffleanswers = !empty($formdata->shuffleanswers); - $options = $this->save_combined_feedback_helper($options, $formdata, $context, true); - $this->save_hints($formdata, true); - $DB->update_record('qtype_ddimageortext', $options); - $DB->delete_records('qtype_ddimageortext_drops', array('questionid' => $formdata->id)); - foreach (array_keys($formdata->drops) as $dropno) { - if ($formdata->drops[$dropno]['choice'] == 0) { - continue; - } - $drop = new stdClass(); - $drop->questionid = $formdata->id; - $drop->no = $dropno + 1; - $drop->xleft = $formdata->drops[$dropno]['xleft']; - $drop->ytop = $formdata->drops[$dropno]['ytop']; - $drop->choice = $formdata->drops[$dropno]['choice']; - $drop->label = $formdata->drops[$dropno]['droplabel']; - - $DB->insert_record('qtype_ddimageortext_drops', $drop); - } - - //an array of drag no -> drag id - $olddragids = $DB->get_records_menu('qtype_ddimageortext_drags', - array('questionid' => $formdata->id), - '', 'no, id'); - foreach (array_keys($formdata->drags) as $dragno) { - $info = file_get_draft_area_info($formdata->dragitem[$dragno]); - if ($info['filecount'] > 0 || (trim($formdata->drags[$dragno]['draglabel'])!='')) { - $draftitemid = $formdata->dragitem[$dragno]; - - $drag = new stdClass(); - $drag->questionid = $formdata->id; - $drag->no = $dragno + 1; - $drag->draggroup = $formdata->drags[$dragno]['draggroup']; - $drag->infinite = empty($formdata->drags[$dragno]['infinite'])? 0 : 1; - $drag->label = $formdata->drags[$dragno]['draglabel']; - - if (isset($olddragids[$dragno +1])) { - $drag->id = $olddragids[$dragno +1]; - unset($olddragids[$dragno +1]); - $DB->update_record('qtype_ddimageortext_drags', $drag); - } else { - $drag->id = $DB->insert_record('qtype_ddimageortext_drags', $drag); - } - - if ($formdata->dragitemtype[$dragno] == 'image') { - self::constrain_image_size_in_draft_area($draftitemid, - QTYPE_DDIMAGEORTEXT_DRAGIMAGE_MAXWIDTH, - QTYPE_DDIMAGEORTEXT_DRAGIMAGE_MAXHEIGHT); - file_save_draft_area_files($draftitemid, $formdata->context->id, - 'qtype_ddimageortext', 'dragimage', $drag->id, - array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1)); - } else { - //delete any existing files for draggable text item type - $fs = get_file_storage(); - $fs->delete_area_files($formdata->context->id, 'qtype_ddimageortext', - 'dragimage', $drag->id); - } - - } - - } - if (!empty($olddragids)) { - list($sql, $params) = $DB->get_in_or_equal(array_values($olddragids)); - $DB->delete_records_select('qtype_ddimageortext_drags', "id $sql", $params); - } - - self::constrain_image_size_in_draft_area($formdata->bgimage, - QTYPE_DDIMAGEORTEXT_BGIMAGE_MAXWIDTH, - QTYPE_DDIMAGEORTEXT_BGIMAGE_MAXHEIGHT); - file_save_draft_area_files($formdata->bgimage, $formdata->context->id, - 'qtype_ddimageortext', 'bgimage', $formdata->id, - array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1)); - } - - public static function constrain_image_size_in_draft_area($draftitemid, $maxwidth, $maxheight) { global $USER; $usercontext = get_context_instance(CONTEXT_USER, $USER->id); @@ -243,139 +135,7 @@ class qtype_ddtoimage_base extends question_type { } } } - public function move_files($questionid, $oldcontextid, $newcontextid) { - global $DB; - $fs = get_file_storage(); - parent::move_files($questionid, $oldcontextid, $newcontextid); - $fs->move_area_files_to_new_context($oldcontextid, - $newcontextid, 'qtype_ddimageortext', 'bgimage', $questionid); - $dragids = $DB->get_records_menu('qtype_ddimageortext_drags', - array('questionid' => $questionid), 'id', 'id,1'); - foreach ($dragids as $dragid => $notused) { - $fs->move_area_files_to_new_context($oldcontextid, - $newcontextid, 'qtype_ddimageortext', 'dragimage', $dragid); - } - - $this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid); - } - - /** - * Delete all the files belonging to this question. - * @param int $questionid the question being deleted. - * @param int $contextid the context the question is in. - */ - - protected function delete_files($questionid, $contextid) { - global $DB; - $fs = get_file_storage(); - - parent::delete_files($questionid, $contextid); - - $dragids = $DB->get_records_menu('qtype_ddimageortext_drags', - array('questionid' => $questionid), 'id', 'id,1'); - foreach ($dragids as $dragid => $notused) { - $fs->delete_area_files($contextid, 'qtype_ddimageortext', 'dragimage', $dragid); - } - - $this->delete_files_in_combined_feedback($questionid, $contextid); - } - - public function export_to_xml($question, $format, $extra = null) { - $fs = get_file_storage(); - $contextid = $question->contextid; - $output = ''; - - if ($question->options->shuffleanswers) { - $output .= " \n"; - } - $output .= $format->write_combined_feedback($question->options); - $output .= $format->write_hints($question); - $files = $fs->get_area_files($contextid, 'qtype_ddimageortext', 'bgimage', $question->id); - $output .= " ".$this->write_files($files, 2)."\n";; - - foreach ($question->options->drags as $drag) { - $files = - $fs->get_area_files($contextid, 'qtype_ddimageortext', 'dragimage', $drag->id); - $output .= " \n"; - $output .= " {$drag->no}\n"; - $output .= $format->writetext($drag->label, 3)."\n"; - $output .= " {$drag->draggroup}\n"; - if ($drag->infinite) { - $output .= " \n"; - } - $output .= $this->write_files($files, 3); - $output .= " \n"; - } - foreach ($question->options->drops as $drop) { - $output .= " \n"; - $output .= $format->writetext($drop->label, 3); - $output .= " {$drop->no}\n"; - $output .= " {$drop->choice}\n"; - $output .= " {$drop->xleft}\n"; - $output .= " {$drop->ytop}\n"; - $output .= " \n"; - } - - return $output; - } - - public function import_from_xml($data, $question, $format, $extra=null) { - if (!isset($data['@']['type']) || $data['@']['type'] != 'ddimageortext') { - return false; - } - - $question = $format->import_headers($data); - $question->qtype = 'ddimageortext'; - - $question->shuffleanswers = array_key_exists('shuffleanswers', - $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]['draglabel'] = - $format->getpath($dragxml, array('#', 'text', 0, '#'), '', true); - $question->drags[$dragindex]['infinite'] = array_key_exists('infinite', $dragxml['#']); - $question->drags[$dragindex]['draggroup'] = - $format->getpath($dragxml, array('#', 'draggroup', 0, '#'), 1); - $filexml = $format->getpath($dragxml, array('#', 'file'), array()); - $question->dragitem[$dragindex] = - $this->import_files_to_draft_file_area($format, $filexml); - if (count($filexml)) { - $question->dragitemtype[$dragindex] = 'image'; - } else { - $question->dragitemtype[$dragindex] = 'word'; - } - } - - $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]['droplabel'] = - $format->getpath($dropxml, array('#', 'text', 0, '#'), '', true); - $question->drops[$dropindex]['xleft'] = - $format->getpath($dropxml, array('#', 'xleft', 0, '#'), ''); - $question->drops[$dropindex]['ytop'] = - $format->getpath($dropxml, array('#', 'ytop', 0, '#'), ''); - } - - $format->import_combined_feedback($question, $data, true); - $format->import_hints($question, $data, true); - - return $question; - } /** @@ -440,9 +200,11 @@ class qtype_ddtoimage_base extends question_type { $summarisechoice = $choice->summarise(); $correct = $question->rightchoices[$placeno] == $i; - $choices[$choice->no] = new question_possible_response( - $summarisechoice, - $correct?1:0); + if ($correct) { + $choices[$choice->no] = new question_possible_response( + $summarisechoice, + $correct?1:0); + } } $choices[null] = question_possible_response::no_response(); From d36f336d841e674bf16ed998836cbcd3e29532e4 Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Sat, 19 Nov 2011 17:00:51 +0700 Subject: [PATCH 5/5] MDL-47494 ddimageortext: MDL-29058 change in api related to fix for saving feedback files --- question/type/ddimageortext/questiontype.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/question/type/ddimageortext/questiontype.php b/question/type/ddimageortext/questiontype.php index d5f1cec0bef..6924c38c08a 100644 --- a/question/type/ddimageortext/questiontype.php +++ b/question/type/ddimageortext/questiontype.php @@ -190,7 +190,9 @@ class qtype_ddimageortext extends qtype_ddtoimage_base { if ($question->options->shuffleanswers) { $output .= " \n"; } - $output .= $format->write_combined_feedback($question->options); + $output .= $format->write_combined_feedback($question->options, + $question->id, + $question->contextid); $output .= $format->write_hints($question); $files = $fs->get_area_files($contextid, 'qtype_ddimageortext', 'bgimage', $question->id); $output .= " ".$this->write_files($files, 2)."\n";;