You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
4.9 KiB
166 lines
4.9 KiB
<?php
|
|
|
|
/* For licensing terms, see /license.txt */
|
|
|
|
use Chamilo\CoreBundle\Framework\Container;
|
|
use Chamilo\CourseBundle\Entity\CQuizQuestion;
|
|
use ChamiloSession as Session;
|
|
|
|
/*
|
|
* This file generates the ActionScript variables code used by the HotSpot .swf.
|
|
*
|
|
* @package chamilo.exercise
|
|
*
|
|
* @author Toon Keppens
|
|
*
|
|
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
|
|
*/
|
|
session_cache_limiter('none');
|
|
|
|
require_once __DIR__.'/../inc/global.inc.php';
|
|
|
|
api_protect_course_script(true);
|
|
|
|
$_course = api_get_course_info();
|
|
require api_get_path(LIBRARY_PATH).'geometry.lib.php';
|
|
|
|
// set vars
|
|
$questionId = (int) $_GET['modifyAnswers'];
|
|
$exerciseId = isset($_GET['exe_id']) ? (int) $_GET['exe_id'] : 0;
|
|
$questionRepo = Container::getQuestionRepository();
|
|
/** @var CQuizQuestion $objQuestion */
|
|
$objQuestion = $questionRepo->find($questionId);
|
|
|
|
$answer_type = $objQuestion->getType(); //very important
|
|
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
|
|
|
|
$resourceFile = $objQuestion->getResourceNode()->getResourceFile();
|
|
$pictureWidth = $resourceFile->getWidth();
|
|
$pictureHeight = $resourceFile->getHeight();
|
|
$imagePath = $questionRepo->getHotSpotImageUrl($objQuestion);
|
|
|
|
$course_id = api_get_course_int_id();
|
|
|
|
// Query db for answers
|
|
if (HOT_SPOT_DELINEATION == $answer_type) {
|
|
$sql = "SELECT iid, id, answer, hotspot_coordinates, hotspot_type, ponderation
|
|
FROM $TBL_ANSWERS
|
|
WHERE
|
|
c_id = $course_id AND
|
|
question_id = $questionId AND
|
|
hotspot_type = 'delineation'
|
|
ORDER BY iid";
|
|
} else {
|
|
$sql = "SELECT iid, id, answer, hotspot_coordinates, hotspot_type, ponderation
|
|
FROM $TBL_ANSWERS
|
|
WHERE c_id = $course_id AND question_id = $questionId
|
|
ORDER BY position";
|
|
}
|
|
$result = Database::query($sql);
|
|
|
|
$data = [];
|
|
$data['type'] = 'user';
|
|
$data['lang'] = [
|
|
'Square' => get_lang('Square'),
|
|
'Ellipse' => get_lang('Ellipse'),
|
|
'Polygon' => get_lang('Polygon'),
|
|
'HotspotStatus1' => get_lang('HotspotStatus1'),
|
|
'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
|
|
'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
|
|
'HotspotStatus3' => get_lang('HotspotStatus3'),
|
|
'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
|
|
'ShowHotspots' => get_lang('ShowHotspots'),
|
|
'Triesleft' => get_lang('Triesleft'),
|
|
'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
|
|
'NextAnswer' => get_lang('NextAnswer'),
|
|
'Delineation' => get_lang('Delineation'),
|
|
'CloseDelineation' => get_lang('CloseDelineation'),
|
|
'Oar' => get_lang('Oar'),
|
|
'ClosePolygon' => get_lang('ClosePolygon'),
|
|
'DelineationStatus1' => get_lang('DelineationStatus1'),
|
|
];
|
|
$data['image'] = $imagePath;
|
|
$data['image_width'] = $pictureWidth;
|
|
$data['image_height'] = $pictureHeight;
|
|
$data['courseCode'] = $_course['path'];
|
|
$data['hotspots'] = [];
|
|
$data['answers'] = [];
|
|
|
|
$nmbrTries = 0;
|
|
|
|
while ($hotspot = Database::fetch_assoc($result)) {
|
|
$hotSpot = [];
|
|
$hotSpot['id'] = $hotspot['id'];
|
|
$hotSpot['iid'] = $hotspot['iid'];
|
|
$hotSpot['answer'] = $hotspot['answer'];
|
|
|
|
// Square or rectancle
|
|
if ('square' == $hotspot['hotspot_type']) {
|
|
$hotSpot['type'] = 'square';
|
|
}
|
|
// Circle or ovale
|
|
if ('circle' == $hotspot['hotspot_type']) {
|
|
$hotSpot['type'] = 'circle';
|
|
}
|
|
// Polygon
|
|
if ('poly' == $hotspot['hotspot_type']) {
|
|
$hotSpot['type'] = 'poly';
|
|
}
|
|
// Delineation
|
|
if ('delineation' == $hotspot['hotspot_type']) {
|
|
$hotSpot['type'] = 'delineation';
|
|
}
|
|
// No error
|
|
if ('noerror' == $hotspot['hotspot_type']) {
|
|
$hotSpot['type'] = 'noerror';
|
|
}
|
|
|
|
// This is a good answer, count + 1 for nmbr of clicks
|
|
if ($hotspot['hotspot_type'] > 0) {
|
|
$nmbrTries++;
|
|
}
|
|
|
|
$hotSpot['coord'] = $hotspot['hotspot_coordinates'];
|
|
$data['hotspots'][] = $hotSpot;
|
|
}
|
|
|
|
$attemptList = Event::getAllExerciseEventByExeId($exerciseId);
|
|
|
|
if (!empty($attemptList)) {
|
|
if (isset($attemptList[$questionId])) {
|
|
$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';
|
|
|
|
if (Session::has("hotspot_ordered$questionId")) {
|
|
$tempHotspots = [];
|
|
$hotspotOrdered = Session::read("hotspot_ordered$questionId");
|
|
|
|
foreach ($hotspotOrdered as $hotspotOrder) {
|
|
foreach ($data['hotspots'] as $hotspot) {
|
|
if ($hotspot['id'] != $hotspotOrder) {
|
|
continue;
|
|
}
|
|
|
|
$tempHotspots[] = $hotspot;
|
|
}
|
|
}
|
|
|
|
$data['hotspots'] = $tempHotspots;
|
|
|
|
Session::erase("hotspot_ordered$questionId");
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode($data);
|
|
|