ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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) {
62 
63  if ($a_ref_id != "")
64  {
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->json = $this->q_gui->object->toJSON();
79  $this->json_decoded = json_decode($this->json);
80  self::$exported[$this->json_decoded->id] = $this->json;
81  self::$mobs[$this->json_decoded->id] = $this->json_decoded->mobs;
82  return $this->$type();
83  } else {
84  return "Error: Question Type not implemented/Question editing not finished";
85  }
86  }
87 
88  static public function indicateNewSco() {
89  self::$exported = array();
90  self::$mobs = array();
91  self::$media_files = array();
92  }
93 
94  static public function getMobs() {
95  $allmobs = array();
96  foreach (self::$mobs as $key => $value) {
97  for ($i=0;$i<count($mobs[$key]);$i++) {
98  array_push($allmobs,$mobs[$key][$i]);
99  }
100  }
101  return $allmobs;
102  }
103 
104  static public function getFiles() {
105  return self::$media_files;
106  }
107 
108  static public function questionsJS() {
109  $exportstring ='var questions = new Array();';
110  foreach (self::$exported as $key => $value) {
111  $exportstring .= "questions[$key]= $value;";
112  }
113  return $exportstring;
114  }
115 
116  private function setHeaderFooter()
117  {
118  $this->tpl->setCurrentBlock("common");
119  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
120  $this->tpl->setVariable("VAL_TYPE", $this->json_decoded->type);
121  $this->tpl->parseCurrentBlock();
122  }
123 
124  private function assSingleChoice()
125  {
126  $this->tpl->setCurrentBlock("singlechoice");
127  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
128  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
129  if ($this->preview_mode) {
130  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
131  }
132  if($this->json_decoded->path)
133  {
134  $this->tpl->setVariable("HANDLE_IMAGES",
135  "ilias.questions.handleMCImages(".$this->json_decoded->id.");");
136  }
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->object->getImagePath().$answer->image);
141  array_push(self::$media_files,$this->q_gui->object->getImagePath()."thumb.".$answer->image);
142  }
143  }
144 // $this->setHeaderFooter();
145  return $this->tpl->get();
146  }
147 
148  private function assMultipleChoice() {
149  $this->tpl->setCurrentBlock("multiplechoice");
150  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
151  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
152  if ($this->preview_mode) {
153  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
154  }
155  if($this->json_decoded->path)
156  {
157  $this->tpl->setVariable("HANDLE_IMAGES",
158  "ilias.questions.handleMCImages(".$this->json_decoded->id.");");
159  }
160  $this->tpl->parseCurrentBlock();
161  foreach ($this->json_decoded->answers as $answer) {
162  if ($answer->image!="") {
163  array_push(self::$media_files,$this->q_gui->object->getImagePath().$answer->image);
164  array_push(self::$media_files,$this->q_gui->object->getImagePath()."thumb.".$answer->image);
165  }
166  }
167 // $this->setHeaderFooter();
168  return $this->tpl->get();
169  }
170 
171 
172  private function assTextQuestion() {
173  $maxlength = $this->json_decoded->maxlength == 0 ? 4096 : $this->json_decoded->maxlength;
174  $this->tpl->setCurrentBlock("textquestion");
175  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
176  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
177  $this->tpl->setVariable("VAL_MAXLENGTH", $maxlength);
178  if ($this->preview_mode) {
179  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
180  }
181  $this->tpl->parseCurrentBlock();
182 // $this->setHeaderFooter();
183  return $this->tpl->get();
184  }
185 
186  private function assClozeTest() {
187  $this->tpl->setCurrentBlock("clozequestion");
188  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
189  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
190  if ($this->preview_mode) {
191  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
192  }
193  $this->tpl->parseCurrentBlock();
194 // $this->setHeaderFooter();
195  return $this->tpl->get();
196  }
197 
198  private function assOrderingQuestion() {
199  $this->tpl->setCurrentBlock("orderingquestion");
200  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
201  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
202  if ($this->preview_mode) {
203  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
204  }
205  if($this->q_gui->object->getOrderingType() == OQ_PICTURES)
206  {
207  $this->tpl->setVariable("VAL_SUBTYPE", "_images");
208  $this->tpl->setVariable("HANDLE_IMAGES",
209  "ilias.questions.handleOrderingImages(".$this->json_decoded->id.");");
210 
211  foreach ($this->json_decoded->answers as $answer) {
212  if ($answer->answertext!="") {
213  array_push(self::$media_files,$this->q_gui->object->getImagePath().$answer->answertext);
214  array_push(self::$media_files,$this->q_gui->object->getImagePath()."thumb.".$answer->answertext);
215  }
216  }
217  }
218  else
219  {
220  $this->tpl->setVariable("VAL_SUBTYPE", "_terms");
221  }
222  $this->tpl->parseCurrentBlock();
223 // $this->setHeaderFooter();
224  return $this->tpl->get();
225  }
226 
227  private function assMatchingQuestion() {
228  $this->tpl->setCurrentBlock("matchingquestion");
229  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
230  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
231  if ($this->preview_mode) {
232  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
233  }
234  $this->tpl->parseCurrentBlock();
235 // $this->setHeaderFooter();
236  return $this->tpl->get();
237  }
238 
239  private function assImagemapQuestion() {
240  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
241  array_push(self::$media_files,$this->q_gui->object->getImagePath().$this->q_gui->object->getImageFilename());
242  $this->tpl->setCurrentBlock("mapareas");
243  $areas = $this->json_decoded->answers;
244  //set areas in PHP cause of inteference between pure and highlighter
245  foreach ($areas as $area) {
246  $this->tpl->setVariable("VAL_COORDS", $area->coords);
247  $this->tpl->setVariable("VAL_ORDER", $area->order);
248  $this->tpl->setVariable("VAL_AREA", $area->area);
249  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
250  $this->tpl->parseCurrentBlock();
251  }
252  $this->tpl->setCurrentBlock("imagemapquestion");
253  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
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 assTextSubset() {
263  $this->tpl->setCurrentBlock("textsubset");
264  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
265  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
266  $this->tpl->setVariable("VAL_MAXLENGTH", $maxlength);
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 assOrderingHorizontal() {
276  $this->tpl->setCurrentBlock("orderinghorizontal");
277  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
278  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
279  if ($this->preview_mode) {
280  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
281  }
282  $this->tpl->parseCurrentBlock();
283 // $this->setHeaderFooter();
284  return $this->tpl->get();
285  }
286 
287  private function assErrorText() {
288  $this->tpl->setCurrentBlock("errortext");
289  $this->tpl->setVariable("VAL_ID", $this->json_decoded->id);
290  $this->tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("cont_submit_answers"));
291  if ($this->preview_mode) {
292  $this->tpl->setVariable("VAL_NO_DISPLAY", "style=\"display:none\"");
293  }
294  $this->tpl->parseCurrentBlock();
295 // $this->setHeaderFooter();
296  return $this->tpl->get();
297  }
298 }
299 
300 ?>