MDL-47494 ddmarker: Fix lots of coding style issues.

This commit is contained in:
Tim Hunt
2014-11-28 18:41:27 +00:00
parent 9398fc3478
commit f8bb5fdc2e
20 changed files with 256 additions and 242 deletions
@@ -15,9 +15,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Backup code for qtype_ddmarker.
*
* @package qtype_ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <[email protected]>
* @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';
}
@@ -15,17 +15,18 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Restore code for qtype_ddmarker.
*
* @package qtype_ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <[email protected]>
* @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
+20 -10
View File
@@ -15,21 +15,20 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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 <[email protected]>
* @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}])) {
+1 -3
View File
@@ -15,15 +15,13 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* ddmarker question type upgrade code.
* Ddmarker question type upgrade code.
*
* @package qtype_ddmarker
* @copyright 2013 The Open University
* @author Jamie Pratt [email protected]
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
+10 -11
View File
@@ -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}]"]
@@ -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;
@@ -15,12 +15,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
*
* @package qtype
* @subpackage ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <[email protected]>
* @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<br>for example: `80, 100; 50`
* Polygon: x1, y1; x2, y2; ...; xn, yn<br>for example: `20, 60; 100, 60; 20, 100`
* Rectangle: left, top, width, height<br>for example: `20, 60; 80, 40`';
* Circle: centre_x, centre_y; radius<br>for example: <code>80, 100; 50</code>
* Polygon: x1, y1; x2, y2; ...; xn, yn<br>for example: <code>20, 60; 100, 60; 20, 100</code>
* Rectangle: left, top, width, height<br>for example: <code>20, 60; 80, 40</code>';
$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).<br /> 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.';
+6 -7
View File
@@ -15,16 +15,14 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Serve question type files
* Serve question type files.
*
* @package qtype
* @subpackage ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package qtype_ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <[email protected]>
* @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',
+1 -3
View File
@@ -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 <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+11 -5
View File
@@ -14,15 +14,21 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
}
+5 -5
View File
@@ -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);
+14 -15
View File
@@ -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) {
+2 -3
View File
@@ -15,11 +15,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Admin settings for qtype_ddmarker.
*
* @package qtype
* @subpackage ddmarker
* @package qtype_ddmarker
* @copyright 2012 The Open University
* @author Jamie Pratt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+30 -32
View File
@@ -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);
}
}
@@ -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')));
@@ -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. */
+55 -56
View File
@@ -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)));
}
}
@@ -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]),
+44 -44
View File
@@ -53,7 +53,7 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) {
return topnode.one('.dropbackground');
},
load_bg_img : function (url) {
dropbgarea.setContent('<img class="dropbackground" src="'+ url +'"/>');
dropbgarea.setContent('<img class="dropbackground" src="' + url + '"/>');
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('<span class="'+classnames+'"><a href="#">' +
markertext+'</a></span>');
this.doc.marker_texts().append('<span class="' + classnames + '"><a href="#">' +
markertext + '</a></span>');
} else {
this.doc.marker_texts().append('<span class="'+classnames+'">' +
markertext+'</span>');
this.doc.marker_texts().append('<span class="' + classnames + '">' +
markertext + '</span>');
}
}
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<coordsstrings.length; i++) {
for (var i = 0; i < coordsstrings.length; i++) {
coords[coords.length] = this.convert_to_window_xy(coordsstrings[i].split(','));
}
}
@@ -474,19 +474,19 @@ YUI.add('moodle-qtype_ddmarker-dd', function(Y) {
},
drag_home_xy : function (choiceno) {
var dragitemhome = this.doc.drag_item_home(choiceno);
return [dragitemhome.getX(), dragitemhome.getY()-12];
return [dragitemhome.getX(), dragitemhome.getY() - 12];
},
get_choiceno_for_node : function(node) {
return +this.doc.get_classname_numeric_suffix(node, 'choice');
return Number(this.doc.get_classname_numeric_suffix(node, 'choice'));
},
get_itemno_for_node : function(node) {
return +this.doc.get_classname_numeric_suffix(node, 'item');
return Number(this.doc.get_classname_numeric_suffix(node, 'item'));
},
get_noofdrags_for_node : function(node) {
return +this.doc.get_classname_numeric_suffix(node, 'noofdrags');
return Number(this.doc.get_classname_numeric_suffix(node, 'noofdrags'));
},
//----------- keyboard accessibility stuff below line ---------------------
// Keyboard accessibility stuff below here.
drop_zone_key_press : function (e) {
var dragitem = e.target;
var xy = dragitem.getXY();
+22 -24
View File
@@ -13,11 +13,11 @@ YUI.add('moodle-qtype_ddmarker-form', function(Y) {
this.fp = this.file_pickers();
var tn = Y.one(this.get('topnode'));
tn.one('div.fcontainer').append(
'<div class="ddarea">'+
'<div class="markertexts"></div>'+
'<div class="droparea"></div>'+
'<div class="dropzones"></div>'+
'<div class="grid"></div>'+
'<div class="ddarea">' +
'<div class="markertexts"></div>' +
'<div class="droparea"></div>' +
'<div class="dropzones"></div>' +
'<div class="grid"></div>' +
'</div>');
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 = '<option value="'+ value +'">'
+ dragitemsoptions[value] +
'</option>';
value = Number(value);
var option = '<option value="' + value + '">' + dragitemsoptions[value] + '</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;