MDL-47494 ddimageortext: NOBUG mainly white space changes to fix code formatting issues highlighted by

code checker.
This commit is contained in:
Jamie Pratt
2011-08-24 18:25:53 +07:00
parent e074cd91ea
commit 87c64021c2
11 changed files with 58 additions and 80 deletions
+4 -2
View File
@@ -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
-12
View File
@@ -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
@@ -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));
@@ -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;
}
+1 -1
View File
@@ -52,4 +52,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
@@ -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');
}
+6 -7
View File
@@ -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 .= " <drag>\n";
$output .= " <no>{$drag->no}</no>\n";
$output .= $format->writetext($drag->label, 3)."\n";
+1 -2
View File
@@ -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()),
-1
View File
@@ -123,4 +123,3 @@ form.mform fieldset#previewareaheader .droptarget {
form.mform fieldset#previewareaheader div.droparea img {
border: 1px solid #000000;
}
+15 -18
View File
@@ -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@', {
+25 -26
View File
@@ -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@', {