MDL-47494 ddmarker: NOBUG made a start to validation of shape coords saved and also at the same time

a start on code to interpret the coords for use in hit detection.
This commit is contained in:
Jamie Pratt
2011-10-05 20:11:54 +07:00
parent ae674bd250
commit 8aae74a457
2 changed files with 33 additions and 4 deletions
+31 -3
View File
@@ -91,14 +91,16 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
return array();
}
protected function shapes() {
return array('circle', 'rectangle', 'polygon');
}
protected function drop_zone($mform, $imagerepeats) {
$dropzoneitem = array();
$grouparray = array();
foreach (array('circle', 'rectangle', 'polygon') as $shape) {
foreach ($this->shapes as $shape) {
$shapearray[$shape] = get_string('shape_'.$shape, 'qtype_ddmarker');
}
$grouparray[] = $mform->createElement('select', 'shape',
@@ -208,7 +210,8 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (!self::file_uploaded($data['bgimage'])) {
$bgimagesize = $this->get_image_size_in_draft_area($data['bgimage']);
if ($bgimagesize === null) {
$errors["bgimage"] = get_string('formerror_nobgimage', 'qtype_ddmarker');
}
@@ -220,6 +223,11 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
if ($choicepresent) {
//test coords here
if ($bgimagesize !== null) {
if (in_array($data['drops'][$i]['shape'], $this->shapes())) {
}
}
} else {
@@ -239,4 +247,24 @@ class qtype_ddmarker_edit_form extends qtype_ddtoimage_edit_form_base {
}
return $errors;
}
public function get_image_size_in_draft_area($draftitemid) {
global $USER;
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
$fs = get_file_storage();
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id');
if ($draftfiles) {
foreach ($draftfiles as $file) {
if ($file->is_directory()) {
continue;
}
//just return the data for the first good file, there should only be one.
$imageinfo = $file->get_imageinfo();
$width = $imageinfo['width'];
$height = $imageinfo['height'];
return array($width, $height);
}
}
return null;
}
}
+2 -1
View File
@@ -27,6 +27,7 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/type/ddimageortext/questionbase.php');
require_once($CFG->dirroot . '/question/type/ddmarker/shapes.php');
/**
@@ -93,4 +94,4 @@ class qtype_ddmarker_drop_zone {
}
return $summariseplace;
}
}
}