64 $this->
lng->loadLanguageModule(
'assessment');
68 $this->preview_mode = $a_preview_mode;
70 $this->tpl =
new ilTemplate(
"tpl.question_export.html",
true,
true,
"components/ILIAS/COPage");
73 if (!$a_preview_mode) {
74 $this->tpl->setVariable(
"FORM_BEGIN",
"<form onsubmit='return false;'>");
75 $this->tpl->setVariable(
"FORM_END",
"</form>");
80 public function exportQuestion($a_ref_id, $a_image_path =
null, $a_output_mode =
"presentation")
82 if ($a_ref_id !=
"") {
91 if (!is_object($this->q_gui->getObject())) {
92 return "Error: Question not found.";
95 $type = $this->q_gui->getObject()->getQuestionType();
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();
105 return "Error: Question Type not implemented/Question editing not finished";
112 if (!is_array($a_qids)) {
113 $exportstring =
'var questions = new Array();';
115 foreach (self::$exported as $key => $value) {
116 if (!is_array($a_qids) || in_array($key, $a_qids)) {
117 $exportstring .=
"questions[$key]= $value;";
120 return $exportstring;
125 $this->tpl->setCurrentBlock(
"singlechoice");
126 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
127 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
128 if ($this->preview_mode) {
129 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
131 if ($this->json_decoded->path ??
false) {
132 $this->tpl->setVariable(
134 "ilias.questions.handleMCImages(" . $this->json_decoded->id .
");"
137 $this->tpl->parseCurrentBlock();
138 foreach ($this->json_decoded->answers as $answer) {
139 if ($answer->image !=
"") {
140 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . $answer->image);
141 if (is_file($this->q_gui->getObject()->getImagePath() .
"thumb." . $answer->image)) {
142 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() .
"thumb." . $answer->image);
146 return $this->tpl->get();
151 $this->tpl->setCurrentBlock(
"multiplechoice");
152 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
153 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
154 if ($this->json_decoded->selection_limit) {
155 $this->tpl->setVariable(
'SELECTION_LIMIT_HINT', sprintf(
156 $this->
lng->txt(
'ass_mc_sel_lim_hint'),
157 $this->json_decoded->selection_limit,
158 count($this->json_decoded->answers)
161 $this->tpl->setVariable(
'SELECTION_LIMIT_VALUE', $this->json_decoded->selection_limit);
163 $this->tpl->setVariable(
'SELECTION_LIMIT_VALUE',
'null');
165 if ($this->preview_mode) {
166 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
168 if (isset($this->json_decoded->path)) {
169 $this->tpl->setVariable(
171 "ilias.questions.handleMCImages(" . $this->json_decoded->id .
");"
174 $this->tpl->parseCurrentBlock();
175 foreach ($this->json_decoded->answers as $answer) {
176 if ($answer->image !=
"") {
177 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . $answer->image);
178 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() .
"thumb." . $answer->image);
181 return $this->tpl->get();
187 $this->tpl->setCurrentBlock(
"kprimchoice");
189 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
190 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
192 if ($this->preview_mode) {
193 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
196 if ($this->json_decoded->path ??
false) {
197 $this->tpl->setVariable(
199 "ilias.questions.handleKprimImages(" . $this->json_decoded->id .
");"
203 $this->tpl->setVariable(
'OPTION_LABEL_TRUE', $this->json_decoded->trueOptionLabel);
204 $this->tpl->setVariable(
'OPTION_LABEL_FALSE', $this->json_decoded->falseOptionLabel);
206 $this->tpl->setVariable(
'VALUE_TRUE', 1);
207 $this->tpl->setVariable(
'VALUE_FALSE', 0);
209 $this->tpl->parseCurrentBlock();
211 foreach ($this->json_decoded->answers as $answer) {
212 if (is_object($answer->image)) {
213 self::$media_files[] = $answer->getImageFsPath();
214 self::$media_files[] = $answer->getThumbFsPath();
215 } elseif (is_string($answer->image)) {
216 self::$media_files[] = $this->q_gui->getObject()->getImagePath() . $answer->image;
217 if (is_file($this->q_gui->getObject()->getImagePath() .
"thumb." . $answer->image)) {
218 self::$media_files[] = $this->q_gui->getObject()->getImagePath() .
"thumb." . $answer->image;
223 return $this->tpl->get();
228 $maxlength = $this->json_decoded->maxlength == 0 ? 4096 : $this->json_decoded->maxlength;
229 $this->tpl->setCurrentBlock(
"textquestion");
230 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
231 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
232 $this->tpl->setVariable(
"VAL_MAXLENGTH", $maxlength);
233 if ($this->preview_mode) {
234 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
236 $this->tpl->parseCurrentBlock();
237 return $this->tpl->get();
242 $this->tpl->setCurrentBlock(
"clozequestion");
243 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
244 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
245 if ($this->preview_mode) {
246 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
248 $this->tpl->parseCurrentBlock();
249 return $this->tpl->get();
254 $this->tpl->setCurrentBlock(
"longmenu");
255 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
256 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
257 if ($this->preview_mode) {
258 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
260 $this->tpl->parseCurrentBlock();
261 return $this->tpl->get();
266 $this->tpl->setCurrentBlock(
"orderingquestion");
267 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
268 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
269 if ($this->preview_mode) {
270 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
273 $this->tpl->setVariable(
"VAL_SUBTYPE",
"_images");
274 $this->tpl->setVariable(
276 "ilias.questions.handleOrderingImages(" . $this->json_decoded->id .
");"
279 foreach ($this->json_decoded->answers as $answer) {
280 if ($answer->answertext !=
"") {
281 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . $answer->answertext);
282 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() .
"thumb." . $answer->answertext);
286 $this->tpl->setVariable(
"VAL_SUBTYPE",
"_terms");
288 $this->tpl->parseCurrentBlock();
289 return $this->tpl->get();
294 $this->tpl->setCurrentBlock(
"matchingquestion");
295 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
296 $this->tpl->setVariable(
"BTN_LABEL_RESET", $this->
lng->txt(
"reset_terms"));
297 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
298 if ($this->preview_mode) {
299 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
301 $this->tpl->parseCurrentBlock();
302 return $this->tpl->get();
307 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
308 array_push(self::$media_files, $this->q_gui->getObject()->getImagePath() . $this->q_gui->getObject()->getImageFilename());
309 $this->tpl->setCurrentBlock(
"mapareas");
310 $areas = $this->json_decoded->answers;
312 foreach ($areas as $area) {
313 $this->tpl->setVariable(
"VAL_TOOLTIP", htmlspecialchars($area->answertext));
314 $this->tpl->setVariable(
"VAL_COORDS", $area->coords);
315 $this->tpl->setVariable(
"VAL_ORDER", $area->order);
316 $this->tpl->setVariable(
"VAL_AREA", $area->area);
317 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
318 $this->tpl->parseCurrentBlock();
320 $this->tpl->setCurrentBlock(
"imagemapquestion");
321 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
322 if ($this->preview_mode) {
323 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
325 $this->tpl->parseCurrentBlock();
326 return $this->tpl->get();
331 $this->tpl->setCurrentBlock(
"textsubset");
332 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
333 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
334 if ($this->preview_mode) {
335 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
337 $this->tpl->parseCurrentBlock();
338 return $this->tpl->get();
343 $this->tpl->setCurrentBlock(
"orderinghorizontal");
344 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
345 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
346 if ($this->preview_mode) {
347 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
349 $this->tpl->parseCurrentBlock();
350 return $this->tpl->get();
355 $this->tpl->setCurrentBlock(
"errortext");
356 $this->tpl->setVariable(
"VAL_ID", $this->json_decoded->id);
357 $this->tpl->setVariable(
"TXT_SUBMIT_ANSWERS", $this->
lng->txt(
"cont_submit_answers"));
358 if ($this->preview_mode) {
359 $this->tpl->setVariable(
"VAL_NO_DISPLAY",
"style=\"display:none\"");
361 $this->tpl->parseCurrentBlock();
362 return $this->tpl->get();
static _getQuestionGUI(string $question_type='', int $question_id=-1)
Creates a question gui representation and returns the alias to the question gui.
static _extractInstOfTarget(string $a_target)
Extract installation id out of target.
static _extractObjIdOfTarget(string $a_target)
Extract object id out of target.
Scorm 2004 Question Exporter.
exportQuestion($a_ref_id, $a_image_path=null, $a_output_mode="presentation")
static questionsJS(?array $a_qids=null)
static array $media_files
__construct(bool $a_preview_mode=false)
Constructor @access public.
special template class to simplify handling of ITX/PEAR