Fix hotspot creation see BT#2766

pull/2837/head
Julio Montoya 6 years ago
parent 3cd2b770cd
commit bcef335270
  1. 17
      assets/js/app.js
  2. 4
      main/exercise/exercise.class.php
  3. 4
      main/exercise/exercise_show.php
  4. 8
      main/exercise/hotspot.class.php
  5. 13
      main/exercise/hotspot_actionscript.as.php
  6. 17
      main/exercise/hotspot_actionscript_admin.as.php
  7. 2
      main/exercise/hotspot_admin.inc.php
  8. 21
      main/exercise/hotspot_answers.as.php
  9. 2
      main/exercise/oral_expression.class.php
  10. 109
      main/exercise/question.class.php
  11. 2
      main/inc/lib/exercise.lib.php
  12. 46
      main/inc/lib/javascript/hotspot/js/hotspot.js

@ -1,3 +1,5 @@
/* For licensing terms, see /license.txt */
// Load symfony routes in order to use it in a js
const routes = require('../../public/js/fos_js_routes.json');
import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';
@ -27,7 +29,10 @@ var disconnect_lang = '{{ "ChatDisconnected"|get_lang }}';*/
var connect_lang = 'ChatConnected';
var disconnect_lang = 'ChatDisconnected';
$( document ).ready(function() {
$(function() {
var webCidReq = '&cidReq=' + $('body').attr('data-course-code');
window.webCidReq = webCidReq;
$("#menu_courses").click(function(){
return false;
});
@ -37,8 +42,7 @@ $( document ).ready(function() {
$("#menu_administrator").click(function(){
return false;
});
});
$(function() {
var isInCourse = $("body").data("in-course");
if (isInCourse == true) {
var courseCode = $("body").data("course-code");
@ -603,8 +607,6 @@ if (typeof CKEDITOR !== 'undefined') {
};
}
function addMainEvent(elm, evType, fn, useCapture)
{
if (elm.addEventListener) {
@ -626,10 +628,7 @@ function copyTextToClipBoard(elementId)
copyText.select();
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
//alert('Copied');
document.execCommand('copy');
}
// Expose functions to be use inside chamilo.

@ -3491,7 +3491,7 @@ class Exercise
$orderedHotspots = $em->getRepository('ChamiloCoreBundle:TrackEHotspot')->findBy(
[
'hotspotQuestionId' => $questionId,
'cId' => $course_id,
'course' => $course_id,
'hotspotExeId' => $exeId,
],
['hotspotAnswerId' => 'ASC']
@ -5579,7 +5579,7 @@ class Exercise
<p><em>".get_lang('HotSpot')."</em></p>
<div id=\"hotspot-solution-$questionId\"></div>
<script>
$(document).on('ready', function () {
$(function() {
new HotspotQuestion({
questionId: $questionId,
exerciseId: {$this->id},

@ -489,7 +489,7 @@ foreach ($questionList as $questionId) {
<td colspan=\"2\">
<div id=\"hotspot-solution-$questionId-$id\"></div>
<script>
$(document).on('ready', function () {
$(function() {
new HotspotQuestion({
questionId: $questionId,
exerciseId: {$objExercise->id},
@ -658,7 +658,7 @@ foreach ($questionList as $questionId) {
<td colspan=\"2\">
<div id=\"hotspot-solution\"></div>
<script>
$(document).on('ready', function () {
$(function() {
new HotspotQuestion({
questionId: $questionId,
exerciseId: {$objExercise->id},

@ -77,17 +77,15 @@ class HotSpot extends Question
*/
public function processCreation($form, $exercise)
{
$file_info = $form->getSubmitValue('imageUpload');
$fileInfo = $form->getSubmitValue('imageUpload');
parent::processCreation($form, $exercise);
if (!empty($file_info['tmp_name'])) {
$result = $this->uploadPicture($file_info['tmp_name']);
if (!empty($fileInfo['tmp_name'])) {
$result = $this->uploadPicture($fileInfo);
if ($result) {
$this->save($exercise);
return true;
} else {
return false;
}
}

@ -12,9 +12,11 @@ use ChamiloSession as Session;
*
* @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
*/
session_cache_limiter("none");
session_cache_limiter('none');
require_once __DIR__.'/../inc/global.inc.php';
$_course = api_get_course_info();
require api_get_path(LIBRARY_PATH).'geometry.lib.php';
// set vars
@ -23,12 +25,11 @@ $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);
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
$picture = $objQuestion->getPicture();
$pictureName = $objQuestion->getPictureFilename();
$pictureSize = getimagesize($picturePath.'/'.$pictureName);
$pictureWidth = $pictureSize[0];
$pictureHeight = $pictureSize[1];
$pictureWidth = $picture->getResourceNode()->getResourceFile()->getMedia()->getWidth();
$pictureHeight = $picture->getResourceNode()->getResourceFile()->getMedia()->getHeight();
$course_id = api_get_course_int_id();
// Query db for answers

@ -21,17 +21,20 @@ if (!$isAllowedToEdit) {
exit;
}
// set vars
$questionId = intval($_GET['modifyAnswers']);
$objQuestion = Question::read($questionId);
$_course = api_get_course_info();
$questionId = (int) $_GET['modifyAnswers'];
$objQuestion = Question::read($questionId);
$picture = $objQuestion->getPicture();
$publicPath = api_get_path(WEB_PUBLIC_PATH);
$courseCode = $_course['code'];
$path = $picture->getPath();
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
$pictureName = $objQuestion->getPictureFilename();
$pictureSize = getimagesize($picturePath.'/'.$pictureName);
$pictureWidth = $pictureSize[0];
$pictureHeight = $pictureSize[1];
$pictureWidth = $picture->getResourceNode()->getResourceFile()->getMedia()->getWidth();
$pictureHeight = $picture->getResourceNode()->getResourceFile()->getMedia()->getHeight();
$data = [];
$data['type'] = 'admin';

@ -1109,7 +1109,7 @@ if (isset($modifyAnswers)) {
</div>
</form>
<script>
$(document).on('ready', function () {
$(function() {
<?php if ($answerType == HOT_SPOT_DELINEATION) {
?>
new DelineationQuestion({

@ -15,6 +15,7 @@ require_once __DIR__.'/../inc/global.inc.php';
api_protect_course_script();
$_course = api_get_course_info();
$questionId = isset($_GET['modifyAnswers']) ? (int) $_GET['modifyAnswers'] : 0;
$exerciseId = isset($_GET['exerciseId']) ? (int) $_GET['exerciseId'] : 0;
$exeId = isset($_GET['exeId']) ? (int) $_GET['exeId'] : 0;
@ -61,9 +62,21 @@ $em = Database::getManager();
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
$pictureName = $objQuestion->getPictureFilename();
$pictureSize = getimagesize($picturePath.'/'.$pictureName);
$pictureWidth = $pictureSize[0];
$pictureHeight = $pictureSize[1];
$picture = $objQuestion->getPicture();
$publicPath = api_get_path(WEB_PUBLIC_PATH);
$courseCode = $_course['code'];
$path = $picture->getPath();
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
$pictureName = $objQuestion->getPictureFilename();
//$pictureSize = getimagesize($picturePath.'/'.$pictureName);
$pictureWidth = $picture->getResourceNode()->getResourceFile()->getMedia()->getWidth();
$pictureHeight = $picture->getResourceNode()->getResourceFile()->getMedia()->getHeight();
$data = [];
$data['type'] = 'solution';
@ -198,7 +211,7 @@ $rs = $em
->findBy(
[
'hotspotQuestionId' => $questionId,
'cId' => $courseId,
'course' => $courseId,
'hotspotExeId' => $exeId,
],
['hotspotAnswerId' => 'ASC']

@ -151,7 +151,7 @@ class OralExpression extends Question
'userId' => $this->userId,
'questionId' => $this->id,
'sessionId' => $this->sessionId,
'cId' => $this->course['real_id'],
'course' => $this->course['real_id'],
]);
if (!$result) {

@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Entity\CQuizAnswer;
/**
@ -391,6 +392,42 @@ abstract class Question
return $documentFilename;
}
/**
* @param int $courseId
* @param int $sessionId
*
* @return false|CDocument
*/
public function getPicture($courseId = 0, $sessionId = 0)
{
$courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId;
$sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId;
if (empty($courseId)) {
return false;
}
$pictureId = $this->getPictureId();
$courseInfo = $this->course;
$documentInfo = DocumentManager::get_document_data_by_id(
$pictureId,
$courseInfo['code'],
false,
$sessionId
);
if ($documentInfo) {
$em = Database::getManager();
/** @var CDocument $document */
$document = $em->getRepository('ChamiloCourseBundle:CDocument')->find($documentInfo['iid']);
return $document;
}
return false;
}
/**
* returns the array with the exercise ID list.
*
@ -664,7 +701,7 @@ abstract class Question
*
* @param array $courseInfo
*
* @return string
* @return CDocument
*/
public function getHotSpotFolderInCourse($courseInfo = [])
{
@ -678,23 +715,21 @@ abstract class Question
$pictureAbsolutePath = api_get_path(SYS_COURSE_PATH).$courseInfo['directory'].'/document/images/';
$picturePath = basename($pictureAbsolutePath);
if (!is_dir($picturePath)) {
create_unexisting_directory(
$courseInfo,
api_get_user_id(),
0,
0,
0,
dirname($pictureAbsolutePath),
'/'.$picturePath,
$picturePath,
'',
false,
false
);
}
$folder = create_unexisting_directory(
$courseInfo,
api_get_user_id(),
0,
0,
0,
dirname($pictureAbsolutePath),
'/'.$picturePath,
$picturePath,
'',
false,
false
);
return $pictureAbsolutePath;
return $folder;
}
/**
@ -708,29 +743,34 @@ abstract class Question
*/
public function uploadPicture($picture)
{
$picturePath = $this->getHotSpotFolderInCourse();
$folder = $this->getHotSpotFolderInCourse();
// if the question has got an ID
if ($this->id) {
$pictureFilename = self::generatePictureName();
$img = new Image($picture);
$img->send_image($picturePath.'/'.$pictureFilename, -1, 'jpg');
$document = DocumentManager::addDocument(
$this->course,
'/images/'.$pictureFilename,
'file',
filesize($picturePath.'/'.$pictureFilename),
$pictureFilename
if ($folder && $this->id) {
$pictureFilename = $this->generatePictureName();
$document = DocumentManager::upload_document(
['imageUpload' => $picture],
'/images',
'',
'',
false,
'overwrite',
false,
true,
'imageUpload',
true,
$folder->getId()
);
if ($document) {
$this->picture = $document->getId();
$this->picture = $document->getIid();
if (!file_exists($picturePath.'/'.$pictureFilename)) {
/*if (!file_exists($picturePath.'/'.$pictureFilename)) {
return false;
}
}*/
$this->resizePicture('width', 800);
//$this->resizePicture('width', 800);
return true;
}
@ -2420,4 +2460,9 @@ abstract class Question
return false;
}
public function getHotSpotData()
{
}
}

@ -1488,7 +1488,7 @@ HOTSPOT;
$s .= "<div class=\"col-sm-8 col-md-9\">
<div class=\"hotspot-image\"></div>
<script>
$(document).on('ready', function() {
$(function() {
new ".($answerType == HOT_SPOT_DELINEATION ? 'DelineationQuestion' : 'HotspotQuestion')."({
questionId: $questionId,
exerciseId: $exe_id,

@ -4,7 +4,6 @@ window.HotspotQuestion = (function () {
this.attributes = attributes;
this.id = 0;
this.name = '';
this.changeEvent = null;
};
HotspotModel.prototype.set = function (key, value) {
@ -577,6 +576,7 @@ window.HotspotQuestion = (function () {
currentHotspot.set('centerY', 0);
currentHotspot.set('radiusX', 0);
currentHotspot.set('radiusY', 0);
return;
}
})
@ -1137,13 +1137,13 @@ window.HotspotQuestion = (function () {
switch (config.for) {
case 'admin':
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_actionscript_admin.as.php?' + _p.web_cid_query, {
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_actionscript_admin.as.php?' + webCidReq, {
modifyAnswers: parseInt(config.questionId)
});
break;
case 'user':
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_actionscript.as.php?' + _p.web_cid_query, {
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_actionscript.as.php?' + webCidReq, {
modifyAnswers: parseInt(config.questionId),
exe_id: parseInt(config.exerciseId)
});
@ -1152,7 +1152,7 @@ window.HotspotQuestion = (function () {
case 'solution':
//no break
case 'preview':
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_answers.as.php?' + _p.web_cid_query, {
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_answers.as.php?' + webCidReq, {
modifyAnswers: parseInt(config.questionId),
exerciseId: parseInt(config.exerciseId),
exeId: parseInt(config.exeId)
@ -1560,9 +1560,7 @@ window.DelineationQuestion = (function () {
this.el.appendChild(imageSvg);
this.renderDelineation();
var isDrawing = false;
var contextMenu = new ContextMenu();
contextMenu.onHide(function () {
var answerInput = $('hotspot[' + config.questionId + '][1]'),
@ -1700,7 +1698,6 @@ window.DelineationQuestion = (function () {
var image = new Image();
image.onload = function () {
$(config.selector).html('');
var polygonCollection = new PolygonCollection(),
previewSvg = new AdminSvg(polygonCollection, image);
@ -1723,23 +1720,23 @@ window.DelineationQuestion = (function () {
};
var config = {
questionId: 0,
exerciseId: 0,
selector: null,
for: ''
},
lang = {},
selectedPolygonIndex = -1;
questionId: 0,
exerciseId: 0,
selector: null,
for: ''
},
lang = {},
selectedPolygonIndex = -1;
var getPointOnImage = function (referenceElement, x, y) {
var pointerPosition = {
left: x + window.scrollX,
top: y + window.scrollY
},
canvasOffset = {
x: referenceElement.getBoundingClientRect().left + window.scrollX,
y: referenceElement.getBoundingClientRect().top + window.scrollY
};
left: x + window.scrollX,
top: y + window.scrollY
},
canvasOffset = {
x: referenceElement.getBoundingClientRect().left + window.scrollX,
y: referenceElement.getBoundingClientRect().top + window.scrollY
};
return {
x: Math.round(pointerPosition.left - canvasOffset.x),
@ -1763,22 +1760,21 @@ window.DelineationQuestion = (function () {
');
var xhrQuestion = null;
switch (config.for) {
case 'admin':
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_actionscript_admin.as.php?' + _p.web_cid_query, {
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_actionscript_admin.as.php?' + webCidReq, {
modifyAnswers: parseInt(config.questionId)
});
break;
case 'user':
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_actionscript.as.php?' + _p.web_cid_query, {
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_actionscript.as.php?' + webCidReq, {
modifyAnswers: parseInt(config.questionId)
});
break;
case 'solution':
// no break
case 'preview':
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_answers.as.php?' + _p.web_cid_query, {
xhrQuestion = $.getJSON(config.relPath + 'exercise/hotspot_answers.as.php?' + webCidReq, {
modifyAnswers: parseInt(config.questionId),
exerciseId: parseInt(config.exerciseId),
exeId: parseInt(config.exeId)

Loading…
Cancel
Save