Issues (2126)

main/exercise/hotspot_actionscript.as.php (1 issue)

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use ChamiloSession as Session;
5
6
/**
7
 * This file generates the ActionScript variables code used by the HotSpot .swf.
8
 *
9
 * @package chamilo.exercise
10
 *
11
 * @author Toon Keppens
12
 *
13
 * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
14
 */
15
session_cache_limiter('none');
16
17
require_once __DIR__.'/../inc/global.inc.php';
18
19
api_protect_course_script(true);
20
21
$_course = api_get_course_info();
22
require api_get_path(LIBRARY_PATH).'geometry.lib.php';
23
24
// set vars
25
$questionId = intval($_GET['modifyAnswers']);
26
$exerciseId = isset($_GET['exe_id']) ? intval($_GET['exe_id']) : 0;
27
$objQuestion = Question::read($questionId);
28
$answer_type = $objQuestion->selectType(); //very important
29
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
30
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
31
$picturePath = $documentPath.'/images';
32
$pictureName = $objQuestion->getPictureFilename();
33
$pictureSize = getimagesize($picturePath.'/'.$pictureName);
34
$pictureWidth = $pictureSize[0];
35
$pictureHeight = $pictureSize[1];
36
$course_id = api_get_course_int_id();
37
38
// Query db for answers
39
if ($answer_type == HOT_SPOT_DELINEATION) {
40
    $sql = "SELECT iid, answer, hotspot_coordinates, hotspot_type, ponderation
41
	        FROM $TBL_ANSWERS
42
	        WHERE
43
	            c_id = $course_id AND
44
	            question_id = $questionId AND
45
	            hotspot_type = 'delineation'
46
            ORDER BY iid";
47
} else {
48
    $sql = "SELECT iid, answer, hotspot_coordinates, hotspot_type, ponderation
49
	        FROM $TBL_ANSWERS
50
	        WHERE c_id = $course_id AND question_id = $questionId
51
	        ORDER BY position";
52
}
53
$result = Database::query($sql);
54
55
$data = [];
56
$data['type'] = 'user';
57
$data['lang'] = [
58
    'Square' => get_lang('Square'),
59
    'Ellipse' => get_lang('Ellipse'),
60
    'Polygon' => get_lang('Polygon'),
61
    'HotspotStatus1' => get_lang('HotspotStatus1'),
62
    'HotspotStatus2Polygon' => get_lang('HotspotStatus2Polygon'),
63
    'HotspotStatus2Other' => get_lang('HotspotStatus2Other'),
64
    'HotspotStatus3' => get_lang('HotspotStatus3'),
65
    'HotspotShowUserPoints' => get_lang('HotspotShowUserPoints'),
66
    'ShowHotspots' => get_lang('ShowHotspots'),
67
    'Triesleft' => get_lang('Triesleft'),
68
    'HotspotExerciseFinished' => get_lang('HotspotExerciseFinished'),
69
    'NextAnswer' => get_lang('NextAnswer'),
70
    'Delineation' => get_lang('Delineation'),
71
    'CloseDelineation' => get_lang('CloseDelineation'),
72
    'Oar' => get_lang('Oar'),
73
    'ClosePolygon' => get_lang('ClosePolygon'),
74
    'DelineationStatus1' => get_lang('DelineationStatus1'),
75
];
76
$data['image'] = $objQuestion->selectPicturePath();
77
$data['image_width'] = $pictureWidth;
78
$data['image_height'] = $pictureHeight;
79
$data['courseCode'] = $_course['path'];
80
$data['hotspots'] = [];
81
$data['answers'] = [];
82
83
$nmbrTries = 0;
84
85
while ($hotspot = Database::fetch_assoc($result)) {
86
    $hotSpot = [];
87
    $hotSpot['iid'] = $hotspot['iid'];
88
    $hotSpot['answer'] = $hotspot['answer'];
89
90
    // Square or rectancle
91
    if ($hotspot['hotspot_type'] == 'square') {
92
        $hotSpot['type'] = 'square';
93
    }
94
    // Circle or ovale
95
    if ($hotspot['hotspot_type'] == 'circle') {
96
        $hotSpot['type'] = 'circle';
97
    }
98
    // Polygon
99
    if ($hotspot['hotspot_type'] == 'poly') {
100
        $hotSpot['type'] = 'poly';
101
    }
102
    // Delineation
103
    if ($hotspot['hotspot_type'] == 'delineation') {
104
        $hotSpot['type'] = 'delineation';
105
    }
106
    // No error
107
    if ($hotspot['hotspot_type'] == 'noerror') {
108
        $hotSpot['type'] = 'noerror';
109
    }
110
111
    // This is a good answer, count + 1 for nmbr of clicks
112
    if ($hotspot['hotspot_type'] > 0) {
113
        $nmbrTries++;
114
    }
115
116
    $hotSpot['coord'] = $hotspot['hotspot_coordinates'];
117
    $data['hotspots'][] = $hotSpot;
118
}
119
120
$attemptInfo = Database::select(
121
    'exe_id',
122
    Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES),
123
    [
124
        'where' => [
125
            'exe_exo_id = ? AND c_id = ? AND exe_user_id = ? AND status = ?' => [
126
                (int) $exerciseId,
127
                $course_id,
128
                api_get_user_id(),
129
                'incomplete',
130
            ],
131
        ],
132
        'order' => 'exe_id DESC',
133
        'limit' => 1,
134
    ],
135
    'first'
136
);
137
138
if (empty($attemptInfo)) {
139
    exit(0);
140
}
141
142
$attemptList = Event::getAllExerciseEventByExeId($attemptInfo['exe_id']);
0 ignored issues
show
The method getAllExerciseEventByExeId() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

142
$attemptList = Event::/** @scrutinizer ignore-call */ getAllExerciseEventByExeId($attemptInfo['exe_id']);

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.

Loading history...
143
144
if (!empty($attemptList)) {
145
    if (isset($attemptList[$questionId])) {
146
        $questionAttempt = $attemptList[$questionId][0];
147
        if (!empty($questionAttempt['answer'])) {
148
            $coordinates = explode('|', $questionAttempt['answer']);
149
150
            foreach ($coordinates as $coordinate) {
151
                $data['answers'][] = Geometry::decodePoint($coordinate);
152
            }
153
        }
154
    }
155
}
156
157
$data['nmbrTries'] = $nmbrTries;
158
$data['done'] = 'done';
159
160
if (Session::has("hotspot_ordered$questionId")) {
161
    $tempHotspots = [];
162
    $hotspotOrdered = Session::read("hotspot_ordered$questionId");
163
164
    foreach ($hotspotOrdered as $hotspotOrder) {
165
        foreach ($data['hotspots'] as $hotspot) {
166
            if ($hotspot['iid'] != $hotspotOrder) {
167
                continue;
168
            }
169
170
            $tempHotspots[] = $hotspot;
171
        }
172
    }
173
174
    $data['hotspots'] = $tempHotspots;
175
176
    Session::erase("hotspot_ordered$questionId");
177
}
178
179
header('Content-Type: application/json');
180
181
echo json_encode($data);
182