From a5290cd828dd6aff7d683c78a96984d26f79e7cb Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 14 Mar 2013 12:21:02 +0000 Subject: [PATCH] MDL-47494 ddwtos: Fixup codechecker and jshint issues. --- .../backup_qtype_ddwtos_plugin.class.php | 31 ++++++++-------- .../restore_qtype_ddwtos_plugin.class.php | 37 +++++++++---------- question/type/ddwtos/renderer.php | 2 +- question/type/ddwtos/yui/dd/dd.js | 22 +++++------ 4 files changed, 44 insertions(+), 48 deletions(-) diff --git a/question/type/ddwtos/backup/moodle2/backup_qtype_ddwtos_plugin.class.php b/question/type/ddwtos/backup/moodle2/backup_qtype_ddwtos_plugin.class.php index 89cb186f836..6ef90d6fb04 100644 --- a/question/type/ddwtos/backup/moodle2/backup_qtype_ddwtos_plugin.class.php +++ b/question/type/ddwtos/backup/moodle2/backup_qtype_ddwtos_plugin.class.php @@ -15,10 +15,9 @@ // along with Moodle. If not, see . /** - * @package moodlecore - * @subpackage backup-moodle2 - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package qtype_ddwtos + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -26,44 +25,44 @@ defined('MOODLE_INTERNAL') || die(); /** - * Provides the information to backup ddwtos questions + * Provides the information to backup ddwtos questions. * - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class backup_qtype_ddwtos_plugin extends backup_qtype_plugin { /** - * Returns the qtype information to attach to question element + * Returns the qtype information to attach to question element. */ protected function define_question_plugin_structure() { - // Define the virtual plugin element with the condition to fulfill + // Define the virtual plugin element with the condition to fulfill. $plugin = $this->get_plugin_element(null, '../../qtype', 'ddwtos'); - // Create one standard named plugin element (the visible container) + // Create one standard named plugin element (the visible container). $pluginwrapper = new backup_nested_element($this->get_recommended_name()); - // connect the visible container ASAP + // Connect the visible container ASAP. $plugin->add_child($pluginwrapper); // This qtype uses standard question_answers, add them here - // to the tree before any other information that will use them + // to the tree before any other information that will use them. $this->add_question_question_answers($pluginwrapper); - // Now create the qtype own structures + // Now create the qtype own structures. $ddwtos = new backup_nested_element('ddwtos', array('id'), array( 'shuffleanswers', 'correctfeedback', 'correctfeedbackformat', 'partiallycorrectfeedback', 'partiallycorrectfeedbackformat', 'incorrectfeedback', 'incorrectfeedbackformat', 'shownumcorrect')); - // Now the own qtype tree + // Now the own qtype tree. $pluginwrapper->add_child($ddwtos); - // set source to populate the data + // Set source to populate the data. $ddwtos->set_source_table('question_ddwtos', array('questionid' => backup::VAR_PARENTID)); - // don't need to annotate ids nor files + // Don't need to annotate ids nor files. return $plugin; } diff --git a/question/type/ddwtos/backup/moodle2/restore_qtype_ddwtos_plugin.class.php b/question/type/ddwtos/backup/moodle2/restore_qtype_ddwtos_plugin.class.php index 48fd9695bef..fe0b65204c7 100644 --- a/question/type/ddwtos/backup/moodle2/restore_qtype_ddwtos_plugin.class.php +++ b/question/type/ddwtos/backup/moodle2/restore_qtype_ddwtos_plugin.class.php @@ -15,10 +15,9 @@ // along with Moodle. If not, see . /** - * @package moodlecore - * @subpackage backup-moodle2 - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package qtype_ddwtos + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -27,33 +26,33 @@ defined('MOODLE_INTERNAL') || die(); /** * restore plugin class that provides the necessary information - * needed to restore one ddwtos qtype plugin + * needed to restore one ddwtos qtype plugin. * - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class restore_qtype_ddwtos_plugin extends restore_qtype_plugin { /** - * Returns the paths to be handled by the plugin at question level + * Returns the paths to be handled by the plugin at question level. */ protected function define_question_plugin_structure() { $paths = array(); - // This qtype uses question_answers, add them + // This qtype uses question_answers, add them. $this->add_question_question_answers($paths); - // Add own qtype stuff + // Add own qtype stuff. $elename = 'ddwtos'; - $elepath = $this->get_pathfor('/ddwtos'); // we used get_recommended_name() so this works + $elepath = $this->get_pathfor('/ddwtos'); // We used get_recommended_name() so this works. $paths[] = new restore_path_element($elename, $elepath); - return $paths; // And we return the interesting paths + return $paths; // And we return the interesting paths. } /** - * Process the qtype/ddwtos element + * Process the qtype/ddwtos element. */ public function process_ddwtos($data) { global $DB; @@ -61,24 +60,24 @@ class restore_qtype_ddwtos_plugin extends restore_qtype_plugin { $data = (object)$data; $oldid = $data->id; - // Detect if the question is created or mapped + // Detect if the question is created or mapped. $oldquestionid = $this->get_old_parentid('question'); $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 question_ddwtos too + // If the question has been created by restore, we need to create its question_ddwtos too. if ($questioncreated) { - // Adjust some columns + // Adjust some columns. $data->questionid = $newquestionid; - // Insert record + // Insert record. $newitemid = $DB->insert_record('question_ddwtos', $data); - // Create mapping (needed for decoding links) + // Create mapping (needed for decoding links). $this->set_mapping('question_ddwtos', $oldid, $newitemid); } } /** - * Return the contents of this qtype to be processed by the links decoder + * Return the contents of this qtype to be processed by the links decoder. */ public static function define_decode_contents() { diff --git a/question/type/ddwtos/renderer.php b/question/type/ddwtos/renderer.php index 1233831fbd4..3146ae30f13 100644 --- a/question/type/ddwtos/renderer.php +++ b/question/type/ddwtos/renderer.php @@ -136,7 +136,7 @@ class qtype_ddwtos_renderer extends qtype_elements_embedded_in_question_text_ren protected function drag_boxes($qa, $group, $choices, question_display_options $options) { $boxes = ''; foreach ($choices as $key => $choice) { - //Bug 8632 - long text entry causes bug in drag and drop field in IE + // Bug 8632: long text entry causes bug in drag and drop field in IE. $content = str_replace('-', '‑', $choice->text); $content = str_replace(' ', ' ', $content); diff --git a/question/type/ddwtos/yui/dd/dd.js b/question/type/ddwtos/yui/dd/dd.js index 2169b72cadf..735623ea5b8 100644 --- a/question/type/ddwtos/yui/dd/dd.js +++ b/question/type/ddwtos/yui/dd/dd.js @@ -26,14 +26,14 @@ YUI.add('moodle-qtype_ddwtos-dd', function(Y) { var DDWTOSDDNAME = 'ddwtos_dd'; var DDWTOS_DD = function() { DDWTOS_DD.superclass.constructor.apply(this, arguments); - } + }; /** * This is the class for ddwtos question rendering. * A DDWTOS_DD class is created for each question. */ Y.extend(DDWTOS_DD, Y.Base, { selectors : null, - initializer : function(params) { + initializer : function() { this.selectors = this.css_selectors(this.get('topnode')); this.set_padding_sizes_all(); this.clone_drag_items(); @@ -45,7 +45,7 @@ YUI.add('moodle-qtype_ddwtos-dd', function(Y) { * put all our selectors in the same place so we can quickly find and change them later * if the structure of the document changes. */ - css_selectors : function(topnode){ + css_selectors : function(topnode) { return { top_node : function() { return topnode; @@ -92,7 +92,7 @@ YUI.add('moodle-qtype_ddwtos-dd', function(Y) { drops_group : function(groupno) { return topnode+' span.drop.group'+groupno; } - } + }; }, set_padding_sizes_all : function () { for (var groupno = 1; groupno <= 8; groupno++) { @@ -160,12 +160,12 @@ YUI.add('moodle-qtype_ddwtos-dd', function(Y) { var classes = node.getAttribute('class'); if (classes !== '') { var classesarr = classes.split(' '); - for (index in classesarr) { + for (var index = 0; index < classesarr.length; index++) { var patt1 = new RegExp('^'+prefix+'([0-9])+$'); if (patt1.test(classesarr[index])) { var patt2 = new RegExp('([0-9])+$'); var match = patt2.exec(classesarr[index]); - return +match[0]; + return + match[0]; } } } @@ -202,9 +202,7 @@ YUI.add('moodle-qtype_ddwtos-dd', function(Y) { } }, make_draggable : function (drag) { - var choice = this.get_choice(drag); - var group = this.get_group(drag); - var dd = new Y.DD.Drag({ + new Y.DD.Drag({ node: drag, groups: [this.get_group(drag)], dragMode: 'point' @@ -261,13 +259,13 @@ YUI.add('moodle-qtype_ddwtos-dd', function(Y) { this.place_drag_in_drop(null, drop); }, position_drag_items : function () { - Y.all(this.selectors.drags()).each(this.position_drag_item, this) + Y.all(this.selectors.drags()).each(this.position_drag_item, this); }, position_drag_item : function (drag) { if (!drag.hasClass('yui3-dd-dragging')) { if (!this.placed[this.get_no(drag)]) { var groupno = this.get_group(drag); - var choiceno = this.get_choice(drag) + var choiceno = this.get_choice(drag); var home = Y.one(this.selectors.drag_home(groupno, choiceno)); drag.setXY(home.getXY()); drag.addClass('unplaced'); @@ -370,7 +368,7 @@ YUI.add('moodle-qtype_ddwtos-dd', function(Y) { M.qtype_ddwtos = M.qtype_ddwtos || {}; M.qtype_ddwtos.init_question = function(config) { return new DDWTOS_DD(config); - } + }; }, '@VERSION@', { requires:['node', 'dd', 'dd-drop', 'dd-constrain'] });