1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
use Chamilo\CourseBundle\Entity\CQuizRelQuestion; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class HotSpot. |
9
|
|
|
* |
10
|
|
|
* This class allows to instantiate an object of |
11
|
|
|
* type HotSpot (MULTIPLE CHOICE, UNIQUE ANSWER) |
12
|
|
|
* extending the class question |
13
|
|
|
* |
14
|
|
|
* @author Eric Marguin |
15
|
|
|
*/ |
16
|
|
|
class HotSpot extends Question |
17
|
|
|
{ |
18
|
|
|
public $typePicture = 'hotspot.png'; |
19
|
|
|
public $explanationLangVar = 'Image zones'; |
20
|
|
|
|
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
parent::__construct(); |
24
|
|
|
$this->type = HOT_SPOT; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function display() |
28
|
|
|
{ |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function createForm(&$form, $exercise) |
32
|
|
|
{ |
33
|
|
|
parent::createForm($form, $exercise); |
34
|
|
|
|
35
|
|
|
if (!isset($_GET['editQuestion'])) { |
36
|
|
|
$icon = Display::return_icon( |
37
|
|
|
'hotspot.png', |
38
|
|
|
null, |
39
|
|
|
null, |
40
|
|
|
ICON_SIZE_BIG, |
41
|
|
|
false, |
42
|
|
|
true |
43
|
|
|
); |
44
|
|
|
$form->addFile( |
45
|
|
|
'imageUpload', |
46
|
|
|
get_lang('Upload image (jpg, png or gif) to apply hotspots.'), |
47
|
|
|
[ |
48
|
|
|
//'<img src="'.$icon.'" />', |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
// setting the save button here and not in the question class.php |
53
|
|
|
// Saving a question |
54
|
|
|
$form->addButtonSave(get_lang('Go to question'), 'submitQuestion'); |
55
|
|
|
$form->addRule( |
56
|
|
|
'imageUpload', |
57
|
|
|
get_lang('Only PNG, JPG or GIF images allowed'), |
58
|
|
|
'filetype', |
59
|
|
|
['jpg', 'jpeg', 'png', 'gif'] |
60
|
|
|
); |
61
|
|
|
$form->addRule('imageUpload', get_lang('Please select an image'), 'uploadedfile'); |
62
|
|
|
} else { |
63
|
|
|
// setting the save button here and not in the question class.php |
64
|
|
|
// Editing a question |
65
|
|
|
$form->addButtonUpdate(get_lang('Save the question'), 'submitQuestion'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function processCreation($form, $exercise) |
70
|
|
|
{ |
71
|
|
|
$fileInfo = $form->getSubmitValue('imageUpload'); |
72
|
|
|
parent::processCreation($form, $exercise); |
73
|
|
|
|
74
|
|
|
if (!empty($fileInfo['tmp_name'])) { |
75
|
|
|
$this->save($exercise); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function createAnswersForm($form) |
82
|
|
|
{ |
83
|
|
|
// nothing |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function processAnswersCreation($form, $exercise) |
87
|
|
|
{ |
88
|
|
|
// nothing |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function return_header(Exercise $exercise, $counter = null, $score = []) |
95
|
|
|
{ |
96
|
|
|
return parent::return_header($exercise, $counter, $score) |
97
|
|
|
.'<table><tr><td><table class="table">'; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function getLangVariables() |
101
|
|
|
{ |
102
|
|
|
return [ |
103
|
|
|
'Square' => get_lang('Square'), |
104
|
|
|
'Ellipse' => get_lang('Ellipse'), |
105
|
|
|
'Polygon' => get_lang('Polygon'), |
106
|
|
|
'HotspotStatus1' => get_lang('Draw a hotspot'), |
107
|
|
|
'HotspotStatus2Polygon' => get_lang('Use right-click to close the polygon'), |
108
|
|
|
'HotspotStatus2Other' => get_lang('Release the mousebutton to save the hotspot'), |
109
|
|
|
'HotspotStatus3' => get_lang('Hotspot saved'), |
110
|
|
|
'HotspotShowUserPoints' => get_lang('Show/Hide userclicks'), |
111
|
|
|
'ShowHotspots' => get_lang('Show / Hide hotspots'), |
112
|
|
|
'Triesleft' => get_lang('Attempts left'), |
113
|
|
|
'HotspotExerciseFinished' => get_lang('Now click on the button below to validate your answers'), |
114
|
|
|
'NextAnswer' => get_lang('Now click on:'), |
115
|
|
|
'Delineation' => get_lang('Delineation'), |
116
|
|
|
'CloseDelineation' => get_lang('Close delineation'), |
117
|
|
|
'Oar' => get_lang('Area to avoid'), |
118
|
|
|
'ClosePolygon' => get_lang('Close polygon'), |
119
|
|
|
'DelineationStatus1' => get_lang('Use right-click to close the delineation'), |
120
|
|
|
]; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getScenarioDestination(int $exerciseId): array |
124
|
|
|
{ |
125
|
|
|
$em = Database::getManager(); |
126
|
|
|
|
127
|
|
|
$rel = $em->getRepository(CQuizRelQuestion::class)->findOneBy([ |
128
|
|
|
'question' => $this->iid, |
129
|
|
|
'quiz' => $exerciseId, |
130
|
|
|
]); |
131
|
|
|
|
132
|
|
|
if (!$rel || empty($rel->getDestination())) { |
133
|
|
|
return [ |
134
|
|
|
'success' => ['type' => '', 'url' => ''], |
135
|
|
|
'failure' => ['type' => '', 'url' => ''], |
136
|
|
|
]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$decoded = json_decode($rel->getDestination(), true); |
140
|
|
|
|
141
|
|
|
if (!is_array($decoded)) { |
142
|
|
|
return [ |
143
|
|
|
'success' => ['type' => '', 'url' => ''], |
144
|
|
|
'failure' => ['type' => '', 'url' => ''], |
145
|
|
|
]; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return [ |
149
|
|
|
'success' => [ |
150
|
|
|
'type' => $decoded['success']['type'] ?? '', |
151
|
|
|
'url' => $decoded['success']['url'] ?? '', |
152
|
|
|
], |
153
|
|
|
'failure' => [ |
154
|
|
|
'type' => $decoded['failure']['type'] ?? '', |
155
|
|
|
'url' => $decoded['failure']['url'] ?? '', |
156
|
|
|
], |
157
|
|
|
]; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|