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