Allow change answers for hotspots - refs #7705

1.10.x
Angel Fernando Quiroz Campos 9 years ago
parent 9cf92118c2
commit b35a767788
  1. 82
      main/exercice/exercise.class.php
  2. 21
      main/exercice/hotspot_actionscript.as.php
  3. 3
      main/inc/lib/exercise.lib.php
  4. 19
      main/inc/lib/javascript/hotspot/js/hotspot.js

@ -3026,39 +3026,43 @@ class Exercise
$totalScore += $answerWeighting;
}
} else {
$studentChoice = $choice[$answerAutoId];
$choiceIsValid = false;
if (!empty($studentChoice)) {
$hotspotType = $objAnswerTmp->selectHotspotType($answerId);
$hotspotCoordinates = $objAnswerTmp->selectHotspotCoordinates($answerId);
$choicePoint = Geometry::decodePoint($studentChoice);
switch ($hotspotType) {
case 'square':
$hotspotProperties = Geometry::decodeSquare($hotspotCoordinates);
$choiceIsValid = Geometry::pointIsInSquare($hotspotProperties, $choicePoint);
break;
case 'circle':
$hotspotProperties = Geometry::decodeEllipse($hotspotCoordinates);
$choiceIsValid = Geometry::pointIsInEllipse($hotspotProperties, $choicePoint);
break;
case 'poly':
$hotspotProperties = Geometry::decodePolygon($hotspotCoordinates);
$choiceIsValid = Geometry::pointIsInPolygon($hotspotProperties, $choicePoint);
break;
if (!isset($choice[$answerAutoId])) {
$choice[$answerAutoId] = 0;
} else {
$studentChoice = $choice[$answerAutoId];
$choiceIsValid = false;
if (!empty($studentChoice)) {
$hotspotType = $objAnswerTmp->selectHotspotType($answerId);
$hotspotCoordinates = $objAnswerTmp->selectHotspotCoordinates($answerId);
$choicePoint = Geometry::decodePoint($studentChoice);
switch ($hotspotType) {
case 'square':
$hotspotProperties = Geometry::decodeSquare($hotspotCoordinates);
$choiceIsValid = Geometry::pointIsInSquare($hotspotProperties, $choicePoint);
break;
case 'circle':
$hotspotProperties = Geometry::decodeEllipse($hotspotCoordinates);
$choiceIsValid = Geometry::pointIsInEllipse($hotspotProperties, $choicePoint);
break;
case 'poly':
$hotspotProperties = Geometry::decodePolygon($hotspotCoordinates);
$choiceIsValid = Geometry::pointIsInPolygon($hotspotProperties, $choicePoint);
break;
}
}
}
$choice[$answerAutoId] = 0;
$choice[$answerAutoId] = 0;
if ($choiceIsValid) {
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
$choice[$answerAutoId] = 1;
if ($choiceIsValid) {
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
$choice[$answerAutoId] = 1;
}
}
}
break;
@ -4058,12 +4062,28 @@ class Exercise
Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
// } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) {
} elseif ($answerType == HOT_SPOT) {
Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
$answer = [];
if (isset($exerciseResultCoordinates[$questionId]) && !empty($exerciseResultCoordinates[$questionId])) {
Database::delete(
Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT),
[
'hotspot_exe_id = ? AND hotspot_question_id = ? AND c_id = ?' => [
$exeId,
$questionId,
api_get_course_int_id()
]
]
);
foreach ($exerciseResultCoordinates[$questionId] as $idx => $val) {
$answer[] = $val;
Event::saveExerciseAttemptHotspot($exeId, $quesId, $idx, $choice[$idx], $val, false, $this->id);
}
}
Event::saveQuestionAttempt($questionScore, implode('|', $answer), $quesId, $exeId, 0, $this->id);
} else {
Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0,$this->id);
}

@ -10,10 +10,12 @@
session_cache_limiter("none");
include('../inc/global.inc.php');
require '../inc/global.inc.php';
require api_get_path(LIBRARY_PATH) . 'geometry.lib.php';
// set vars
$questionId = intval($_GET['modifyAnswers']);
$exerciseId = isset($_GET['exe_id']) ? intval($_GET['exe_id']) : 0;
$objQuestion = Question::read($questionId);
$answer_type = $objQuestion->selectType(); //very important
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
@ -62,6 +64,7 @@ $data['image_width'] = $pictureWidth;
$data['image_height'] = $pictureHeight;
$data['courseCode'] = $_course['path'];
$data['hotspots'] = [];
$data['answers'] = [];
$nmbrTries = 0;
@ -108,9 +111,23 @@ while ($hotspot = Database::fetch_assoc($result))
$data['hotspots'][] = $hotSpot;
}
$attemptList = Event::getAllExerciseEventByExeId($exerciseId);
if (!empty($attemptList)) {
$questionAttempt = $attemptList[$questionId][0];
if (!empty($questionAttempt['answer'])) {
$coordinates = explode('|', $questionAttempt['answer']);
foreach ($coordinates as $coordinate) {
$data['answers'][] = Geometry::decodePoint($coordinate);
}
}
}
$data['nmbrTries'] = $nmbrTries;
$data['done'] = 'done';
header('Content-Type: application/json');
echo json_encode($data, JSON_PRETTY_PRINT);
echo json_encode($data);

@ -1083,7 +1083,7 @@ HTML;
return $s;
}
} elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) {
global $exerciseId;
global $exerciseId, $exe_id;
// Question is a HOT_SPOT
//checking document/images visibility
if (api_is_platform_admin() || api_is_course_admin()) {
@ -1192,6 +1192,7 @@ HOTSPOT;
$(document).on('ready', function () {
new " . ($answerType == HOT_SPOT_DELINEATION ? 'DelineationQuestion' : 'HotspotQuestion') . "({
questionId: $questionId,
exerciseId: $exe_id,
selector: '#question_div_' + $questionId + ' .hotspot-image',
for: 'user'
});

@ -783,12 +783,12 @@ window.HotspotQuestion = (function () {
lang = questionInfo.lang;
};
var UserHotspotsSVG = function (hotspotsCollection, image) {
var UserHotspotsSVG = function (hotspotsCollection, answersCollection, image) {
var self = this;
this.el = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
this.hotspotsCollection = hotspotsCollection;
this.answersCollection = new AnswersCollection();
this.answersCollection = answersCollection;
this.image = image;
this.answersCollection.onAdd(function (answerModel) {
@ -933,7 +933,8 @@ window.HotspotQuestion = (function () {
var image = new Image();
image.onload = function () {
var hotspotsCollection = new HotspotsCollection(),
hotspotsSVG = new UserHotspotsSVG(hotspotsCollection, this);
answersCollection = new AnswersCollection(),
hotspotsSVG = new UserHotspotsSVG(hotspotsCollection, answersCollection, this);
$(config.selector).css('width', this.width).append(hotspotsSVG.render().el);
@ -967,6 +968,15 @@ window.HotspotQuestion = (function () {
hotspotsCollection.add(hotspot);
});
$.each(questionInfo.answers, function (index, answerInfo) {
var answerModel = new AnswerModel({
x: answerInfo.x,
y: answerInfo.y
});
answersCollection.add(answerModel);
});
$(config.selector).parent().find('#hotspot-messages-' + config.questionId + ' span:not(.fa)')
.text(
lang.NextAnswer + ' ' + hotspotsCollection.get(0).name
@ -1116,7 +1126,8 @@ window.HotspotQuestion = (function () {
case 'user':
xhrQuestion = $.getJSON('/main/exercice/hotspot_actionscript.as.php', {
modifyAnswers: parseInt(config.questionId)
modifyAnswers: parseInt(config.questionId),
exe_id: parseInt(config.exerciseId)
});
break;

Loading…
Cancel
Save