MDL-47494 ddmarker: NOBUG implemented 'Fill in correct responses'

This commit is contained in:
Jamie Pratt
2011-11-16 16:01:47 +07:00
parent 457c35b3dc
commit bcbe321a87
2 changed files with 46 additions and 0 deletions
+27
View File
@@ -210,6 +210,7 @@ class qtype_ddmarker_question extends qtype_ddtoimage_question_base {
return $choicekey;
}
}
return null;
}
public function grade_response(array $response) {
list($right, $total) = $this->get_num_parts_right($response);
@@ -278,6 +279,28 @@ class qtype_ddmarker_question extends qtype_ddtoimage_question_base {
}
return $parts;
}
public function get_correct_response() {
$responsecoords = array();
foreach ($this->places as $placeno => $place) {
$rightchoice = $this->get_right_choice_for($placeno);
if ($rightchoice !== null) {
$rightchoicekey = $this->choice($rightchoice);
$correctcoords = $place->correct_coords();
if ($correctcoords !== null) {
if (!isset($responsecoords[$rightchoicekey])) {
$responsecoords[$rightchoicekey] = array();
}
$responsecoords[$rightchoicekey][] = join(',', $correctcoords);
}
}
}
$response = array();
foreach ($responsecoords as $choicekey => $coords) {
$response[$choicekey] = join(';', $coords);
}
return $response;
}
}
/**
@@ -329,4 +352,8 @@ class qtype_ddmarker_drop_zone {
public function drop_hit($xy) {
return $this->shape->is_point_in_shape($xy);
}
public function correct_coords() {
return $this->shape->center_point();
}
}
+19
View File
@@ -39,6 +39,8 @@ abstract class qtype_ddmarker_shape {
}
abstract protected function outlying_coords_to_test();
abstract public function center_point();
protected function is_only_numbers() {
$args = func_get_args();
foreach ($args as $arg) {
@@ -153,6 +155,10 @@ class qtype_ddmarker_shape_rectangle extends qtype_ddmarker_shape {
return $this->is_point_in_bounding_box($xy, array($this->xleft, $this->ytop),
array($this->xleft + $this->width, $this->ytop + $this->height));
}
public function center_point() {
return array($this->xleft + round($this->width / 2),
$this->ytop + round($this->height / 2));
}
}
class qtype_ddmarker_shape_circle extends qtype_ddmarker_shape {
@@ -191,6 +197,9 @@ class qtype_ddmarker_shape_circle extends qtype_ddmarker_shape {
+ pow(($xy[1] - $this->ycentre), 2));
return $distancefromcentre < $this->radius;
}
public function center_point() {
return array($this->xcentre, $this->ycentre);
}
}
class qtype_ddmarker_shape_polygon extends qtype_ddmarker_shape {
/**
@@ -327,6 +336,16 @@ class qtype_ddmarker_shape_polygon extends qtype_ddmarker_shape {
}
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));
if ($this->is_point_in_shape($center)) {
return $center;
} else {
return null;
}
}
}
class qtype_ddmarker_point {
public $x;