ILIAS  release_4-4 Revision
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 {
18  static $exported = array(); //json data for all exported questions (class variable)
19  static $mobs = array(); //json data for all mobs (class variable)
20  static $media_files = array(); //json data for all files (class variable)
21 
22  var $db; // database object
23  var $ilias; // ilias object
24  var $ref_id; // reference ID
25  var $inst_id; // installation id
26  var $q_gui; // Question GUI object
27  var $tpl; // question template
28  var $json; // json object for current question
29  var $json_decoded; // json object (decoded) for current question
30  var $preview_mode; // preview mode activated yes/no
31 
36  public function ilQuestionExporter($a_preview_mode = false)
37  {
38  global $ilDB, $ilias, $lng;
39 
40  $this->ref_id =& $a_ref_id;
41 
42  $this->db =& $ilDB;
43  $this->lng = $lng;
44 
45  $this->inst_id = IL_INST_ID;
46 
47  $this->preview_mode = $a_preview_mode;
48 
49  $this->tpl = new ilTemplate("tpl.question_export.html", true, true, "Modules/Scorm2004");
50 
51  // fix for bug 5386, alex 29.10.2009
52  if (!$a_preview_mode)
53  {
54  $this->tpl->setVariable("FORM_BEGIN", "<form onsubmit='return false;'>");
55  $this->tpl->setVariable("FORM_END", "</form>");
56  }
57 
58  }
59 
60 
61  public function exportQuestion($a_ref_id, $a_image_path = null, $a_output_mode = "presentation") {
62 
63  if ($a_ref_id != "")
64  {
65  $inst_id = ilInternalLink::_extractInstOfTarget($a_ref_id);
66  if (!($inst_id > 0))
67  {
68  $q_id = ilInternalLink::_extractObjIdOfTarget($a_ref_id);
69  }
70  }
71 
72  $this->q_gui =& assQuestionGUI::_getQuestionGUI("", $q_id);
73 
74  $type = $this->q_gui->object->getQuestionType();
75  if (method_exists($this,$type))
76  {
77  $this->q_gui->object->setExportImagePath($a_image_path);
78  $this->q_gui->object->feedbackOBJ->setPageObjectOutputMode($a_output_mode);
79  $this->json = $this->q_gui->object->toJSON();
80  $this->json_decoded = json_decode($this->json);
81 
82  self::$exported[$this->json_decoded->id] = $this->json;
83  self::$mobs[$this->json_decoded->id] = $this->json_decoded->mobs;
84  return $this->$type();
85  } else {
86  return "Error: Question Type not implemented/Question editing not finished";
87  }
88  }
89 
90  static public function indicateNewSco() {
91  self::$exported = array();
92  self::$mobs = array();
93  self::$media_files = array();
94  }
95 
96  static public function getMobs() {
97  $allmobs = array();
98  foreach (self::$mobs as $key => $value) {
99  for ($i=0;$i<count($mobs[$key]);$i++) {
100  array_push($allmobs,$mobs[$key][$i]);
101  }
102  }
103  return $allmobs;
104  }
105 
106  static public function getFiles() {
107  return self::$media_files;
108  }
109 
110  static public function questionsJS() {
111  $exportstring ='var questions = new Array();';
112  foreach (self::$exported as $key => $value) {
113  $exportstring .= "questions[$key]= $value;";
114  }
115  return $exportstring;
116  }
117 
118  private function setHeaderFooter()
119  {
120  $this->tpl->setCurrentBlock("common");
121  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
122  $this->tpl->setVariable("VAL_TYPE", $this->json_decoded->type);
123  $this->tpl->parseCurrentBlock();
124  }
125 
126  private function assSingleChoice()
127  {
128  $this->tpl->setCurrentBlock("singlechoice");
129  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
130  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
131  if ($this->preview_mode) {
132  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
133  }
134  if($this->json_decoded->path)
135  {
136  $this->tpl->setVariable("HANDLE_IMAGES",
137  "ilias.questions.handleMCImages(".$this->json_decoded->id.");");
138  }
139  $this->tpl->parseCurrentBlock();
140  foreach ($this->json_decoded->answers as $answer) {
141  if ($answer->image!="") {
142  array_push(self::$media_files,$this->q_gui->object->getImagePath().$answer->image);
143  if (is_file($this->q_gui->object->getImagePath()."thumb.".$answer->image))
144  {
145  array_push(self::$media_files,$this->q_gui->object->getImagePath()."thumb.".$answer->image);
146  }
147  }
148  }
149 // $this->setHeaderFooter();
150  return $this->tpl->get();
151  }
152 
153  private function assMultipleChoice() {
154  $this->tpl->setCurrentBlock("multiplechoice");
155  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
156  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
157  if ($this->preview_mode) {
158  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
159  }
160  if($this->json_decoded->path)
161  {
162  $this->tpl->setVariable("HANDLE_IMAGES",
163  "ilias.questions.handleMCImages(".$this->json_decoded->id.");");
164  }
165  $this->tpl->parseCurrentBlock();
166  foreach ($this->json_decoded->answers as $answer) {
167  if ($answer->image!="") {
168  array_push(self::$media_files,$this->q_gui->object->getImagePath().$answer->image);
169  array_push(self::$media_files,$this->q_gui->object->getImagePath()."thumb.".$answer->image);
170  }
171  }
172 // $this->setHeaderFooter();
173  return $this->tpl->get();
174  }
175 
176 
177  private function assTextQuestion() {
178  $maxlength = $this->json_decoded->maxlength == 0 ? 4096 : $this->json_decoded->maxlength;
179  $this->tpl->setCurrentBlock("textquestion");
180  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
181  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
182  $this->tpl->setVariable("VAL_MAXLENGTH", $maxlength);
183  if ($this->preview_mode) {
184  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
185  }
186  $this->tpl->parseCurrentBlock();
187 // $this->setHeaderFooter();
188  return $this->tpl->get();
189  }
190 
191  private function assClozeTest() {
192  $this->tpl->setCurrentBlock("clozequestion");
193  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
194  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
195  if ($this->preview_mode) {
196  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
197  }
198  $this->tpl->parseCurrentBlock();
199 // $this->setHeaderFooter();
200  return $this->tpl->get();
201  }
202 
203  private function assOrderingQuestion() {
204  $this->tpl->setCurrentBlock("orderingquestion");
205  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
206  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
207  if ($this->preview_mode) {
208  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
209  }
210  if($this->q_gui->object->getOrderingType() == OQ_PICTURES)
211  {
212  $this->tpl->setVariable("VAL_SUBTYPE", "_images");
213  $this->tpl->setVariable("HANDLE_IMAGES",
214  "ilias.questions.handleOrderingImages(".$this->json_decoded->id.");");
215 
216  foreach ($this->json_decoded->answers as $answer) {
217  if ($answer->answertext!="") {
218  array_push(self::$media_files,$this->q_gui->object->getImagePath().$answer->answertext);
219  array_push(self::$media_files,$this->q_gui->object->getImagePath()."thumb.".$answer->answertext);
220  }
221  }
222  }
223  else
224  {
225  $this->tpl->setVariable("VAL_SUBTYPE", "_terms");
226  }
227  $this->tpl->parseCurrentBlock();
228 // $this->setHeaderFooter();
229  return $this->tpl->get();
230  }
231 
232  private function assMatchingQuestion() {
233  $this->tpl->setCurrentBlock("matchingquestion");
234  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
235  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
236  if ($this->preview_mode) {
237  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
238  }
239  $this->tpl->parseCurrentBlock();
240 // $this->setHeaderFooter();
241  return $this->tpl->get();
242  }
243 
244  private function assImagemapQuestion() {
245  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
246  array_push(self::$media_files,$this->q_gui->object->getImagePath().$this->q_gui->object->getImageFilename());
247  $this->tpl->setCurrentBlock("mapareas");
248  $areas = $this->json_decoded->answers;
249  //set areas in PHP cause of inteference between pure and highlighter
250  foreach ($areas as $area) {
251  $this->tpl->setVariable("VAL_COORDS", $area->coords);
252  $this->tpl->setVariable("VAL_ORDER", $area->order);
253  $this->tpl->setVariable("VAL_AREA", $area->area);
254  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
255  $this->tpl->parseCurrentBlock();
256  }
257  $this->tpl->setCurrentBlock("imagemapquestion");
258  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
259  if ($this->preview_mode) {
260  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
261  }
262  $this->tpl->parseCurrentBlock();
263 // $this->setHeaderFooter();
264  return $this->tpl->get();
265  }
266 
267  private function assTextSubset() {
268  $this->tpl->setCurrentBlock("textsubset");
269  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
270  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
271  $this->tpl->setVariable("VAL_MAXLENGTH", $maxlength);
272  if ($this->preview_mode) {
273  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
274  }
275  $this->tpl->parseCurrentBlock();
276 // $this->setHeaderFooter();
277  return $this->tpl->get();
278  }
279 
280  private function assOrderingHorizontal() {
281  $this->tpl->setCurrentBlock("orderinghorizontal");
282  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
283  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
284  if ($this->preview_mode) {
285  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
286  }
287  $this->tpl->parseCurrentBlock();
288 // $this->setHeaderFooter();
289  return $this->tpl->get();
290  }
291 
292  private function assErrorText() {
293  $this->tpl->setCurrentBlock("errortext");
294  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
295  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
296  if ($this->preview_mode) {
297  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
298  }
299  $this->tpl->parseCurrentBlock();
300 // $this->setHeaderFooter();
301  return $this->tpl->get();
302  }
303 }
304 
305 ?>
Scorm 2004 Question Exporter.
exportQuestion($a_ref_id, $a_image_path=null, $a_output_mode="presentation")
ilQuestionExporter($a_preview_mode=false)
Constructor public.
$mobs
const OQ_PICTURES
Ordering question constants.
special template class to simplify handling of ITX/PEAR
& _getQuestionGUI($question_type, $question_id=-1)
Creates a question gui representation and returns the alias to the question gui note: please do not u...
global $lng
Definition: privfeed.php:40