diff --git a/question/type/ddmarker/backup/moodle2/backup_qtype_ddmarker_plugin.class.php b/question/type/ddmarker/backup/moodle2/backup_qtype_ddmarker_plugin.class.php index 267e88745d6..31967f7d4fc 100644 --- a/question/type/ddmarker/backup/moodle2/backup_qtype_ddmarker_plugin.class.php +++ b/question/type/ddmarker/backup/moodle2/backup_qtype_ddmarker_plugin.class.php @@ -15,9 +15,10 @@ // along with Moodle. If not, see . /** + * Backup code for qtype_ddmarker. + * * @package qtype_ddmarker * @copyright 2012 The Open University - * @author Jamie Pratt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); @@ -31,6 +32,10 @@ defined('MOODLE_INTERNAL') || die(); */ class backup_qtype_ddmarker_plugin extends backup_qtype_plugin { + /** + * Get the name of this question type. + * @return string the question type, like 'ddmarker'. + */ protected static function qtype_name() { return 'ddmarker'; } diff --git a/question/type/ddmarker/backup/moodle2/restore_qtype_ddmarker_plugin.class.php b/question/type/ddmarker/backup/moodle2/restore_qtype_ddmarker_plugin.class.php index 9215ce5c947..608a48d604f 100644 --- a/question/type/ddmarker/backup/moodle2/restore_qtype_ddmarker_plugin.class.php +++ b/question/type/ddmarker/backup/moodle2/restore_qtype_ddmarker_plugin.class.php @@ -15,17 +15,18 @@ // along with Moodle. If not, see . /** + * Restore code for qtype_ddmarker. + * * @package qtype_ddmarker * @copyright 2012 The Open University - * @author Jamie Pratt * @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 ddmarker qtype plugin. + * Restore plugin class for the ddmarker question type plugin. * * @copyright 2011 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/question/type/ddmarker/db/install.php b/question/type/ddmarker/db/install.php index 61c03b36a64..a20f18a1c59 100644 --- a/question/type/ddmarker/db/install.php +++ b/question/type/ddmarker/db/install.php @@ -15,21 +15,20 @@ // along with Moodle. If not, see . /** - * ddmarker question type installation code. + * Ddmarker question type installation code. * - * @package qtype - * @subpackage ddmarker + * @package qtype_ddmarker * @copyright 2012 The Open University - * @author Jamie Pratt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); /** - * Installation code for the ddmarker question type. It converts all existing imagetarget questions to ddmarker + * Installation code for the ddmarker question type. + * + * It converts all existing imagetarget questions to ddmarker */ function xmldb_qtype_ddmarker_install() { global $DB, $OUTPUT; @@ -44,13 +43,13 @@ function xmldb_qtype_ddmarker_install() { if (!empty($questions)) { require_once(dirname(__FILE__).'/../lib.php'); $dragssql = 'SELECT drag.* '.$from.', {qtype_ddmarker_drags} drag'.$where.' AND drag.questionid = q.id'; - $drags = xmldb_qtype_ddmarker_index_array_of_records_by_key('questionid', $DB->get_records_sql($dragssql)); + $drags = qtype_ddmarker_index_array_of_records_by_key('questionid', $DB->get_records_sql($dragssql)); $dropssql = 'SELECT drp.* '.$from.', {qtype_ddmarker_drops} drp'.$where.' AND drp.questionid = q.id'; - $drops = xmldb_qtype_ddmarker_index_array_of_records_by_key('questionid', $DB->get_records_sql($dropssql)); + $drops = qtype_ddmarker_index_array_of_records_by_key('questionid', $DB->get_records_sql($dropssql)); $answerssql = 'SELECT answer.* '.$from.', {question_answers} answer'.$where.' AND answer.question = q.id'; - $answers = xmldb_qtype_ddmarker_index_array_of_records_by_key('question', $DB->get_records_sql($answerssql)); + $answers = qtype_ddmarker_index_array_of_records_by_key('question', $DB->get_records_sql($answerssql)); $imgfiles = $DB->get_records_sql_menu('SELECT question, qimage FROM {question_imagetarget}'); $progressbar = new progress_bar('qtype_ddmarker_convert_from_imagetarget'); @@ -69,7 +68,18 @@ function xmldb_qtype_ddmarker_install() { } } -function xmldb_qtype_ddmarker_index_array_of_records_by_key($key, $recs) { + +/** + * Helper used by {@link xmldb_qtype_ddmarker_install}. + * + * Convert a one-dimensional array of records into a two-dimensional array + * grouped by field $key. + * + * @param string $key the key to group by. + * @param array $recs The records to group. + * @return array the re-grouped array. + */ +function qtype_ddmarker_index_array_of_records_by_key($key, $recs) { $out = array(); foreach ($recs as $id => $rec) { if (!isset($out[$rec->{$key}])) { diff --git a/question/type/ddmarker/db/upgrade.php b/question/type/ddmarker/db/upgrade.php index 899baa8675c..03f795b7f11 100644 --- a/question/type/ddmarker/db/upgrade.php +++ b/question/type/ddmarker/db/upgrade.php @@ -15,15 +15,13 @@ // along with Moodle. If not, see . /** - * ddmarker question type upgrade code. + * Ddmarker question type upgrade code. * * @package qtype_ddmarker * @copyright 2013 The Open University - * @author Jamie Pratt me@jamiep.org * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); diff --git a/question/type/ddmarker/edit_ddmarker_form.php b/question/type/ddmarker/edit_ddmarker_form.php index 045e2763cc8..15c72c3f665 100644 --- a/question/type/ddmarker/edit_ddmarker_form.php +++ b/question/type/ddmarker/edit_ddmarker_form.php @@ -54,7 +54,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { public function js_call() { global $PAGE; - $maxsizes =new stdClass(); + $maxsizes = new stdClass(); $maxsizes->bgimage = new stdClass(); $maxsizes->bgimage->width = QTYPE_DDMARKER_BGIMAGE_MAXWIDTH; $maxsizes->bgimage->height = QTYPE_DDMARKER_BGIMAGE_MAXHEIGHT; @@ -82,10 +82,9 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { protected function draggable_item($mform) { $draggableimageitem = array(); - $grouparray= array(); - $grouparray[] = $mform->createElement('text', 'label', - '', - array('size'=>30, 'class'=>'tweakcss')); + $grouparray = array(); + $grouparray[] = $mform->createElement('text', 'label', '', + array('size' => 30, 'class' => 'tweakcss')); $mform->setType('text', PARAM_RAW_TRIMMED); $noofdragoptions = array(0 => get_string('infinite', 'qtype_ddmarker')); @@ -113,8 +112,8 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { $grouparray[] = $mform->createElement('select', 'shape', get_string('shape', 'qtype_ddmarker'), $shapearray); $grouparray[] = $mform->createElement('text', 'coords', - get_string('coords', 'qtype_ddmarker'), - array('size'=>50, 'class'=>'tweakcss')); + get_string('coords', 'qtype_ddmarker'), + array('size' => 50, 'class' => 'tweakcss')); $mform->setType('coords', PARAM_RAW); // These are validated manually. $markernos = array(); $markernos[0] = ''; @@ -167,7 +166,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { $question->showmisplaced = $question->options->showmisplaced; $question->drags = array(); foreach ($question->options->drags as $drag) { - $dragindex = $drag->no -1; + $dragindex = $drag->no - 1; $question->drags[$dragindex] = array(); $question->drags[$dragindex]['label'] = $drag->label; if ($drag->infinite == 1) { @@ -183,7 +182,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { unset($droparray['id']); unset($droparray['no']); unset($droparray['questionid']); - $question->drops[$drop->no -1] = $droparray; + $question->drops[$drop->no - 1] = $droparray; } } // Initialise file picker for bgimage. @@ -226,7 +225,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { } $allchoices = array(); - for ($i=0; $i < $data['nodropzone']; $i++) { + for ($i = 0; $i < $data['nodropzone']; $i++) { $choice = $data['drops'][$i]['choice']; $choicepresent = ($choice !== '0'); @@ -253,7 +252,7 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base { } } - for ($dragindex=0; $dragindex < $data['noitems']; $dragindex++) { + for ($dragindex = 0; $dragindex < $data['noitems']; $dragindex++) { $label = $data['drags'][$dragindex]['label']; if ($label != strip_tags($label, QTYPE_DDMARKER_ALLOWED_TAGS_IN_MARKER)) { $errors["drags[{$dragindex}]"] diff --git a/question/type/ddmarker/imagetargetconverter.php b/question/type/ddmarker/imagetargetconverter.php index 72a9d28e369..2106c792afb 100644 --- a/question/type/ddmarker/imagetargetconverter.php +++ b/question/type/ddmarker/imagetargetconverter.php @@ -156,7 +156,7 @@ if (!count($questions)) { break; case 'confirm' : echo $renderer->render_qtype_ddmarker_list($top); - $cofirmedurl = new moodle_url($PAGE->url, compact('categoryid', 'contextid', 'questionid') + array('confirm'=>1)); + $cofirmedurl = new moodle_url($PAGE->url, compact('categoryid', 'contextid', 'questionid') + array('confirm' => 1)); $cancelurl = new moodle_url($PAGE->url); echo $renderer->confirm(get_string('confirmimagetargetconversion', 'qtype_ddmarker'), $cofirmedurl, $cancelurl); break; diff --git a/question/type/ddmarker/lang/en/qtype_ddmarker.php b/question/type/ddmarker/lang/en/qtype_ddmarker.php index 07a6407da84..087605fee55 100644 --- a/question/type/ddmarker/lang/en/qtype_ddmarker.php +++ b/question/type/ddmarker/lang/en/qtype_ddmarker.php @@ -15,12 +15,10 @@ // along with Moodle. If not, see . /** - * - * @package qtype - * @subpackage ddmarker - * @copyright 2012 The Open University - * @author Jamie Pratt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * Language strings for qtype_ddmarker. + * @package qtype_ddmarker + * @copyright 2012 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $string['addmoreitems'] = 'Blanks for {no} more markers'; @@ -42,9 +40,9 @@ $string['dropzoneheader'] = 'Drop zones'; $string['dropzones'] = 'Drop zones'; $string['dropzones_help'] = 'The drop zones are defined by typing co-ordinates. As you type, the preview above is immediately updated, so you can position things by trial and error. -* Circle: centre_x, centre_y; radius
for example: `80, 100; 50` -* Polygon: x1, y1; x2, y2; ...; xn, yn
for example: `20, 60; 100, 60; 20, 100` -* Rectangle: left, top, width, height
for example: `20, 60; 80, 40`'; +* Circle: centre_x, centre_y; radius
for example: 80, 100; 50 +* Polygon: x1, y1; x2, y2; ...; xn, yn
for example: 20, 60; 100, 60; 20, 100 +* Rectangle: left, top, width, height
for example: 20, 60; 80, 40'; $string['followingarewrong'] = 'The following markers have been placed in the wrong area : {$a}.'; $string['followingarewrongandhighlighted'] = 'The following markers were incorrectly placed : {$a}. Highlighted marker(s) are now shown with the correct placement(s).
Click on the marker to highlight the allowed area.'; $string['formerror_nobgimage'] = 'You need to select an image to use as the background for the drag and drop area.'; diff --git a/question/type/ddmarker/lib.php b/question/type/ddmarker/lib.php index 28a85614bdb..4b6f9da2bc7 100644 --- a/question/type/ddmarker/lib.php +++ b/question/type/ddmarker/lib.php @@ -15,16 +15,14 @@ // along with Moodle. If not, see . /** - * Serve question type files + * Serve question type files. * - * @package qtype - * @subpackage ddmarker - * @copyright 2012 The Open University - * @author Jamie Pratt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package qtype_ddmarker + * @copyright 2012 The Open University + * @author Jamie Pratt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - defined('MOODLE_INTERNAL') || die(); /** @@ -115,6 +113,7 @@ function qtype_ddmarker_convert_image_target_question($question, $imgfilename, $ $DB->update_record('question', $newrec); $fs = get_file_storage(); + // We need to look in the course legacy files area for file. $bgimagefile = $fs->get_file(qtype_ddmarker_course_context_id($question->contextid), 'course', diff --git a/question/type/ddmarker/question.php b/question/type/ddmarker/question.php index 49c59b94484..84fdb572c0a 100644 --- a/question/type/ddmarker/question.php +++ b/question/type/ddmarker/question.php @@ -17,10 +17,8 @@ /** * Drag-and-drop markers question definition class. * - * @package qtype - * @subpackage ddmarker + * @package qtype_ddmarker * @copyright 2012 The Open University - * @author Jamie Pratt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/question/type/ddmarker/questionlists.php b/question/type/ddmarker/questionlists.php index ea8b722a0b3..44cb838675e 100644 --- a/question/type/ddmarker/questionlists.php +++ b/question/type/ddmarker/questionlists.php @@ -14,15 +14,21 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * These classes handle transforming arrays of records into a linked tree of contexts, categories and questions. + * + * @package qtype_ddmarker + * @copyright 2012 Jamie Pratt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + defined('MOODLE_INTERNAL') || die(); /** * These classes handle transforming arrays of records into a linked tree of contexts, categories and questions. * - * @package qtype - * @subpackage ddmarker - * @copyright 2012 Jamie Pratt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2012 Jamie Pratt + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class qtype_ddmarker_list_item implements renderable { @@ -162,7 +168,7 @@ class qtype_ddmarker_context_list_item extends qtype_ddmarker_list_item { public function parent_node() { $pathids = explode('/', $this->record->path); if (count($pathids) >= 3) { - return $this->list->get_instance($pathids[count($pathids)-2]); + return $this->list->get_instance($pathids[count($pathids) - 2]); } else { return null; } diff --git a/question/type/ddmarker/questiontype.php b/question/type/ddmarker/questiontype.php index bea6d30f78b..2241090618d 100644 --- a/question/type/ddmarker/questiontype.php +++ b/question/type/ddmarker/questiontype.php @@ -136,9 +136,9 @@ class qtype_ddmarker extends qtype_ddtoimage_base { } $drag->label = $formdata->drags[$dragno]['label']; - if (isset($olddragids[$dragno +1])) { - $drag->id = $olddragids[$dragno +1]; - unset($olddragids[$dragno +1]); + if (isset($olddragids[$dragno + 1])) { + $drag->id = $olddragids[$dragno + 1]; + unset($olddragids[$dragno + 1]); $DB->update_record('qtype_ddmarker_drags', $drag); } else { $drag->id = $DB->insert_record('qtype_ddmarker_drags', $drag); @@ -337,7 +337,7 @@ class qtype_ddmarker extends qtype_ddtoimage_base { foreach ($drags as $dragxml) { $dragno = $format->getpath($dragxml, array('#', 'no', 0, '#'), 0); - $dragindex = $dragno -1; + $dragindex = $dragno - 1; $question->drags[$dragindex] = array(); $question->drags[$dragindex]['label'] = $format->getpath($dragxml, array('#', 'text', 0, '#'), '', true); @@ -353,7 +353,7 @@ class qtype_ddmarker extends qtype_ddtoimage_base { $question->drops = array(); foreach ($drops as $dropxml) { $dropno = $format->getpath($dropxml, array('#', 'no', 0, '#'), 0); - $dropindex = $dropno -1; + $dropindex = $dropno - 1; $question->drops[$dropindex] = array(); $question->drops[$dropindex]['choice'] = $format->getpath($dropxml, array('#', 'choice', 0, '#'), 0); diff --git a/question/type/ddmarker/renderer.php b/question/type/ddmarker/renderer.php index cfb35a0d50a..ec7b6ec55b7 100644 --- a/question/type/ddmarker/renderer.php +++ b/question/type/ddmarker/renderer.php @@ -51,12 +51,11 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base { $bgimage = self::get_url_for_image($qa, 'bgimage'); - $img = html_writer::empty_tag('img', - array('src'=>$bgimage, - 'class'=>'dropbackground', - 'alt' => get_string('dropbackground', 'qtype_ddmarker'))); + $img = html_writer::empty_tag('img', array( + 'src' => $bgimage, 'class' => 'dropbackground', + 'alt' => get_string('dropbackground', 'qtype_ddmarker'))); - $droparea = html_writer::tag('div', $img, array('class'=>'droparea')); + $droparea = html_writer::tag('div', $img, array('class' => 'droparea')); $draghomes = ''; $orderedgroup = $question->get_ordered_choices(1); @@ -71,12 +70,12 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base { $classes[] = 'dragno'.$drag->noofdrags; } $targeticonhtml = - $OUTPUT->pix_icon('crosshairs', '', $componentname, array('class'=> 'target')); + $OUTPUT->pix_icon('crosshairs', '', $componentname, array('class' => 'target')); - $markertextattrs = array('class'=> 'markertext'); + $markertextattrs = array('class' => 'markertext'); $markertext = html_writer::tag('span', $drag->text, $markertextattrs); - $draghomesattrs = array('class'=>join(' ', $classes)); - $draghomes .= html_writer::tag('span', $targeticonhtml.$markertext, $draghomesattrs); + $draghomesattrs = array('class' => join(' ', $classes)); + $draghomes .= html_writer::tag('span', $targeticonhtml . $markertext, $draghomesattrs); $hiddenfields .= $this->hidden_field_choice($qa, $choiceno, $drag->infinite, $drag->noofdrags); } @@ -85,12 +84,12 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base { $dragitemsclass .= ' readonly'; } - $dragitems = html_writer::tag('div', $draghomes, array('class'=> $dragitemsclass)); - $dropzones = html_writer::tag('div', '', array('class'=> 'dropzones')); - $texts = html_writer::tag('div', '', array('class'=> 'markertexts')); + $dragitems = html_writer::tag('div', $draghomes, array('class' => $dragitemsclass)); + $dropzones = html_writer::tag('div', '', array('class' => 'dropzones')); + $texts = html_writer::tag('div', '', array('class' => 'markertexts')); $output .= html_writer::tag('div', - $droparea.$dragitems.$dropzones.$texts, - array('class'=>'ddarea')); + $droparea.$dragitems.$dropzones . $texts, + array('class' => 'ddarea')); if ($question->showmisplaced && $qa->get_state()->is_finished()) { $visibledropzones = $question->get_drop_zones_without_hit($response); @@ -130,7 +129,7 @@ class qtype_ddmarker_renderer extends qtype_ddtoimage_renderer_base { } } - $output .= html_writer::tag('div', $hiddenfields, array('class'=>'ddform')); + $output .= html_writer::tag('div', $hiddenfields, array('class' => 'ddform')); return $output; } protected function hidden_field_choice(question_attempt $qa, $choiceno, $infinite, $noofdrags, $value = null) { diff --git a/question/type/ddmarker/settings.php b/question/type/ddmarker/settings.php index 2dd2cc81d6e..d6373961fc8 100644 --- a/question/type/ddmarker/settings.php +++ b/question/type/ddmarker/settings.php @@ -15,11 +15,10 @@ // along with Moodle. If not, see . /** + * Admin settings for qtype_ddmarker. * - * @package qtype - * @subpackage ddmarker + * @package qtype_ddmarker * @copyright 2012 The Open University - * @author Jamie Pratt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/question/type/ddmarker/shapes.php b/question/type/ddmarker/shapes.php index 9c960e6affa..112b8bf14cb 100644 --- a/question/type/ddmarker/shapes.php +++ b/question/type/ddmarker/shapes.php @@ -236,8 +236,7 @@ class qtype_ddmarker_shape_circle extends qtype_ddmarker_shape { } public function is_point_in_shape($xy) { - $distancefromcentre = sqrt(pow(($xy[0] - $this->xcentre), 2) - + pow(($xy[1] - $this->ycentre), 2)); + $distancefromcentre = sqrt(pow(($xy[0] - $this->xcentre), 2) + pow(($xy[1] - $this->ycentre), 2)); return $distancefromcentre < $this->radius; } @@ -301,9 +300,9 @@ class qtype_ddmarker_shape_polygon extends qtype_ddmarker_shape { } } // Make sure polygon is not closed. - if ($this->coords[count($this->coords)-1][0] == $this->coords[0][0] && - $this->coords[count($this->coords)-1][1] == $this->coords[0][1]) { - unset($this->coords[count($this->coords)-1]); + if ($this->coords[count($this->coords) - 1][0] == $this->coords[0][0] && + $this->coords[count($this->coords) - 1][1] == $this->coords[0][1]) { + unset($this->coords[count($this->coords) - 1]); } } } @@ -313,17 +312,17 @@ class qtype_ddmarker_shape_polygon extends qtype_ddmarker_shape { } public function is_point_in_shape($xy) { - $pointatinfinity = new qtype_ddmarker_point(-1000000, $xy[1]+1); + $pointatinfinity = new qtype_ddmarker_point(-1000000, $xy[1] + 1); $pointtotest = new qtype_ddmarker_point($xy[0], $xy[1]); $testsegment = new qtype_ddmarker_segment($pointatinfinity, $pointtotest); $windingnumber = 0; foreach ($this->coords as $index => $coord) { if ($index != 0) { - $a = new qtype_ddmarker_point($this->coords[$index -1][0], - $this->coords[$index -1][1]); + $a = new qtype_ddmarker_point($this->coords[$index - 1][0], + $this->coords[$index - 1][1]); } else { - $a = new qtype_ddmarker_point($this->coords[count($this->coords)-1][0], - $this->coords[count($this->coords)-1][1]); + $a = new qtype_ddmarker_point($this->coords[count($this->coords) - 1][0], + $this->coords[count($this->coords) - 1][1]); } $b = new qtype_ddmarker_point($this->coords[$index][0], $this->coords[$index][1]); @@ -332,11 +331,11 @@ class qtype_ddmarker_shape_polygon extends qtype_ddmarker_shape { if ($intersects === null) { list($perturbedsegment, $testsegment) = $this->perturb($segment, $testsegment); if ($index !== 0) { - $this->coords[$index-1][0] = $perturbedsegment->a->x; - $this->coords[$index-1][1] = $perturbedsegment->a->y; + $this->coords[$index - 1][0] = $perturbedsegment->a->x; + $this->coords[$index - 1][1] = $perturbedsegment->a->y; } else { - $this->coords[count($this->coords)-1][0] = $perturbedsegment->a->x; - $this->coords[count($this->coords)-1][1] = $perturbedsegment->a->y; + $this->coords[count($this->coords) - 1][0] = $perturbedsegment->a->x; + $this->coords[count($this->coords) - 1][1] = $perturbedsegment->a->y; } $this->coords[$index][0] = $perturbedsegment->b->x; $this->coords[$index][1] = $perturbedsegment->b->y; @@ -351,7 +350,7 @@ class qtype_ddmarker_shape_polygon extends qtype_ddmarker_shape { $windingnumber++; } } - return ($windingnumber%2)?true:false; + return ($windingnumber % 2) ? true : false; } /** @@ -366,34 +365,34 @@ class qtype_ddmarker_shape_polygon extends qtype_ddmarker_shape { $h = $p->a->dist($p->b); if ($ua == 0) { // ... q1, q2 intersects p1 exactly, move vertex p1 closer to p2. - $a = ($pt * $p->a->dist(new qtype_ddmarker_point($p->b->x, $p->a->y)))/$h; - $b = ($pt * $p->b->dist(new qtype_ddmarker_point($p->b->x, $p->a->y)))/$h; + $a = ($pt * $p->a->dist(new qtype_ddmarker_point($p->b->x, $p->a->y))) / $h; + $b = ($pt * $p->b->dist(new qtype_ddmarker_point($p->b->x, $p->a->y))) / $h; $p->a->x = $p->a->x + $a; $p->a->y = $p->a->y + $b; } else if ($ua == 1) { // ... q1, q2 intersects p2 exactly, move vertex p2 closer to p1. - $a = ($pt * $p->a->dist(new qtype_ddmarker_point($p->b->x, $p->a->y)))/$h; - $b = ($pt * $p->b->dist(new qtype_ddmarker_point($p->b->x, $p->a->y)))/$h; + $a = ($pt * $p->a->dist(new qtype_ddmarker_point($p->b->x, $p->a->y))) / $h; + $b = ($pt * $p->b->dist(new qtype_ddmarker_point($p->b->x, $p->a->y))) / $h; $p->b->x = $p->b->x - $a; $p->b->y = $p->b->y - $b; } else if ($ub == 0) { // ... p1, p2 intersects q1 exactly, move vertex q1 closer to q2. - $a = ($pt * $q->a->dist(new qtype_ddmarker_point($q->b->x, $q->a->y)))/$h; - $b = ($pt * $q->b->dist(new qtype_ddmarker_point($q->b->x, $q->a->y)))/$h; + $a = ($pt * $q->a->dist(new qtype_ddmarker_point($q->b->x, $q->a->y))) / $h; + $b = ($pt * $q->b->dist(new qtype_ddmarker_point($q->b->x, $q->a->y))) / $h; $q->a->x = $q->a->x + $a; $q->a->y = $q->a->y + $b; } else if ($ub == 1) { // ... p1, p2 intersects q2 exactly, move vertex q2 closer to q1. - $a = ($pt * $q->a->dist(new qtype_ddmarker_point($q->b->x, $q->a->y)))/$h; - $b = ($pt * $q->b->dist(new qtype_ddmarker_point($q->b->x, $q->a->y)))/$h; + $a = ($pt * $q->a->dist(new qtype_ddmarker_point($q->b->x, $q->a->y))) / $h; + $b = ($pt * $q->b->dist(new qtype_ddmarker_point($q->b->x, $q->a->y))) / $h; $q->b->x = $q->b->x - $a; $q->b->y = $q->b->y - $b; } return array($p, $q); } public function center_point() { - $center = array(round(($this->minxy[0] + $this->maxxy[0])/2), - round(($this->minxy[1] + $this->maxxy[1])/2)); + $center = array(round(($this->minxy[0] + $this->maxxy[0]) / 2), + round(($this->minxy[1] + $this->maxxy[1]) / 2)); if ($this->is_point_in_shape($center)) { return $center; } else { @@ -474,18 +473,17 @@ class qtype_ddmarker_segment { } public function intersection_point(qtype_ddmarker_segment $v) { - $d = (($v->b->y - $v->a->y) * ($this->b->x - $this->a->x)) - -(($v->b->x - $v->a->x) * ($this->b->y - $this->a->y)); + $d = (($v->b->y - $v->a->y) * ($this->b->x - $this->a->x)) - + (($v->b->x - $v->a->x) * ($this->b->y - $this->a->y)); if ($d != 0) { // The lines intersect at a point somewhere. - $ua = (($v->b->x-$v->a->x)*($this->a->y-$v->a->y) - -($v->b->y-$v->a->y)*($this->a->x-$v->a->x))/$d; - $ub = (($this->b->x-$this->a->x)*($this->a->y-$v->a->y) - -($this->b->y-$this->a->y)*($this->a->x-$v->a->x))/$d; + $ua = (($v->b->x - $v->a->x) * ($this->a->y - $v->a->y) - + ($v->b->y - $v->a->y) * ($this->a->x - $v->a->x)) / $d; + $ub = (($this->b->x - $this->a->x) * ($this->a->y - $v->a->y) - + ($this->b->y - $this->a->y) * ($this->a->x - $v->a->x)) / $d; } else { $ua = null; $ub = null; } return array($d, $ua, $ub); } - } diff --git a/question/type/ddmarker/tests/question_test.php b/question/type/ddmarker/tests/question_test.php index 37c47591707..82e34abb3a2 100644 --- a/question/type/ddmarker/tests/question_test.php +++ b/question/type/ddmarker/tests/question_test.php @@ -36,7 +36,6 @@ require_once($CFG->dirroot . '/question/type/ddmarker/tests/helper.php'); * * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @group qtype_ddmarker */ class qtype_ddmarker_question_test extends basic_testcase { @@ -261,7 +260,7 @@ class qtype_ddmarker_question_test extends basic_testcase { $this->assertEquals(array(1, question_state::$gradedright), $dd->grade_response(array('c1' => '50,50', 'c2' => '150,50', 'c3' => '100,150'))); - $this->assertEquals(array(2/3, question_state::$gradedpartial), + $this->assertEquals(array(2 / 3, question_state::$gradedpartial), $dd->grade_response(array('c1' => '50,50', 'c2' => '50,50', 'c3' => '100,150'))); $this->assertEquals(array(0, question_state::$gradedwrong), $dd->grade_response(array('c1' => '150,50', 'c2' => '50,50', 'c3' => '100,50'))); @@ -291,13 +290,13 @@ class qtype_ddmarker_question_test extends basic_testcase { $dd->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array( - 1 => new question_classified_response(1, 'quick', 1/3), - 2 => new question_classified_response(2, 'fox', 1/3), - 3 => new question_classified_response(3, 'lazy', 1/3)), + 1 => new question_classified_response(1, 'quick', 1 / 3), + 2 => new question_classified_response(2, 'fox', 1 / 3), + 3 => new question_classified_response(3, 'lazy', 1 / 3)), $dd->classify_response(array('c1' => '50,50', 'c2' => '150,50', 'c3' => '100,150'))); $this->assertEquals(array( - 1 => new question_classified_response(1, 'quick', 1/3), + 1 => new question_classified_response(1, 'quick', 1 / 3), 2 => question_classified_response::no_response(), 3 => question_classified_response::no_response()), $dd->classify_response(array('c1' => '50,50', 'c2' => '100,150', 'c3' => '150,50'))); diff --git a/question/type/ddmarker/tests/questiontype_test.php b/question/type/ddmarker/tests/questiontype_test.php index f32c6fbe11f..4fac4557f93 100644 --- a/question/type/ddmarker/tests/questiontype_test.php +++ b/question/type/ddmarker/tests/questiontype_test.php @@ -36,7 +36,6 @@ require_once($CFG->dirroot . '/question/type/ddmarker/tests/helper.php'); * * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @group qtype_ddmarker */ class qtype_ddmarker_test extends basic_testcase { /** @var qtype_ddmarker instance of the question type class to test. */ diff --git a/question/type/ddmarker/tests/shapes_test.php b/question/type/ddmarker/tests/shapes_test.php index 9933feee101..b45c534358e 100644 --- a/question/type/ddmarker/tests/shapes_test.php +++ b/question/type/ddmarker/tests/shapes_test.php @@ -7,7 +7,7 @@ // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of +// but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // @@ -24,10 +24,10 @@ */ -defined('MOODLE_INTERNAL') || die(); -global $CFG; +defined('MOODLE_INTERNAL') || die(); +global $CFG; -require_once($CFG->dirroot . '/question/type/ddmarker/shapes.php'); +require_once($CFG->dirroot . '/question/type/ddmarker/shapes.php'); /** @@ -35,7 +35,6 @@ require_once($CFG->dirroot . '/question/type/ddmarker/shapes.php'); * * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @group qtype_ddmarker */ class qtype_ddmarker_shapes_test extends basic_testcase { @@ -45,44 +44,44 @@ class qtype_ddmarker_shapes_test extends basic_testcase { } public function test_polygon_hit_test() { - $shape = new qtype_ddmarker_shape_polygon('10, 10; 20, 10; 20, 20; 10, 20'); - $this->assertTrue($shape->is_point_in_shape(array(15, 15))); - $this->assertFalse($shape->is_point_in_shape(array(5, 5))); - $this->assertFalse($shape->is_point_in_shape(array(5, 15))); - $this->assertFalse($shape->is_point_in_shape(array(15, 25))); - $this->assertFalse($shape->is_point_in_shape(array(25, 15))); - $this->assertTrue($shape->is_point_in_shape(array(11, 11))); - $this->assertTrue($shape->is_point_in_shape(array(19, 19))); + $shape = new qtype_ddmarker_shape_polygon('10, 10; 20, 10; 20, 20; 10, 20'); + $this->assertTrue($shape->is_point_in_shape(array(15, 15))); + $this->assertFalse($shape->is_point_in_shape(array(5, 5))); + $this->assertFalse($shape->is_point_in_shape(array(5, 15))); + $this->assertFalse($shape->is_point_in_shape(array(15, 25))); + $this->assertFalse($shape->is_point_in_shape(array(25, 15))); + $this->assertTrue($shape->is_point_in_shape(array(11, 11))); + $this->assertTrue($shape->is_point_in_shape(array(19, 19))); // Should accept closed polygon coords or unclosed and it will model a closed polygon. - $shape = new qtype_ddmarker_shape_polygon('10, 10; 20, 10; 20, 20; 10, 20; 10, 10'); - $this->assertTrue($shape->is_point_in_shape(array(15, 15))); - $this->assertFalse($shape->is_point_in_shape(array(5, 5))); - $this->assertFalse($shape->is_point_in_shape(array(5, 15))); - $this->assertFalse($shape->is_point_in_shape(array(15, 25))); - $this->assertFalse($shape->is_point_in_shape(array(25, 15))); - $this->assertTrue($shape->is_point_in_shape(array(11, 11))); - $this->assertTrue($shape->is_point_in_shape(array(19, 19))); + $shape = new qtype_ddmarker_shape_polygon('10, 10; 20, 10; 20, 20; 10, 20; 10, 10'); + $this->assertTrue($shape->is_point_in_shape(array(15, 15))); + $this->assertFalse($shape->is_point_in_shape(array(5, 5))); + $this->assertFalse($shape->is_point_in_shape(array(5, 15))); + $this->assertFalse($shape->is_point_in_shape(array(15, 25))); + $this->assertFalse($shape->is_point_in_shape(array(25, 15))); + $this->assertTrue($shape->is_point_in_shape(array(11, 11))); + $this->assertTrue($shape->is_point_in_shape(array(19, 19))); - $shape = new qtype_ddmarker_shape_polygon('10, 10; 15, 5; 20, 10; 20, 20; 10, 20'); - $this->assertTrue($shape->is_point_in_shape(array(15, 15))); - $this->assertFalse($shape->is_point_in_shape(array(5, 5))); - $this->assertFalse($shape->is_point_in_shape(array(5, 15))); - $this->assertFalse($shape->is_point_in_shape(array(15, 25))); - $this->assertFalse($shape->is_point_in_shape(array(25, 15))); - $this->assertTrue($shape->is_point_in_shape(array(11, 11))); - $this->assertTrue($shape->is_point_in_shape(array(19, 19))); - $this->assertTrue($shape->is_point_in_shape(array(15, 9))); - $this->assertTrue($shape->is_point_in_shape(array(15, 10))); + $shape = new qtype_ddmarker_shape_polygon('10, 10; 15, 5; 20, 10; 20, 20; 10, 20'); + $this->assertTrue($shape->is_point_in_shape(array(15, 15))); + $this->assertFalse($shape->is_point_in_shape(array(5, 5))); + $this->assertFalse($shape->is_point_in_shape(array(5, 15))); + $this->assertFalse($shape->is_point_in_shape(array(15, 25))); + $this->assertFalse($shape->is_point_in_shape(array(25, 15))); + $this->assertTrue($shape->is_point_in_shape(array(11, 11))); + $this->assertTrue($shape->is_point_in_shape(array(19, 19))); + $this->assertTrue($shape->is_point_in_shape(array(15, 9))); + $this->assertTrue($shape->is_point_in_shape(array(15, 10))); - $shape = new qtype_ddmarker_shape_polygon('15, 5; 20, 10; 20, 20; 10, 20; 10, 10'); - $this->assertTrue($shape->is_point_in_shape(array(15, 10))); + $shape = new qtype_ddmarker_shape_polygon('15, 5; 20, 10; 20, 20; 10, 20; 10, 10'); + $this->assertTrue($shape->is_point_in_shape(array(15, 10))); - $shape = new qtype_ddmarker_shape_polygon('15, 5; 20, 10; 20, 20; 10, 20; 10, 10'); - $this->assertFalse($shape->is_point_in_shape(array(25, 10))); + $shape = new qtype_ddmarker_shape_polygon('15, 5; 20, 10; 20, 20; 10, 20; 10, 10'); + $this->assertFalse($shape->is_point_in_shape(array(25, 10))); - $shape = new qtype_ddmarker_shape_polygon('0, 0; 500, 0; 600, 1000; 0, 1200; 10, 10'); - $this->assertTrue($shape->is_point_in_shape(array(25, 10))); + $shape = new qtype_ddmarker_shape_polygon('0, 0; 500, 0; 600, 1000; 0, 1200; 10, 10'); + $this->assertTrue($shape->is_point_in_shape(array(25, 10))); } public function test_circle_valdiation_test() { @@ -91,17 +90,17 @@ class qtype_ddmarker_shapes_test extends basic_testcase { } public function test_circle_hit_test() { - $shape = new qtype_ddmarker_shape_circle('10, 10; 10'); - $this->assertTrue($shape->is_point_in_shape(array(19, 10))); - $this->assertFalse($shape->is_point_in_shape(array(20, 10))); - $this->assertTrue($shape->is_point_in_shape(array(10, 1))); - $this->assertFalse($shape->is_point_in_shape(array(15, 25))); - $this->assertFalse($shape->is_point_in_shape(array(25, 15))); - $this->assertTrue($shape->is_point_in_shape(array(11, 11))); - $this->assertTrue($shape->is_point_in_shape(array(1, 10))); - $this->assertTrue($shape->is_point_in_shape(array(17, 17))); - $this->assertTrue($shape->is_point_in_shape(array(3, 3))); - $this->assertFalse($shape->is_point_in_shape(array(2, 2))); + $shape = new qtype_ddmarker_shape_circle('10, 10; 10'); + $this->assertTrue($shape->is_point_in_shape(array(19, 10))); + $this->assertFalse($shape->is_point_in_shape(array(20, 10))); + $this->assertTrue($shape->is_point_in_shape(array(10, 1))); + $this->assertFalse($shape->is_point_in_shape(array(15, 25))); + $this->assertFalse($shape->is_point_in_shape(array(25, 15))); + $this->assertTrue($shape->is_point_in_shape(array(11, 11))); + $this->assertTrue($shape->is_point_in_shape(array(1, 10))); + $this->assertTrue($shape->is_point_in_shape(array(17, 17))); + $this->assertTrue($shape->is_point_in_shape(array(3, 3))); + $this->assertFalse($shape->is_point_in_shape(array(2, 2))); } public function test_rectangle_valdiation_test() { @@ -110,13 +109,13 @@ class qtype_ddmarker_shapes_test extends basic_testcase { } public function test_rectangle_hit_test() { - $shape = new qtype_ddmarker_shape_rectangle('1000, 4000; 500, 400'); - $this->assertTrue($shape->is_point_in_shape(array(1001, 4001))); - $this->assertFalse($shape->is_point_in_shape(array(1000, 4000))); - $this->assertFalse($shape->is_point_in_shape(array(501, 3601))); - $this->assertTrue($shape->is_point_in_shape(array(1499, 4399))); - $this->assertFalse($shape->is_point_in_shape(array(25, 15))); - $this->assertTrue($shape->is_point_in_shape(array(1001, 4399))); - $this->assertTrue($shape->is_point_in_shape(array(1499, 4001))); + $shape = new qtype_ddmarker_shape_rectangle('1000, 4000; 500, 400'); + $this->assertTrue($shape->is_point_in_shape(array(1001, 4001))); + $this->assertFalse($shape->is_point_in_shape(array(1000, 4000))); + $this->assertFalse($shape->is_point_in_shape(array(501, 3601))); + $this->assertTrue($shape->is_point_in_shape(array(1499, 4399))); + $this->assertFalse($shape->is_point_in_shape(array(25, 15))); + $this->assertTrue($shape->is_point_in_shape(array(1001, 4399))); + $this->assertTrue($shape->is_point_in_shape(array(1499, 4001))); } } diff --git a/question/type/ddmarker/tests/walkthrough_test.php b/question/type/ddmarker/tests/walkthrough_test.php index 198e9633401..7f55debb165 100644 --- a/question/type/ddmarker/tests/walkthrough_test.php +++ b/question/type/ddmarker/tests/walkthrough_test.php @@ -36,10 +36,15 @@ require_once($CFG->dirroot . '/question/type/ddmarker/tests/helper.php'); * * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @group qtype_ddmarker */ class qtype_ddmarker_walkthrough_test extends qbehaviour_walkthrough_test_base { + /** + * Get an expectation that the output contains a marker. + * @param unknown $choice which choice. + * @param unknown $infinite whether there are infinitely many of that choice. + * @return question_contains_tag_with_attributes the expectation. + */ protected function get_contains_draggable_marker_home_expectation($choice, $infinite) { $class = 'draghome choice'.$choice; if ($infinite) { @@ -52,6 +57,10 @@ class qtype_ddmarker_walkthrough_test extends qbehaviour_walkthrough_test_base { return new question_contains_tag_with_attributes('span', $expectedattrs); } + /** + * (non-PHPdoc) + * @see qbehaviour_walkthrough_test_base::get_contains_hidden_expectation() + */ protected function get_contains_hidden_expectation($choiceno, $value = null) { $name = $this->quba->get_field_prefix($this->slot) .'c'. $choiceno; $expectedattributes = array('type' => 'hidden', 'name' => s($name)); @@ -694,8 +703,8 @@ class qtype_ddmarker_walkthrough_test extends qbehaviour_walkthrough_test_base { // Verify. $this->check_current_state(question_state::$complete); $this->check_current_mark(null); - $rightanswer = array($dd->get_right_choice_for(1)=>'50,50', - $dd->get_right_choice_for(2) =>'150,50', + $rightanswer = array($dd->get_right_choice_for(1) => '50,50', + $dd->get_right_choice_for(2) => '150,50', $dd->get_right_choice_for(3) => '100,150'); $this->check_current_output( $this->get_contains_hidden_expectation(1, $rightanswer[1]), diff --git a/question/type/ddmarker/yui/dd/dd.js b/question/type/ddmarker/yui/dd/dd.js index fbf332ebad2..ba62941a0fa 100644 --- a/question/type/ddmarker/yui/dd/dd.js +++ b/question/type/ddmarker/yui/dd/dd.js @@ -53,7 +53,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { return topnode.one('.dropbackground'); }, load_bg_img : function (url) { - dropbgarea.setContent(''); + dropbgarea.setContent(''); this.bg_img().on('load', this.on_image_load, this, 'bg_image'); }, drag_items : function() { @@ -63,7 +63,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { return dragitemsarea.all('span.dragitem.choice' + choiceno); }, drag_item_for_choice : function(choiceno, itemno) { - return dragitemsarea.one('span.dragitem.choice'+ choiceno + + return dragitemsarea.one('span.dragitem.choice' + choiceno + '.item' + itemno); }, drag_item_being_dragged : function(choiceno) { @@ -84,7 +84,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { if (patt1.test(classesarr[index])) { var patt2 = new RegExp('([0-9])+$'); var match = patt2.exec(classesarr[index]); - return +match[0]; + return Number(match[0]); } } } @@ -94,7 +94,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { return topnode.all('input.choices'); }, input_for_choice : function (choiceno) { - return topnode.one('input.choice'+choiceno); + return topnode.one('input.choice' + choiceno); }, marker_texts : function () { return topnode.one('div.markertexts'); @@ -117,16 +117,16 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { return colour; }, convert_to_window_xy : function (bgimgxy) { - return [+bgimgxy[0] + this.doc.bg_img().getX() + 1, - +bgimgxy[1] + this.doc.bg_img().getY() + 1]; + return [Number(bgimgxy[0]) + this.doc.bg_img().getX() + 1, + Number(bgimgxy[1]) + this.doc.bg_img().getY() + 1]; }, shapes : [], draw_drop_zone : function (dropzoneno, markertext, shape, coords, colour, link) { var existingmarkertext; if (link) { - existingmarkertext = this.doc.marker_texts().one('span.markertext'+dropzoneno+' a'); + existingmarkertext = this.doc.marker_texts().one('span.markertext' + dropzoneno + ' a'); } else { - existingmarkertext = this.doc.marker_texts().one('span.markertext'+dropzoneno); + existingmarkertext = this.doc.marker_texts().one('span.markertext' + dropzoneno); } if (existingmarkertext) { @@ -138,18 +138,18 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { } else if (markertext !== '') { var classnames = 'markertext markertext' + dropzoneno; if (link) { - this.doc.marker_texts().append('' + - markertext+''); + this.doc.marker_texts().append('' + + markertext + ''); } else { - this.doc.marker_texts().append('' + - markertext+''); + this.doc.marker_texts().append('' + + markertext + ''); } } - var drawfunc = 'draw_shape_'+shape; + var drawfunc = 'draw_shape_' + shape; if (this[drawfunc] instanceof Function){ var xyfortext = this[drawfunc](dropzoneno, coords, colour); if (xyfortext !== null) { - var markerspan = this.doc.top_node().one('div.ddarea div.markertexts span.markertext'+dropzoneno); + var markerspan = this.doc.top_node().one('div.ddarea div.markertexts span.markertext' + dropzoneno); if (markerspan !== null) { markerspan.setStyle('opacity', '0.6'); xyfortext[0] -= markerspan.get('offsetWidth') / 2; @@ -174,25 +174,25 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { draw_shape_circle : function (dropzoneno, coords, colour) { var coordsparts = coords.match(/(\d+),(\d+);(\d+)/); if (coordsparts && coordsparts.length === 4) { - var xy = [+coordsparts[1] - coordsparts[3], +coordsparts[2] - coordsparts[3]]; + var xy = [Number(coordsparts[1]) - coordsparts[3], Number(coordsparts[2]) - coordsparts[3]]; if (this.coords_in_img(xy)) { - var widthheight = [+coordsparts[3]*2, +coordsparts[3]*2]; + var widthheight = [Number(coordsparts[3]) * 2, Number(coordsparts[3]) * 2]; var shape = this.graphics.addShape({ type: 'circle', width: widthheight[0], height: widthheight[1], fill: { color: colour, - opacity : "0.5" + opacity: "0.5" }, stroke: { - weight:1, + weight: 1, color: "black" } }); shape.setXY(this.convert_to_window_xy(xy)); this.shapes[dropzoneno] = shape; - return [+coordsparts[1], +coordsparts[2]]; + return [Number(coordsparts[1]), Number(coordsparts[2])]; } } return null; @@ -200,25 +200,25 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { draw_shape_rectangle : function (dropzoneno, coords, colour) { var coordsparts = coords.match(/(\d+),(\d+);(\d+),(\d+)/); if (coordsparts && coordsparts.length === 5) { - var xy = [+coordsparts[1], +coordsparts[2]]; - var widthheight = [+coordsparts[3], +coordsparts[4]]; - if (this.coords_in_img([xy[0]+widthheight[0], xy[1]+widthheight[1]])) { + var xy = [Number(coordsparts[1]), Number(coordsparts[2])]; + var widthheight = [Number(coordsparts[3]), Number(coordsparts[4])]; + if (this.coords_in_img([xy[0] + widthheight[0], xy[1] + widthheight[1]])) { var shape = this.graphics.addShape({ type: 'rect', width: widthheight[0], height: widthheight[1], fill: { color: colour, - opacity : "0.5" + opacity: "0.5" }, stroke: { - weight:1, + weight: 1, color: "black" } }); shape.setXY(this.convert_to_window_xy(xy)); this.shapes[dropzoneno] = shape; - return [+xy[0]+widthheight[0]/2, +xy[1]+widthheight[1]/2]; + return [Number(xy[0]) + widthheight[0] / 2, Number(xy[1]) + widthheight[1] / 2]; } } return null; @@ -259,13 +259,13 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { polygon.lineTo(xy[i][0], xy[i][1]); } } - if (+xy[0][0] !== +xy[xy.length-1][0] || +xy[0][1] !== +xy[xy.length-1][1]) { - polygon.lineTo(xy[0][0], xy[0][1]); //close polygon if not already closed + if (Number(xy[0][0]) !== Number(xy[xy.length - 1][0]) || Number(xy[0][1]) !== Number(xy[xy.length - 1][1])) { + polygon.lineTo(xy[0][0], xy[0][1]); // Close polygon if not already closed. } polygon.end(); polygon.setXY(this.doc.bg_img().getXY()); this.shapes[dropzoneno] = polygon; - return [(minxy[0] + maxxy[0])/2, (minxy[1] + maxxy[1])/2]; + return [(minxy[0] + maxxy[0]) / 2, (minxy[1] + maxxy[1]) / 2]; } return null; }, @@ -306,7 +306,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { var drag = draghome.cloneNode(true); drag.removeClass('draghome'); drag.addClass('dragitem'); - drag.addClass('item'+ itemno); + drag.addClass('item' + itemno); drag.one('span.markertext').setStyle('opacity', 0.6); draghome.insert(drag, 'after'); if (!this.get('readonly')) { @@ -325,7 +325,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { var choiceno = this.get_choiceno_for_node(dragnode); var itemno = this.get_itemno_for_node(dragnode); if (itemno !== null) { - dragnode.removeClass('item'+dragnode); + dragnode.removeClass('item' + dragnode); } this.save_all_xy_for_choice(choiceno, null); this.redraw_drags_and_drops(); @@ -344,15 +344,15 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { save_all_xy_for_choice: function (choiceno, dropped) { var coords = []; var bgimgxy; - for (var i=0; i <= this.doc.drag_items_for_choice(choiceno).size(); i++) { + for (var i = 0; i <= this.doc.drag_items_for_choice(choiceno).size(); i++) { var dragitem = this.doc.drag_item_for_choice(choiceno, i); if (dragitem) { - dragitem.removeClass('item'+i); + dragitem.removeClass('item' + i); if (!dragitem.hasClass('beingdragged')) { bgimgxy = this.convert_to_bg_img_xy(dragitem.getXY()); if (this.xy_in_bgimg(bgimgxy)) { - dragitem.removeClass('item'+i); - dragitem.addClass('item'+coords.length); + dragitem.removeClass('item' + i); + dragitem.addClass('item' + coords.length); coords[coords.length] = bgimgxy; } } @@ -360,7 +360,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { } if (dropped !== null){ bgimgxy = this.convert_to_bg_img_xy(dropped.getXY()); - dropped.addClass('item'+coords.length); + dropped.addClass('item' + coords.length); if (this.xy_in_bgimg(bgimgxy)) { coords[coords.length] = bgimgxy; } @@ -393,8 +393,8 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { return this.convert_to_window_xy(bgimgxy); }, convert_to_bg_img_xy : function (windowxy) { - return [+windowxy[0] - this.doc.bg_img().getX()-1, - +windowxy[1] - this.doc.bg_img().getY()-1]; + return [Number(windowxy[0]) - this.doc.bg_img().getX() - 1, + Number(windowxy[1]) - this.doc.bg_img().getY() - 1]; }, redraw_drags_and_drops : function() { this.doc.drag_items().each(function(item) { @@ -406,7 +406,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { var choiceno = this.get_choiceno_for_node(input); var coords = this.get_coords(input); var dragitemhome = this.doc.drag_item_home(choiceno); - for (var i=0; i < coords.length; i++) { + for (var i = 0; i < coords.length; i++) { var dragitem = this.doc.drag_item_for_choice(choiceno, i); if (!dragitem || dragitem.hasClass('beingdragged')) { dragitem = this.clone_new_drag_item(dragitemhome, i); @@ -462,7 +462,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) { var coords = []; if (fv !== '') { var coordsstrings = fv.split(';'); - for (var i=0; i'+ - '
'+ - '
'+ - '
'+ - '
'+ + '
' + + '
' + + '
' + + '
' + + '
' + '
'); this.doc = this.doc_structure(this); this.stop_selector_events(); @@ -67,16 +67,16 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) { this.restart_colours(); this.graphics = new Y.Graphic({render:"div.ddarea div.dropzones"}); var noofdropzones = this.form.get_form_value('nodropzone', []); - for (var dropzoneno=0; dropzoneno < noofdropzones; dropzoneno++) { + for (var dropzoneno = 0; dropzoneno < noofdropzones; dropzoneno++) { var dragitemno = this.form.get_form_value('drops', [dropzoneno, 'choice']); var markertext = this.get_marker_text(dragitemno); var shape = this.form.get_form_value('drops', [dropzoneno, 'shape']); var coords = this.get_coords(dropzoneno); var colourfordropzone = this.get_next_colour(); - Y.one('input#id_drops_'+dropzoneno+'_coords') - .setStyle('background-color', colourfordropzone); + Y.one('input#id_drops_' + dropzoneno + '_coords') + .setStyle('background-color', colourfordropzone); this.draw_drop_zone(dropzoneno, markertext, - shape, coords, colourfordropzone, false); + shape, coords, colourfordropzone, false); } Y.one('div.ddarea .grid') .setXY(this.doc.bg_img().getXY()) @@ -89,8 +89,8 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) { return coords.replace(new RegExp("\\s*", 'g'), ''); }, get_marker_text : function (markerno) { - if (+markerno !== 0) { - var label = this.form.get_form_value('drags', [markerno-1, 'label']); + if (Number(markerno) !== 0) { + var label = this.form.get_form_value('drags', [markerno - 1, 'label']); return label.replace(new RegExp("^\\s*(.*)\\s*$"), "$1"); } else { return ''; @@ -98,7 +98,7 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) { }, set_options_for_drag_item_selectors : function () { var dragitemsoptions = {0: ''}; - for (var i=1; i <= this.form.get_form_value('noitems', []); i++) { + for (var i = 1; i <= this.form.get_form_value('noitems', []); i++) { var label = this.get_marker_text(i); if (label !== "") { dragitemsoptions[i] = Y.Escape.html(label); @@ -108,19 +108,17 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) { var selectedvalues = []; var selector; for (i = 0; i < this.form.get_form_value('nodropzone', []); i++) { - selector = Y.one('#id_drops_'+i+'_choice'); - selectedvalues[i] = +selector.get('value'); + selector = Y.one('#id_drops_' + i + '_choice'); + selectedvalues[i] = Number(selector.get('value')); } for (i = 0; i < this.form.get_form_value('nodropzone', []); i++) { - selector = Y.one('#id_drops_'+i+'_choice'); + selector = Y.one('#id_drops_' + i + '_choice'); // Remove all options for drag choice. selector.all('option').remove(true); // And recreate the options. for (var value in dragitemsoptions) { - value = +value; - var option = ''; + value = Number(value); + var option = ''; selector.append(option); var optionnode = selector.one('option[value="' + value + '"]'); // Is this the currently selected value? @@ -130,13 +128,13 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) { // It is not the currently selected value, is it selectable? if (value !== 0) { // The 'no item' option is always selectable. // Variables to hold form values about this drag item. - var noofdrags = this.form.get_form_value('drags', [value-1, 'noofdrags']); - if (noofdrags != 0) { // 'noofdrags == 0' means infinite. + var noofdrags = this.form.get_form_value('drags', [value - 1, 'noofdrags']); + if (Number(noofdrags) !== 0) { // 'noofdrags == 0' means infinite. // Go through all selected values in drop downs. for (var k in selectedvalues) { // Count down 'noofdrags' and if reach zero then set disabled option for this drag item. - if (+selectedvalues[k] === value) { - if (noofdrags == 1) { + if (Number(selectedvalues[k]) === value) { + if (Number(noofdrags) === 1) { optionnode.set('disabled', true); break; } else { @@ -180,7 +178,7 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) { form : { to_name_with_index : function(name, indexes) { var indexstring = name; - for (var i=0; i < indexes.length; i++) { + for (var i = 0; i < indexes.length; i++) { indexstring = indexstring + '[' + indexes[i] + ']'; } return indexstring;