ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilQuestionExporter.php
Go to the documentation of this file.
1<?php
2
20
31{
35 protected $lng;
36
37 public static $exported = array(); //json data for all exported questions (class variable)
38 public static $mobs = array(); //json data for all mobs (class variable)
39 public static $media_files = array(); //json data for all files (class variable)
40
41 public $db; // database object
42 public $ref_id; // reference ID
43 public $inst_id; // installation id
44 public $q_gui; // Question GUI object
45 public $tpl; // question template
46 public $json; // json object for current question
47 public $json_decoded; // json object (decoded) for current question
48 public $preview_mode; // preview mode activated yes/no
49
54 public function __construct($a_preview_mode = false)
55 {
56 global $DIC;
57
58 $ilDB = $DIC->database();
59 $lng = $DIC->language();
60
61 $this->db = $ilDB;
62 $this->lng = $lng;
63
64 $this->lng->loadLanguageModule('assessment');
65
66 $this->inst_id = IL_INST_ID;
67
68 $this->preview_mode = $a_preview_mode;
69
70 $this->tpl = new ilTemplate("tpl.question_export.html", true, true, "components/ILIAS/COPage");
71
72 // fix for bug 5386, alex 29.10.2009
73 if (!$a_preview_mode) {
74 $this->tpl->setVariable("FORM_BEGIN", "<form onsubmit='return false;'>");
75 $this->tpl->setVariable("FORM_END", "</form>");
76 }
77 }
78
79
80 public function exportQuestion($a_ref_id, $a_image_path = null, $a_output_mode = "presentation")
81 {
82 if ($a_ref_id != "") {
84 if (!($inst_id > 0)) {
86 }
87 }
88
89 $this->q_gui = assQuestionGUI::_getQuestionGUI("", $q_id);
90
91 if (!is_object($this->q_gui->getObject())) {
92 return "Error: Question not found.";
93 }
94
95 $type = $this->q_gui->getObject()->getQuestionType();
96 if($this->q_gui->getObject() instanceof QuestionLMExportable) {
97 $this->q_gui->getObject()->setExportImagePath($a_image_path);
98 $this->q_gui->getObject()->feedbackOBJ->setPageObjectOutputMode($a_output_mode);
99 $this->json = $this->q_gui->getObject()->toJSON();
100 $this->json_decoded = json_decode($this->json);
101 self::$exported[$this->json_decoded->id] = $this->json;
102 self::$mobs[$this->json_decoded->id] = $this->json_decoded->mobs;
103 return $this->$type();
104 } else {
105 return "Error: Question Type not implemented/Question editing not finished";
106 }
107 }
108
109 public static function indicateNewSco()
110 {
111 self::$exported = array();
112 self::$mobs = array();
113 self::$media_files = array();
114 }
115
116 public static function getMobs()
117 {
118 $allmobs = array();
119 foreach (self::$mobs as $key => $value) {
120 for ($i = 0;$i < count(self::$mobs[$key]);$i++) {
121 array_push($allmobs, self::$mobs[$key][$i]);
122 }
123 }
124 return $allmobs;
125 }
126
127 public static function getFiles()
128 {
129 return self::$media_files;
130 }
131
132 public static function questionsJS(?array $a_qids = null)
133 {
134 $exportstring = '';
135 if (!is_array($a_qids)) {
136 $exportstring = 'var questions = new Array();';
137 }
138 foreach (self::$exported as $key => $value) {
139 if (!is_array($a_qids) || in_array($key, $a_qids)) {
140 $exportstring .= "questions[$key]= $value;";
141 }
142 }
143 return $exportstring;
144 }
145
146 private function setHeaderFooter()
147 {
148 $this->tpl->setCurrentBlock("common");
149 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
150 $this->tpl->setVariable("VAL_TYPE", $this->json_decoded->type);
151 $this->tpl->parseCurrentBlock();
152 }
153
154 private function assSingleChoice()
155 {
156 $this->tpl->setCurrentBlock("singlechoice");
157 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
158 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
159 if ($this->preview_mode) {
160 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
161 }
162 if ($this->json_decoded->path ?? false) {
163 $this->tpl->setVariable(
164 "HANDLE_IMAGES",
165 "ilias.questions.handleMCImages(" . $this->json_decoded->id . ");"
166 );
167 }
168 $this->tpl->parseCurrentBlock();
169 foreach ($this->json_decoded->answers as $answer) {
170 if ($answer->image != "") {
171 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . $answer->image);
172 if (is_file($this->q_gui->getObject()->getImagePath() . "thumb." . $answer->image)) {
173 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . "thumb." . $answer->image);
174 }
175 }
176 }
177 // $this->setHeaderFooter();
178 return $this->tpl->get();
179 }
180
181 private function assMultipleChoice()
182 {
183 $this->tpl->setCurrentBlock("multiplechoice");
184 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
185 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
186 if ($this->json_decoded->selection_limit) {
187 $this->tpl->setVariable('SELECTION_LIMIT_HINT', sprintf(
188 $this->lng->txt('ass_mc_sel_lim_hint'),
189 $this->json_decoded->selection_limit,
190 count($this->json_decoded->answers)
191 ));
192
193 $this->tpl->setVariable('SELECTION_LIMIT_VALUE', $this->json_decoded->selection_limit);
194 } else {
195 $this->tpl->setVariable('SELECTION_LIMIT_VALUE', 'null');
196 }
197 if ($this->preview_mode) {
198 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
199 }
200 if (isset($this->json_decoded->path)) {
201 $this->tpl->setVariable(
202 "HANDLE_IMAGES",
203 "ilias.questions.handleMCImages(" . $this->json_decoded->id . ");"
204 );
205 }
206 $this->tpl->parseCurrentBlock();
207 foreach ($this->json_decoded->answers as $answer) {
208 if ($answer->image != "") {
209 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . $answer->image);
210 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . "thumb." . $answer->image);
211 }
212 }
213 // $this->setHeaderFooter();
214 return $this->tpl->get();
215 }
216
217
218 private function assKprimChoice()
219 {
220 $this->tpl->setCurrentBlock("kprimchoice");
221
222 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
223 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
224
225 if ($this->preview_mode) {
226 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
227 }
228
229 if ($this->json_decoded->path ?? false) {
230 $this->tpl->setVariable(
231 "HANDLE_IMAGES",
232 "ilias.questions.handleKprimImages(" . $this->json_decoded->id . ");"
233 );
234 }
235
236 $this->tpl->setVariable('OPTION_LABEL_TRUE', $this->json_decoded->trueOptionLabel);
237 $this->tpl->setVariable('OPTION_LABEL_FALSE', $this->json_decoded->falseOptionLabel);
238
239 $this->tpl->setVariable('VALUE_TRUE', 1);
240 $this->tpl->setVariable('VALUE_FALSE', 0);
241
242 $this->tpl->parseCurrentBlock();
243
244 foreach ($this->json_decoded->answers as $answer) {
245 if (is_object($answer->image)) {
246 self::$media_files[] = $answer->getImageFsPath();
247 self::$media_files[] = $answer->getThumbFsPath();
248 } elseif (is_string($answer->image)) {
249 self::$media_files[] = $this->q_gui->getObject()->getImagePath() . $answer->image;
250 if (is_file($this->q_gui->getObject()->getImagePath() . "thumb." . $answer->image)) {
251 self::$media_files[] = $this->q_gui->getObject()->getImagePath() . "thumb." . $answer->image;
252 }
253 }
254 }
255
256 // $this->setHeaderFooter();
257
258 return $this->tpl->get();
259 }
260
261 private function assTextQuestion()
262 {
263 $maxlength = $this->json_decoded->maxlength == 0 ? 4096 : $this->json_decoded->maxlength;
264 $this->tpl->setCurrentBlock("textquestion");
265 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
266 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
267 $this->tpl->setVariable("VAL_MAXLENGTH", $maxlength);
268 if ($this->preview_mode) {
269 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
270 }
271 $this->tpl->parseCurrentBlock();
272 // $this->setHeaderFooter();
273 return $this->tpl->get();
274 }
275
276 private function assClozeTest()
277 {
278 $this->tpl->setCurrentBlock("clozequestion");
279 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
280 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
281 if ($this->preview_mode) {
282 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
283 }
284 $this->tpl->parseCurrentBlock();
285 // $this->setHeaderFooter();
286 return $this->tpl->get();
287 }
288
289 private function assLongMenu()
290 {
291 $this->tpl->setCurrentBlock("longmenu");
292 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
293 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
294 if ($this->preview_mode) {
295 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
296 }
297 $this->tpl->parseCurrentBlock();
298 // $this->setHeaderFooter();
299 return $this->tpl->get();
300 }
301
302 private function assOrderingQuestion()
303 {
304 $this->tpl->setCurrentBlock("orderingquestion");
305 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
306 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
307 if ($this->preview_mode) {
308 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
309 }
310 if ($this->q_gui->getObject()->getOrderingType() == assOrderingQuestion::OQ_PICTURES) {
311 $this->tpl->setVariable("VAL_SUBTYPE", "_images");
312 $this->tpl->setVariable(
313 "HANDLE_IMAGES",
314 "ilias.questions.handleOrderingImages(" . $this->json_decoded->id . ");"
315 );
316
317 foreach ($this->json_decoded->answers as $answer) {
318 if ($answer->answertext != "") {
319 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . $answer->answertext);
320 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . "thumb." . $answer->answertext);
321 }
322 }
323 } else {
324 $this->tpl->setVariable("VAL_SUBTYPE", "_terms");
325 }
326 $this->tpl->parseCurrentBlock();
327 // $this->setHeaderFooter();
328 return $this->tpl->get();
329 }
330
331 private function assMatchingQuestion()
332 {
333 $this->tpl->setCurrentBlock("matchingquestion");
334 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
335 $this->tpl->setVariable("BTN_LABEL_RESET", $this->lng->txt("reset_terms"));
336 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
337 if ($this->preview_mode) {
338 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
339 }
340 $this->tpl->parseCurrentBlock();
341 // $this->setHeaderFooter();
342 return $this->tpl->get();
343 }
344
345 private function assImagemapQuestion()
346 {
347 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
348 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . $this->q_gui->getObject()->getImageFilename());
349 $this->tpl->setCurrentBlock("mapareas");
350 $areas = $this->json_decoded->answers;
351 //set areas in PHP cause of inteference between pure and highlighter
352 foreach ($areas as $area) {
353 $this->tpl->setVariable("VAL_TOOLTIP", htmlspecialchars($area->answertext));
354 $this->tpl->setVariable("VAL_COORDS", $area->coords);
355 $this->tpl->setVariable("VAL_ORDER", $area->order);
356 $this->tpl->setVariable("VAL_AREA", $area->area);
357 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
358 $this->tpl->parseCurrentBlock();
359 }
360 $this->tpl->setCurrentBlock("imagemapquestion");
361 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
362 if ($this->preview_mode) {
363 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
364 }
365 $this->tpl->parseCurrentBlock();
366 // $this->setHeaderFooter();
367 return $this->tpl->get();
368 }
369
370 private function assTextSubset()
371 {
372 $this->tpl->setCurrentBlock("textsubset");
373 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
374 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
375 if ($this->preview_mode) {
376 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
377 }
378 $this->tpl->parseCurrentBlock();
379 // $this->setHeaderFooter();
380 return $this->tpl->get();
381 }
382
383 private function assOrderingHorizontal()
384 {
385 $this->tpl->setCurrentBlock("orderinghorizontal");
386 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
387 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
388 if ($this->preview_mode) {
389 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
390 }
391 $this->tpl->parseCurrentBlock();
392 // $this->setHeaderFooter();
393 return $this->tpl->get();
394 }
395
396 private function assErrorText()
397 {
398 $this->tpl->setCurrentBlock("errortext");
399 $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
400 $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
401 if ($this->preview_mode) {
402 $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
403 }
404 $this->tpl->parseCurrentBlock();
405 // $this->setHeaderFooter();
406 return $this->tpl->get();
407 }
408}
static _getQuestionGUI(string $question_type='', int $question_id=-1)
Creates a question gui representation and returns the alias to the question gui.
Scorm 2004 Question Exporter.
__construct($a_preview_mode=false)
Constructor @access public.
exportQuestion($a_ref_id, $a_image_path=null, $a_output_mode="presentation")
static questionsJS(?array $a_qids=null)
special template class to simplify handling of ITX/PEAR
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: shib_login.php:26