From 87c64021c2dc001a38648bbb5293168abc4e2fa6 Mon Sep 17 00:00:00 2001 From: Jamie Pratt Date: Wed, 24 Aug 2011 18:25:53 +0700 Subject: [PATCH] MDL-47494 ddimageortext: NOBUG mainly white space changes to fix code formatting issues highlighted by code checker. --- question/type/ddimageortext/README.txt | 6 ++- question/type/ddimageortext/TODO.txt | 12 ----- ...ckup_qtype_ddimagetoimage_plugin.class.php | 2 - ...tore_qtype_ddimagetoimage_plugin.class.php | 8 +-- question/type/ddimageortext/db/install.xml | 2 +- .../edit_ddimagetoimage_form.php | 7 +-- question/type/ddimageortext/questiontype.php | 13 +++-- question/type/ddimageortext/renderer.php | 3 +- question/type/ddimageortext/styles.css | 1 - question/type/ddimageortext/yui/dd/dd.js | 33 ++++++------ question/type/ddimageortext/yui/form/form.js | 51 +++++++++---------- 11 files changed, 58 insertions(+), 80 deletions(-) delete mode 100644 question/type/ddimageortext/TODO.txt diff --git a/question/type/ddimageortext/README.txt b/question/type/ddimageortext/README.txt index 5fbeb377a09..6c4605afe54 100644 --- a/question/type/ddimageortext/README.txt +++ b/question/type/ddimageortext/README.txt @@ -11,8 +11,10 @@ This question type is compatible with Moodle 2.1+. Requires this fix : MDL-28099 filepicker form element does not work with element names with an index such as image[0] -To install using git, type this command in the root of your Moodle install - git clone git://github.com/jamiepratt/moodle-qtype_ddimagetoimage.git question/type/ddimagetoimage +To install using git, type this command in the root of your Moodle install : + +git clone git://github.com/jamiepratt/moodle-qtype_ddimagetoimage.git question/type/ddimagetoimage + Then add question/type/ddimagetoimage to your git ignore. Alternatively, download the zip from diff --git a/question/type/ddimageortext/TODO.txt b/question/type/ddimageortext/TODO.txt deleted file mode 100644 index aceaf24f456..00000000000 --- a/question/type/ddimageortext/TODO.txt +++ /dev/null @@ -1,12 +0,0 @@ -Question authoring form fields -* correct sizing of borders and margins - -Question instance saving 2 hours -Question instance loading 2 hours -Question rendering code 6 hours -- repurpose and extend authoring form code for question rendering -- make sure code works with multiple questions on the page -- get position that images where dropped to from hidden fields -- grade question parts based on where images dragged to - -Testing and debugging for cross browser compatibility 4 hours diff --git a/question/type/ddimageortext/backup/moodle2/backup_qtype_ddimagetoimage_plugin.class.php b/question/type/ddimageortext/backup/moodle2/backup_qtype_ddimagetoimage_plugin.class.php index 4aeef438677..de8d93da728 100644 --- a/question/type/ddimageortext/backup/moodle2/backup_qtype_ddimagetoimage_plugin.class.php +++ b/question/type/ddimageortext/backup/moodle2/backup_qtype_ddimagetoimage_plugin.class.php @@ -57,7 +57,6 @@ class backup_qtype_ddimagetoimage_plugin extends backup_qtype_plugin { $drop = new backup_nested_element('drop', array('id'), array('no', 'xleft', 'ytop', 'choice', 'label')); - $ddimagetoimages->set_source_table('qtype_ddimagetoimage', array('questionid' => backup::VAR_PARENTID)); @@ -69,7 +68,6 @@ class backup_qtype_ddimagetoimage_plugin extends backup_qtype_plugin { $drag->set_source_table('qtype_ddimagetoimage_drags', array('questionid' => backup::VAR_PARENTID)); - $drop->set_source_table('qtype_ddimagetoimage_drops', array('questionid' => backup::VAR_PARENTID)); diff --git a/question/type/ddimageortext/backup/moodle2/restore_qtype_ddimagetoimage_plugin.class.php b/question/type/ddimageortext/backup/moodle2/restore_qtype_ddimagetoimage_plugin.class.php index eeb4ac1f289..7d54ed41861 100644 --- a/question/type/ddimageortext/backup/moodle2/restore_qtype_ddimagetoimage_plugin.class.php +++ b/question/type/ddimageortext/backup/moodle2/restore_qtype_ddimagetoimage_plugin.class.php @@ -21,10 +21,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); - /** * restore plugin class that provides the necessary information * needed to restore one ddimagetoimage qtype plugin @@ -71,7 +69,8 @@ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { $newquestionid = $this->get_new_parentid('question'); $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false; - // If the question has been created by restore, we need to create its qtype_ddimagetoimage too + // If the question has been created by restore, + // we need to create its qtype_ddimagetoimage too if ($questioncreated) { // Adjust some columns $data->questionid = $newquestionid; @@ -137,7 +136,8 @@ class restore_qtype_ddimagetoimage_plugin extends restore_qtype_plugin { $contents = array(); $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback'); - $contents[] = new restore_decode_content('qtype_ddimagetoimage', $fields, 'question_ddimagetoimage'); + $contents[] = + new restore_decode_content('qtype_ddimagetoimage', $fields, 'question_ddimagetoimage'); return $contents; } diff --git a/question/type/ddimageortext/db/install.xml b/question/type/ddimageortext/db/install.xml index 07a40be9766..209aa0a2a08 100755 --- a/question/type/ddimageortext/db/install.xml +++ b/question/type/ddimageortext/db/install.xml @@ -52,4 +52,4 @@ - \ No newline at end of file + diff --git a/question/type/ddimageortext/edit_ddimagetoimage_form.php b/question/type/ddimageortext/edit_ddimagetoimage_form.php index d47bff8ed0f..f21e4d9b114 100644 --- a/question/type/ddimageortext/edit_ddimagetoimage_form.php +++ b/question/type/ddimageortext/edit_ddimagetoimage_form.php @@ -67,7 +67,7 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { } $imagerepeats = optional_param('noimages', $imagerepeatsatstart, PARAM_INT); $addfields = optional_param('addimages', '', PARAM_TEXT); - if (!empty($addfields)){ + if (!empty($addfields)) { $imagerepeats += self::ADD_NUM_IMAGES; } return array($imagerepeatsatstart, $imagerepeats); @@ -85,7 +85,6 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { get_string('previewarea', 'qtype_ddimagetoimage'), get_string('previewareamessage', 'qtype_ddimagetoimage')); - list($imagerepeatsatstart, $imagerepeats) = $this->get_drag_image_repeats(); $this->definition_drop_zones($mform, $imagerepeats); $mform->addElement('advcheckbox', 'shuffleanswers', ' ', @@ -106,7 +105,6 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { $mform->addElement('filepicker', 'bgimage', get_string('bgimage', 'qtype_ddimagetoimage'), null, self::file_picker_options()); - $countdropzones = 0; if (isset($this->question->id)) { foreach ($this->question->options->drops as $drop) { @@ -129,7 +127,6 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { protected function drop_zone($mform, $imagerepeats) { $dropzoneitem = array(); - $grouparray = array(); $grouparray[] = $mform->createElement('static', 'xleftlabel', '', ' '.get_string('xleft', 'qtype_ddimagetoimage').' '); @@ -293,7 +290,7 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form { public function validation($data, $files) { $errors = parent::validation($data, $files); - if (!self::file_uploaded($data['bgimage'])){ + if (!self::file_uploaded($data['bgimage'])) { $errors["bgimage"] = get_string('formerror_nobgimage', 'qtype_ddimagetoimage'); } diff --git a/question/type/ddimageortext/questiontype.php b/question/type/ddimageortext/questiontype.php index ead9773eb8b..e3d7cea2180 100755 --- a/question/type/ddimageortext/questiontype.php +++ b/question/type/ddimageortext/questiontype.php @@ -134,8 +134,8 @@ class qtype_ddimagetoimage extends question_type { $this->save_hints($formdata, true); $DB->update_record('qtype_ddimagetoimage', $options); $DB->delete_records('qtype_ddimagetoimage_drops', array('questionid' => $formdata->id)); - foreach (array_keys($formdata->drops) as $dropno){ - if ($formdata->drops[$dropno]['choice'] == 0){ + foreach (array_keys($formdata->drops) as $dropno) { + if ($formdata->drops[$dropno]['choice'] == 0) { continue; } $drop = new stdClass(); @@ -153,7 +153,7 @@ class qtype_ddimagetoimage extends question_type { $olddragids = $DB->get_records_menu('qtype_ddimagetoimage_drags', array('questionid' => $formdata->id), '', 'no, id'); - foreach (array_keys($formdata->drags) as $dragno){ + foreach (array_keys($formdata->drags) as $dragno) { $info = file_get_draft_area_info($formdata->dragitem[$dragno]); if ($info['filecount'] > 0) { $draftitemid = $formdata->dragitem[$dragno]; @@ -173,8 +173,6 @@ class qtype_ddimagetoimage extends question_type { $drag->id = $DB->insert_record('qtype_ddimagetoimage_drags', $drag); } - - self::constrain_image_size_in_draft_area($draftitemid, QTYPE_DDIMAGETOIMAGE_DRAGIMAGE_MAXWIDTH, QTYPE_DDIMAGETOIMAGE_DRAGIMAGE_MAXHEIGHT); @@ -218,7 +216,7 @@ class qtype_ddimagetoimage extends question_type { $quality = 8; break; default : - $quality = NULL; + $quality = null; } $newwidth = min($maxwidth, $width); $newheight = min($maxheight, $height); @@ -291,7 +289,8 @@ class qtype_ddimagetoimage extends question_type { $output .= " ".$this->write_files($files, 2)."\n";; foreach ($question->options->drags as $drag) { - $files = $fs->get_area_files($contextid, 'qtype_ddimagetoimage', 'dragimage', $drag->id); + $files = + $fs->get_area_files($contextid, 'qtype_ddimagetoimage', 'dragimage', $drag->id); $output .= " \n"; $output .= " {$drag->no}\n"; $output .= $format->writetext($drag->label, 3)."\n"; diff --git a/question/type/ddimageortext/renderer.php b/question/type/ddimageortext/renderer.php index 18a3c238a04..fb5fe30679c 100755 --- a/question/type/ddimageortext/renderer.php +++ b/question/type/ddimageortext/renderer.php @@ -100,7 +100,7 @@ class qtype_ddimagetoimage_renderer extends qtype_with_combined_feedback_rendere $dropzones = html_writer::empty_tag('div', array('class'=>'dropzones')); $output .= html_writer::tag('div', $droparea.$dragitems.$dropzones, array('class'=>'ddarea')); - foreach ($question->places as $placeno => $place){ + foreach ($question->places as $placeno => $place) { $varname = $question->field($placeno); list($fieldname, $html) = $this->hidden_field_for_qt_var($qa, $varname); $output .= $html; @@ -115,7 +115,6 @@ class qtype_ddimagetoimage_renderer extends qtype_with_combined_feedback_rendere 'M.qtype_ddimagetoimage.init_question', array($params)); - if ($qa->get_state() == question_state::$invalid) { $output .= html_writer::nonempty_tag('div', $question->get_validation_error($qa->get_last_qt_data()), diff --git a/question/type/ddimageortext/styles.css b/question/type/ddimageortext/styles.css index 9453d9273e5..77038e98293 100755 --- a/question/type/ddimageortext/styles.css +++ b/question/type/ddimageortext/styles.css @@ -123,4 +123,3 @@ form.mform fieldset#previewareaheader .droptarget { form.mform fieldset#previewareaheader div.droparea img { border: 1px solid #000000; } - diff --git a/question/type/ddimageortext/yui/dd/dd.js b/question/type/ddimageortext/yui/dd/dd.js index 2f024e7c0bc..32c199795ef 100644 --- a/question/type/ddimageortext/yui/dd/dd.js +++ b/question/type/ddimageortext/yui/dd/dd.js @@ -1,4 +1,3 @@ - YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { var DDIMAGETOIMAGEDDNAME = 'ddimagetoimage_dd'; var DDIMAGETOIMAGE_DD = function() { @@ -16,7 +15,7 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { bgdone = bgdone && this.doc.bg_img().hasClass('constrained'); } var alldragsloaded = !this.doc.drag_image_homes().some(function(dragimagehome){ - //in 'some' loop returning true breaks the loop and is passed as return value from + //in 'some' loop returning true breaks the loop and is passed as return value from //'some' else returns false. Can be though of as equivalent to ||. var done = (dragimagehome.get('complete')); if (waitforimageconstrain) { @@ -141,13 +140,13 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { node: drag, dragMode: 'intersect' }).plug(Y.Plugin.DDConstrained, {constrain2node: topnode}); - + dd.on('drag:end', function(e) { mainobj.reposition_drags_for_question(); }, this); drag.setData('group', group); drag.setData('choice', choice); - + }, draggable_for_form : function (drag) { var dd = new Y.DD.Drag({ @@ -159,7 +158,7 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { var draginstanceno = dragnode.getData('draginstanceno'); var gooddrop = dragnode.getData('gooddrop'); var endxy; - + if (!gooddrop) { mainobj.reset_drag_xy(draginstanceno); } else { @@ -171,12 +170,12 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { var drag = e.target; drag.get('node').setData('gooddrop', false); }, this); - + } - + } }, - + update_padding_sizes_all : function () { for (var groupno = 1; groupno <= 8; groupno++) { this.update_padding_size_for_group(groupno); @@ -238,7 +237,7 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { this.update_padding_sizes_all(); var i = 0; this.doc.drag_image_homes().each(function(dragimagehome){ - var dragimageno = + var dragimageno = +this.doc.get_classname_numeric_suffix(dragimagehome, 'dragimagehomes'); var choice = +this.doc.get_classname_numeric_suffix(dragimagehome, 'choice'); var group = +this.doc.get_classname_numeric_suffix(dragimagehome, 'group') @@ -272,7 +271,7 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { }, drop_zone_key_press : function (e) { switch (e.direction) { - case 'next' : + case 'next' : this.place_next_drag_in(e.target); break; case 'previous' : @@ -370,7 +369,7 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { } }, this); }, - get_choices_for_drop : function(choice, drop) { + get_choices_for_drop : function(choice, drop) { var group = drop.getData('group'); var dragimage = null; var dragimages = this.doc.top_node() @@ -379,6 +378,7 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { }, get_unplaced_choice_for_drop : function(choice, drop) { var dragimages = this.get_choices_for_drop(choice, drop); + var dragimage = null; if (dragimages.some(function (d) { if (!d.hasClass('placed')) { dragimage = d; @@ -386,11 +386,8 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { } else { return false; } - })) { - return dragimage; - } else { - return null; - } + })); + return dragimage; }, init_drops : function () { var dropareas = this.doc.top_node().one('div.dropzones'); @@ -424,7 +421,7 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { }; } }, {NAME : DDIMAGETOIMAGEQUESTIONNAME, ATTRS : {}}); - + Y.Event.define('dragchange', { // Webkit and IE repeat keydown when you hold down arrow keys. // Opera links keypress to page scroll; others keydown. @@ -453,7 +450,7 @@ YUI.add('moodle-qtype_ddimagetoimage-dd', function(Y) { this, notifier); } }); - M.qtype_ddimagetoimage.init_question = function(config) { + M.qtype_ddimagetoimage.init_question = function(config) { return new DDIMAGETOIMAGE_QUESTION(config); } }, '@VERSION@', { diff --git a/question/type/ddimageortext/yui/form/form.js b/question/type/ddimageortext/yui/form/form.js index 2189d75bfe9..e8b0436bf76 100644 --- a/question/type/ddimageortext/yui/form/form.js +++ b/question/type/ddimageortext/yui/form/form.js @@ -17,7 +17,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { this.doc = this.doc_structure(this); this.draw_dd_area(); }, - + draw_dd_area : function() { var bgimageurl = this.fp.file('bgimage').href; this.stop_selector_events(); @@ -25,7 +25,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { if (bgimageurl !== null) { this.doc.load_bg_img(bgimageurl); this.load_drag_homes(); - + var drop = new Y.DD.Drop({ node: this.doc.bg_img() }); @@ -33,9 +33,9 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { drop.on('drop:hit', function(e) { e.drag.get('node').setData('gooddrop', true); }); - + Y.on('windowresize', this.reposition_drags_for_form, this); - + this.doc.bg_img().on('load', this.constrain_image_size, this, 'bgimage'); this.doc.drag_image_homes() .on('load', this.constrain_image_size, this, 'dragimage'); @@ -47,7 +47,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { this.setup_form_events(); } }, - + after_all_images_loaded : function () { this.update_padding_sizes_all(); this.update_drag_instances(); @@ -55,7 +55,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { this.set_options_for_drag_image_selectors(); this.setup_form_events(); }, - + constrain_image_size : function (e, imagetype) { var maxsize = this.get('maxsizes')[imagetype]; var reduceby = Math.max(e.target.get('width') / maxsize.width, @@ -66,22 +66,22 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { e.target.addClass('constrained'); e.target.detach('load', this.constrain_image_size); }, - + load_drag_homes : function () { //set up drag items homes - var dragimagesoptions = {0: ''}; + var dragimagesoptions = {0: ''}; for (var i=0; i < this.form.get_form_value('noimages', []); i++) { this.load_drag_home(i); } }, - + load_drag_home : function (dragimageno) { var url = this.fp.file(this.form.to_name_with_index('dragitem', [dragimageno])).href; - this.doc.add_or_update_drag_image_home(dragimageno, url, + this.doc.add_or_update_drag_image_home(dragimageno, url, this.form.get_form_value('drags', [dragimageno, 'draglabel']), this.form.get_form_value('drags', [dragimageno, 'draggroup'])); }, - + update_drag_instances : function () { //set up drop zones for (var i=0; i < this.form.get_form_value('nodropzone', []); i++) { @@ -95,7 +95,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { } }, set_options_for_drag_image_selectors : function () { - var dragimagesoptions = {0: ''}; + var dragimagesoptions = {0: ''}; for (var i=0; i < this.form.get_form_value('noimages', []); i++) { var file = this.fp.file(this.form.to_name_with_index('dragitem', [i])); if (file.name !== null) { @@ -130,21 +130,21 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { } } }, - + stop_selector_events : function () { Y.all('fieldset#dropzoneheader select').detachAll(); }, - + setup_form_events : function () { //events triggered by changes to form data - + //x and y coordinates Y.all('fieldset#dropzoneheader input').on('blur', function (e){ var name = e.target.getAttribute('name'); var draginstanceno = this.form.from_name_with_index(name).indexes[0]; this.reposition_drag_for_form(draginstanceno); }, this); - + //change in selected image Y.all('fieldset#dropzoneheader select').on('change', function (e){ var name = e.target.getAttribute('name'); @@ -155,7 +155,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { } this.draw_dd_area(); }, this); - + for (var i=0; i < this.form.get_form_value('noimages', []); i++) { //change to group selector Y.all('fieldset#draggableimageheader_'+i+' select').on('change', function (e){ @@ -171,26 +171,25 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { var name = this.fp.name(e.id); if (name !== 'bgimage') { this.doc.drag_images().remove(true); - } + } this.draw_dd_area(); }, M.form_filepicker, 'callback', this); }, - - + reposition_drags_for_form : function() { this.doc.drag_images().each(function (drag) { var draginstanceno = drag.getData('draginstanceno'); this.reposition_drag_for_form(draginstanceno); }, this); }, - + reposition_drag_for_form : function (draginstanceno) { var drag = this.doc.drag_image(draginstanceno); if (null !== drag) { var fromform = [this.form.get_form_value('drops', [draginstanceno, 'xleft']), this.form.get_form_value('drops', [draginstanceno, 'ytop'])]; if (fromform[0] == '' && fromform[1] == '') { - var dragimageno = drag.getData('dragimageno'); + var dragimageno = drag.getData('dragimageno'); drag.setXY(this.doc.drag_image_home(dragimageno).getXY()); } else { var constrainedxy = this.constrain_xy(draginstanceno, fromform); @@ -213,7 +212,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { this.form.set_form_value('drops', [draginstanceno, 'ytop'], ''); this.reposition_drag_for_form(draginstanceno); }, - + //make sure xy value is not out of bounds of bg image constrain_xy : function (draginstanceno, bgimgxy) { var drag = this.doc.drag_image(draginstanceno); @@ -229,7 +228,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { return [windowxy[0] - this.doc.bg_img().getX(), windowxy[1] - this.doc.bg_img().getY()]; }, - + /** * Low level operations on form. */ @@ -270,7 +269,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { return toreturn; } }, - + file_pickers : function () { var draftitemidstoname; var nametoparentnode; @@ -301,7 +300,7 @@ YUI.add('moodle-qtype_ddimagetoimage-form', function(Y) { } }, {NAME : DDIMAGETOIMAGEFORMNAME, ATTRS : {maxsizes:{value:null}}}); M.qtype_ddimagetoimage = M.qtype_ddimagetoimage || {}; - M.qtype_ddimagetoimage.init_form = function(config) { + M.qtype_ddimagetoimage.init_form = function(config) { return new DDIMAGETOIMAGE_FORM(config); } }, '@VERSION@', {