Skip to content

Commit 084dcfb

Browse files
committed
Fix hotspot questions when Practice Mode is enable - refs #8148
1 parent d72f5df commit 084dcfb

File tree

1 file changed

+77
-68
lines changed

1 file changed

+77
-68
lines changed

main/exercice/hotspot_answers.as.php

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,25 @@
77
* @package chamilo.exercise
88
* @author Toon Keppens, Julio Montoya adding hotspot "medical" support
99
*/
10-
11-
include('../inc/global.inc.php');
10+
include '../inc/global.inc.php';
1211

1312
// Set vars
14-
$questionId = intval($_GET['modifyAnswers']);
15-
$exe_id = intval($_GET['exe_id']);
16-
$objQuestion = Question :: read($questionId);
17-
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
18-
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
19-
20-
$picturePath = $documentPath.'/images';
21-
$pictureName = $objQuestion->selectPicture();
22-
$pictureSize = getimagesize($picturePath.'/'.$objQuestion->selectPicture());
23-
$pictureWidth = $pictureSize[0];
13+
$questionId = intval($_GET['modifyAnswers']);
14+
$exe_id = intval($_GET['exe_id']);
15+
16+
$objQuestion = Question::read($questionId);
17+
$trackExerciseInfo = ExerciseLib::get_exercise_track_exercise_info($exe_id);
18+
$objExercise = new Exercise(api_get_course_int_id());
19+
$objExercise->read($trackExerciseInfo['exe_exo_id']);
20+
$em = Database::getManager();
21+
$documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
22+
$picturePath = $documentPath . '/images';
23+
$pictureName = $objQuestion->selectPicture();
24+
$pictureSize = getimagesize($picturePath . '/' . $objQuestion->selectPicture());
25+
$pictureWidth = $pictureSize[0];
2426
$pictureHeight = $pictureSize[1];
27+
$course_id = api_get_course_int_id();
2528

26-
$answer_type = $objQuestion->selectType();
27-
28-
$course_id = api_get_course_int_id();
29-
30-
if ($answer_type == HOT_SPOT_DELINEATION) {
31-
// Query db for answers
32-
$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
33-
WHERE c_id = $course_id AND question_id = ".intval($questionId)." AND hotspot_type <> 'noerror' ORDER BY id";
34-
} else {
35-
$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
36-
WHERE c_id = $course_id AND question_id = ".intval($questionId)." ORDER BY id";
37-
}
38-
$result = Database::query($sql);
3929
// Init
4030
$data = [];
4131
$data['type'] = 'solution';
@@ -64,53 +54,72 @@
6454
$data['courseCode'] = $_course['path'];
6555
$data['hotspots'] = [];
6656

67-
while ($hotspot = Database::fetch_array($result)) {
68-
$hotSpot = [];
69-
$hotSpot['id'] = $hotspot['id'];
70-
$hotSpot['answer'] = $hotspot['answer'];
71-
72-
// Square or rectancle
73-
if ($hotspot['hotspot_type'] == 'square' ) {
74-
$hotSpot['type'] = 'square';
75-
}
76-
77-
// Circle or ovale
78-
if ($hotspot['hotspot_type'] == 'circle') {
79-
$hotSpot['type'] = 'circle';
80-
}
81-
82-
// Polygon
83-
if ($hotspot['hotspot_type'] == 'poly') {
84-
$hotSpot['type'] = 'poly';
85-
}
86-
87-
// Delineation
88-
if ($hotspot['hotspot_type'] == 'delineation') {
89-
$hotSpot['type'] = 'delineation';
90-
}
91-
// oar
92-
if ($hotspot['hotspot_type'] == 'oar') {
93-
$hotSpot['type'] = 'delineation';
94-
}
95-
96-
$hotSpot['coord'] = $hotspot['hotspot_coordinates'];
97-
98-
$data['hotspots'][] = $hotSpot;
57+
if ($objExercise->results_disabled != RESULT_DISABLE_SHOW_SCORE_ONLY) {
58+
$qb = $em->createQueryBuilder();
59+
$qb
60+
->select('a')
61+
->from('ChamiloCourseBundle:CQuizAnswer', 'a');
62+
63+
if ($objQuestion->selectType() == HOT_SPOT_DELINEATION) {
64+
$qb
65+
->where($qb->expr()->eq('a.cId', $course_id))
66+
->andWhere($qb->expr()->eq('a.questionId', intval($questionId)))
67+
->andWhere($qb->expr()->neq('a.hotspotType', 'noerror'));
68+
} else {
69+
$qb
70+
->where($qb->expr()->eq('a.cId', $course_id))
71+
->andWhere($qb->expr()->eq('a.questionId', intval($questionId)));
72+
}
73+
74+
$result = $qb
75+
->orderBy('a.id', 'ASC')
76+
->getQuery()
77+
->getResult();
78+
79+
foreach ($result as $hotspotAnswer) {
80+
$hotSpot = [];
81+
$hotSpot['id'] = $hotspotAnswer->getId();
82+
$hotSpot['answer'] = $hotspotAnswer->getAnswer();
83+
84+
switch ($hotspotAnswer->getHotspotType()) {
85+
case 'square':
86+
$hotSpot['type'] = 'square';
87+
break;
88+
case 'circle':
89+
$hotSpot['type'] = 'circle';
90+
break;
91+
case 'poly':
92+
$hotSpot['type'] = 'poly';
93+
break;
94+
case 'delineation':
95+
$hotSpot['type'] = 'delineation';
96+
break;
97+
case 'oar':
98+
$hotSpot['type'] = 'delineation';
99+
break;
100+
}
101+
102+
$hotSpot['coord'] = $hotspotAnswer->getHotspotCoordinates();
103+
104+
$data['hotspots'][] = $hotSpot;
105+
}
99106
}
100107

101108
$data['answers'] = [];
102109

103-
$tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
104-
$sql = "SELECT hotspot_coordinate
105-
FROM $tbl_track_e_hotspot
106-
WHERE hotspot_question_id = $questionId AND
107-
c_id = $course_id AND
108-
hotspot_exe_id = $exe_id
109-
ORDER by hotspot_id";
110-
$rs = Database::query($sql); // don't output error because we are in Flash execution.
111-
112-
while($row = Database :: fetch_array($rs, 'ASSOC')) {
113-
$data['answers'][] = $row['hotspot_coordinate'];
110+
$rs = $em
111+
->getRepository('ChamiloCoreBundle:TrackEHotspot')
112+
->findBy(
113+
[
114+
'hotspotQuestionId' => $questionId,
115+
'cId' => $course_id,
116+
'hotspotExeId' => $exe_id
117+
],
118+
['hotspotId' => 'ASC']
119+
);
120+
121+
foreach ($rs as $row) {
122+
$data['answers'][] = $row->getHotspotCoordinate();
114123
}
115124

116125
$data['done'] = 'done';

0 commit comments

Comments
 (0)