1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | use Chamilo\CoreBundle\Entity\TrackEHotspot; |
||
6 | use Chamilo\CourseBundle\Entity\CQuizAnswer; |
||
7 | |||
8 | /** |
||
9 | * This file generates a json answer to the question preview. |
||
10 | * |
||
11 | * @author Toon Keppens, Julio Montoya adding hotspot "medical" support |
||
12 | */ |
||
13 | require_once __DIR__.'/../inc/global.inc.php'; |
||
14 | |||
15 | api_protect_course_script(); |
||
16 | |||
17 | $_course = api_get_course_info(); |
||
18 | $questionId = isset($_GET['modifyAnswers']) ? (int) $_GET['modifyAnswers'] : 0; |
||
19 | $exerciseId = isset($_GET['exerciseId']) ? (int) $_GET['exerciseId'] : 0; |
||
20 | $exeId = isset($_GET['exeId']) ? (int) $_GET['exeId'] : 0; |
||
21 | $userId = api_get_user_id(); |
||
22 | $courseId = api_get_course_int_id(); |
||
23 | $objExercise = new Exercise($courseId); |
||
24 | $debug = false; |
||
25 | |||
26 | if ($debug) { |
||
27 | error_log("Call to hotspot_answers.as.php"); |
||
28 | } |
||
29 | |||
30 | $trackExerciseInfo = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId); |
||
31 | |||
32 | // Check if student has access to the hotspot answers |
||
33 | if (!api_is_allowed_to_edit(null, true)) { |
||
34 | if (empty($exeId)) { |
||
35 | api_not_allowed(); |
||
36 | } |
||
37 | |||
38 | if (empty($trackExerciseInfo)) { |
||
39 | api_not_allowed(); |
||
40 | } |
||
41 | |||
42 | // Different exercise |
||
43 | if ($exerciseId != $trackExerciseInfo['exe_exo_id']) { |
||
44 | api_not_allowed(); |
||
45 | } |
||
46 | |||
47 | // Different user |
||
48 | if ($trackExerciseInfo['exe_user_id'] != $userId) { |
||
49 | api_not_allowed(); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | $objQuestion = Question::read($questionId, $objExercise->course); |
||
54 | $objExercise->read($exerciseId); |
||
55 | |||
56 | if (empty($objQuestion) || empty($objExercise)) { |
||
57 | exit; |
||
58 | } |
||
59 | |||
60 | $em = Database::getManager(); |
||
61 | $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
||
62 | $picturePath = $documentPath.'/images'; |
||
63 | $pictureName = $objQuestion->getPictureFilename(); |
||
64 | $pictureSize = getimagesize($picturePath.'/'.$pictureName); |
||
65 | $pictureWidth = $pictureSize[0]; |
||
66 | $pictureHeight = $pictureSize[1]; |
||
67 | |||
68 | $data = []; |
||
69 | $data['type'] = 'solution'; |
||
70 | $data['lang'] = [ |
||
71 | 'Square' => get_lang('Square'), |
||
72 | 'Ellipse' => get_lang('Ellipse'), |
||
73 | 'Polygon' => get_lang('Polygon'), |
||
74 | 'HotspotStatus1' => get_lang('HotspotStatus1'), |
||
75 | 'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'), |
||
76 | 'HotspotStatus2Other' => get_lang('HotspotStatus2Other'), |
||
77 | 'HotspotStatus3' => get_lang('HotspotStatus3'), |
||
78 | 'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'), |
||
79 | 'ShowHotspots' => get_lang('ShowHotspots'), |
||
80 | 'Triesleft' => get_lang('Triesleft'), |
||
81 | 'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'), |
||
82 | 'NextAnswer' => get_lang('NextAnswer'), |
||
83 | 'Delineation' => get_lang('Delineation'), |
||
84 | 'CloseDelineation' => get_lang('CloseDelineation'), |
||
85 | 'Oar' => get_lang('Oar'), |
||
86 | 'ClosePolygon' => get_lang('ClosePolygon'), |
||
87 | 'DelineationStatus1' => get_lang('DelineationStatus1'), |
||
88 | ]; |
||
89 | $data['image'] = $objQuestion->selectPicturePath(); |
||
90 | $data['image_width'] = $pictureWidth; |
||
91 | $data['image_height'] = $pictureHeight; |
||
92 | $data['courseCode'] = $_course['path']; |
||
93 | $data['hotspots'] = []; |
||
94 | $resultDisable = $objExercise->selectResultsDisabled(); |
||
95 | $showTotalScoreAndUserChoicesInLastAttempt = true; |
||
96 | if (in_array( |
||
97 | $resultDisable, [ |
||
98 | RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, |
||
99 | RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK, |
||
100 | RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK, |
||
101 | ] |
||
102 | ) |
||
103 | ) { |
||
104 | $showOnlyScore = true; |
||
105 | $showResults = true; |
||
106 | $lpId = isset($trackExerciseInfo['orig_lp_id']) ? $trackExerciseInfo['orig_lp_id'] : 0; |
||
107 | $lpItemId = isset($trackExerciseInfo['orig_lp_item_id']) ? $trackExerciseInfo['orig_lp_item_id'] : 0; |
||
108 | if ($objExercise->attempts > 0) { |
||
109 | $attempts = Event::getExerciseResultsByUser( |
||
0 ignored issues
–
show
|
|||
110 | api_get_user_id(), |
||
111 | $objExercise->iid, |
||
112 | $courseId, |
||
113 | api_get_session_id(), |
||
114 | $lpId, |
||
115 | $lpItemId, |
||
116 | 'desc' |
||
117 | ); |
||
118 | $numberAttempts = count($attempts); |
||
119 | $showTotalScoreAndUserChoicesInLastAttempt = false; |
||
120 | |||
121 | if ($numberAttempts >= $objExercise->attempts) { |
||
122 | $showResults = true; |
||
123 | $showOnlyScore = false; |
||
124 | $showTotalScoreAndUserChoicesInLastAttempt = true; |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | $hideExpectedAnswer = false; |
||
130 | if ($objExercise->getFeedbackType() == 0 && |
||
131 | $resultDisable == RESULT_DISABLE_SHOW_SCORE_ONLY |
||
132 | ) { |
||
133 | $hideExpectedAnswer = true; |
||
134 | } |
||
135 | |||
136 | if (in_array( |
||
137 | $resultDisable, [ |
||
138 | RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, |
||
139 | RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK, |
||
140 | ] |
||
141 | ) |
||
142 | ) { |
||
143 | $hideExpectedAnswer = $showTotalScoreAndUserChoicesInLastAttempt ? false : true; |
||
144 | } |
||
145 | |||
146 | if (in_array( |
||
147 | $resultDisable, [ |
||
148 | RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK, |
||
149 | ] |
||
150 | ) |
||
151 | ) { |
||
152 | $hideExpectedAnswer = false; |
||
153 | } |
||
154 | |||
155 | $hotSpotWithAnswer = []; |
||
156 | $data['answers'] = []; |
||
157 | $rs = $em |
||
158 | ->getRepository('ChamiloCoreBundle:TrackEHotspot') |
||
159 | ->findBy( |
||
160 | [ |
||
161 | 'hotspotQuestionId' => $questionId, |
||
162 | 'cId' => $courseId, |
||
163 | 'hotspotExeId' => $exeId, |
||
164 | ], |
||
165 | ['hotspotAnswerId' => 'ASC'] |
||
166 | ); |
||
167 | |||
168 | /** @var TrackEHotspot $row */ |
||
169 | foreach ($rs as $row) { |
||
170 | $data['answers'][] = $row->getHotspotCoordinate(); |
||
171 | |||
172 | if ($row->getHotspotCorrect()) { |
||
173 | $hotSpotWithAnswer[] = $row->getHotspotAnswerId(); |
||
174 | } |
||
175 | } |
||
176 | |||
177 | if (!$hideExpectedAnswer) { |
||
178 | $qb = $em->createQueryBuilder(); |
||
179 | $qb |
||
180 | ->select('a') |
||
181 | ->from('ChamiloCourseBundle:CQuizAnswer', 'a'); |
||
182 | |||
183 | if ($objQuestion->selectType() == HOT_SPOT_DELINEATION) { |
||
184 | $qb |
||
185 | ->where($qb->expr()->eq('a.questionId', $questionId)) |
||
186 | ->andWhere("a.hotspotType != 'noerror'") |
||
187 | ->orderBy('a.iid', 'ASC'); |
||
188 | } else { |
||
189 | $qb |
||
190 | ->where($qb->expr()->eq('a.questionId', $questionId)) |
||
191 | ->orderBy('a.position', 'ASC'); |
||
192 | } |
||
193 | |||
194 | $result = $qb->getQuery()->getResult(); |
||
195 | /** @var CQuizAnswer $hotSpotAnswer */ |
||
196 | foreach ($result as $hotSpotAnswer) { |
||
197 | if (RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK == $resultDisable) { |
||
198 | if (false === $showTotalScoreAndUserChoicesInLastAttempt) { |
||
199 | if (!in_array($hotSpotAnswer->getId(), $hotSpotWithAnswer)) { |
||
200 | continue; |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | |||
205 | $hotSpot = []; |
||
206 | $hotSpot['id'] = $hotSpotAnswer->getId(); |
||
207 | $hotSpot['answer'] = $hotSpotAnswer->getAnswer(); |
||
208 | |||
209 | switch ($hotSpotAnswer->getHotspotType()) { |
||
210 | case 'square': |
||
211 | $hotSpot['type'] = 'square'; |
||
212 | break; |
||
213 | case 'circle': |
||
214 | $hotSpot['type'] = 'circle'; |
||
215 | break; |
||
216 | case 'poly': |
||
217 | $hotSpot['type'] = 'poly'; |
||
218 | break; |
||
219 | case 'delineation': |
||
220 | $hotSpot['type'] = 'delineation'; |
||
221 | break; |
||
222 | case 'oar': |
||
223 | $hotSpot['type'] = 'delineation'; |
||
224 | break; |
||
225 | } |
||
226 | $hotSpot['coord'] = $hotSpotAnswer->getHotspotCoordinates(); |
||
227 | $data['hotspots'][] = $hotSpot; |
||
228 | } |
||
229 | } |
||
230 | |||
231 | $data['done'] = 'done'; |
||
232 | header('Content-Type: application/json'); |
||
233 | |||
234 | echo json_encode($data); |
||
235 | |||
236 | if ($debug) { |
||
237 | error_log("---------- End call to hotspot_answers.as.php------------"); |
||
238 | } |
||
239 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.